Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java @ 1063:e7c1ebfc2701
Repaired xpath expressions for wms srid and background layers that broke after the floodmap config structure changed.
flys-artifacts/trunk@2541 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 24 Aug 2011 07:51:12 +0000 |
parents | ae198bef4ba0 |
children | 7f5426c69ee0 |
comparison
equal
deleted
inserted
replaced
1062:ee105e5d5ead | 1063:e7c1ebfc2701 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | 2 |
3 import java.util.HashMap; | |
3 import java.util.List; | 4 import java.util.List; |
5 import java.util.Map; | |
6 | |
7 import javax.xml.xpath.XPathConstants; | |
4 | 8 |
5 import org.apache.log4j.Logger; | 9 import org.apache.log4j.Logger; |
6 | 10 |
11 import org.w3c.dom.Document; | |
7 import org.w3c.dom.Node; | 12 import org.w3c.dom.Node; |
8 | 13 |
9 import de.intevation.artifacts.CallMeta; | 14 import de.intevation.artifacts.CallMeta; |
10 | 15 |
11 import de.intevation.artifacts.common.utils.Config; | 16 import de.intevation.artifacts.common.utils.Config; |
17 import de.intevation.artifacts.common.utils.XMLUtils; | |
12 | 18 |
13 import de.intevation.artifactdatabase.state.Facet; | 19 import de.intevation.artifactdatabase.state.Facet; |
14 | 20 |
15 import de.intevation.flys.artifacts.FLYSArtifact; | 21 import de.intevation.flys.artifacts.FLYSArtifact; |
16 import de.intevation.flys.artifacts.model.WMSLayerFacet; | 22 import de.intevation.flys.artifacts.model.WMSLayerFacet; |
21 public class WMSBackgroundState extends OutputState { | 27 public class WMSBackgroundState extends OutputState { |
22 | 28 |
23 public static final String I18N_DESCRIPTION = "floodmap.wmsbackground"; | 29 public static final String I18N_DESCRIPTION = "floodmap.wmsbackground"; |
24 | 30 |
25 public static final String XPATH_WMS_URL = | 31 public static final String XPATH_WMS_URL = |
26 "/artifact-database/floodmap/background-layer/@url"; | 32 "/artifact-database/floodmap/river[@name=$name]/background-wms/@url"; |
27 | 33 |
28 public static final String XPATH_WMS_LAYER = | 34 public static final String XPATH_WMS_LAYER = |
29 "/artifact-database/floodmap/background-layer/@layer"; | 35 "/artifact-database/floodmap/river[@name=$name]/background-wms/@layers"; |
30 | 36 |
31 | 37 |
32 protected String url; | 38 protected String url; |
33 protected String layer; | 39 protected String layer; |
34 | 40 |
39 @Override | 45 @Override |
40 public void setup(Node config) { | 46 public void setup(Node config) { |
41 super.setup(config); | 47 super.setup(config); |
42 | 48 |
43 logger.debug("WMSBackgroundState.setup()"); | 49 logger.debug("WMSBackgroundState.setup()"); |
44 | |
45 this.url = Config.getStringXPath(XPATH_WMS_URL); | |
46 this.layer = Config.getStringXPath(XPATH_WMS_LAYER); | |
47 } | 50 } |
48 | 51 |
49 | 52 |
50 @Override | 53 @Override |
51 public Object computeInit( | 54 public Object computeInit( |
54 Object context, | 57 Object context, |
55 CallMeta meta, | 58 CallMeta meta, |
56 List<Facet> facets | 59 List<Facet> facets |
57 ) { | 60 ) { |
58 logger.debug("WMSBackgroundState.computeInit()"); | 61 logger.debug("WMSBackgroundState.computeInit()"); |
62 | |
63 if (url == null || layer == null) { | |
64 Document cfg = Config.getConfig(); | |
65 | |
66 String river = artifact.getDataAsString("river"); | |
67 | |
68 Map<String, String> variables = new HashMap<String, String>(); | |
69 variables.put("name", river); | |
70 | |
71 url = (String) XMLUtils.xpath( | |
72 cfg, | |
73 XPATH_WMS_URL, | |
74 XPathConstants.STRING, | |
75 null, | |
76 variables); | |
77 | |
78 layer = (String) XMLUtils.xpath( | |
79 cfg, | |
80 XPATH_WMS_LAYER, | |
81 XPathConstants.STRING, | |
82 null, | |
83 variables); | |
84 } | |
59 | 85 |
60 if (url == null || layer == null) { | 86 if (url == null || layer == null) { |
61 logger.warn("No background layers currently configured:"); | 87 logger.warn("No background layers currently configured:"); |
62 logger.warn("... add config for WMS url: " + XPATH_WMS_URL); | 88 logger.warn("... add config for WMS url: " + XPATH_WMS_URL); |
63 logger.warn("... add config for WMS layer: " + XPATH_WMS_LAYER); | 89 logger.warn("... add config for WMS layer: " + XPATH_WMS_LAYER); |