Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java @ 2424:092e519ff461
merged flys-artifacts/2.6.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:26 +0200 |
parents | fde3db5e68e8 |
children | 453d2d0c4258 |
comparison
equal
deleted
inserted
replaced
2392:8112ec686a9a | 2424:092e519ff461 |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import java.util.HashMap; | |
4 import java.util.List; | |
5 import java.util.Map; | |
6 | |
7 import javax.xml.xpath.XPathConstants; | |
8 | |
9 import org.apache.log4j.Logger; | |
10 | |
11 import org.w3c.dom.Document; | |
12 import org.w3c.dom.Node; | |
13 | |
14 import de.intevation.artifacts.CallMeta; | |
15 | |
16 import de.intevation.artifacts.common.utils.Config; | |
17 import de.intevation.artifacts.common.utils.XMLUtils; | |
18 | |
19 import de.intevation.artifactdatabase.state.Facet; | |
20 | |
21 import de.intevation.flys.artifacts.FLYSArtifact; | |
22 import de.intevation.flys.artifacts.model.WMSLayerFacet; | |
23 import de.intevation.flys.artifacts.resources.Resources; | |
24 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | |
25 | |
26 | |
27 public class WMSBackgroundState extends OutputState { | |
28 | |
29 public static final String I18N_DESCRIPTION = "floodmap.wmsbackground"; | |
30 | |
31 public static final String XPATH_SRID = | |
32 "/artifact-database/floodmap/river[@name=$name]/srid/@value"; | |
33 | |
34 public static final String XPATH_WMS_URL = | |
35 "/artifact-database/floodmap/river[@name=$name]/background-wms/@url"; | |
36 | |
37 public static final String XPATH_WMS_LAYER = | |
38 "/artifact-database/floodmap/river[@name=$name]/background-wms/@layers"; | |
39 | |
40 | |
41 protected String url; | |
42 protected String layer; | |
43 protected String srid; | |
44 | |
45 protected Document cfg; | |
46 | |
47 protected Map<String, String> variables; | |
48 | |
49 | |
50 private static final Logger logger = Logger.getLogger(WMSBackgroundState.class); | |
51 | |
52 | |
53 @Override | |
54 public void setup(Node config) { | |
55 super.setup(config); | |
56 | |
57 logger.debug("WMSBackgroundState.setup()"); | |
58 } | |
59 | |
60 | |
61 @Override | |
62 public Object computeInit( | |
63 FLYSArtifact artifact, | |
64 String hash, | |
65 Object context, | |
66 CallMeta meta, | |
67 List<Facet> facets | |
68 ) { | |
69 logger.debug("WMSBackgroundState.computeInit()"); | |
70 | |
71 initVariables(artifact); | |
72 | |
73 if (url == null || layer == null) { | |
74 // XXX I don't remember why 'srid', 'url' and 'layer' are member | |
75 // variables. I think the reason was buffering those values. | |
76 srid = getSrid(); | |
77 url = getUrl(); | |
78 layer = getLayer(); | |
79 } | |
80 | |
81 if (url == null || layer == null) { | |
82 logger.warn("No background layers currently configured:"); | |
83 logger.warn("... add config for WMS url: " + XPATH_WMS_URL); | |
84 logger.warn("... add config for WMS layer: " + XPATH_WMS_LAYER); | |
85 return null; | |
86 } | |
87 | |
88 WMSLayerFacet facet = new WMSLayerFacet( | |
89 0, | |
90 getFacetType(), | |
91 getTitle(meta), | |
92 ComputeType.INIT, | |
93 getID(), hash, | |
94 url); | |
95 | |
96 facet.addLayer(layer); | |
97 facet.setSrid(srid); | |
98 | |
99 facets.add(facet); | |
100 | |
101 return null; | |
102 } | |
103 | |
104 | |
105 protected Document getConfig() { | |
106 if (cfg == null) { | |
107 cfg = Config.getConfig(); | |
108 } | |
109 | |
110 return cfg; | |
111 } | |
112 | |
113 | |
114 protected void initVariables(FLYSArtifact artifact) { | |
115 String river = artifact.getDataAsString("river"); | |
116 | |
117 variables = new HashMap<String, String>(); | |
118 variables.put("name", river); | |
119 } | |
120 | |
121 | |
122 protected String getFacetType() { | |
123 return FLOODMAP_WMSBACKGROUND; | |
124 } | |
125 | |
126 | |
127 protected String getSrid() { | |
128 return (String) XMLUtils.xpath( | |
129 getConfig(), | |
130 XPATH_SRID, | |
131 XPathConstants.STRING, | |
132 null, | |
133 variables); | |
134 } | |
135 | |
136 | |
137 protected String getUrl() { | |
138 return (String) XMLUtils.xpath( | |
139 getConfig(), | |
140 XPATH_WMS_URL, | |
141 XPathConstants.STRING, | |
142 null, | |
143 variables); | |
144 } | |
145 | |
146 | |
147 protected String getLayer() { | |
148 return (String) XMLUtils.xpath( | |
149 getConfig(), | |
150 XPATH_WMS_LAYER, | |
151 XPathConstants.STRING, | |
152 null, | |
153 variables); | |
154 } | |
155 | |
156 | |
157 protected String getTitle(CallMeta meta) { | |
158 return Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION); | |
159 } | |
160 } | |
161 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |