comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WMSBackgroundState.java @ 5838:5aa05a7a34b7

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

http://dive4elements.wald.intevation.org