changeset 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 ee105e5d5ead
children 13784581ab0c
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java
diffstat 4 files changed, 66 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Aug 23 15:32:33 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Aug 24 07:51:12 2011 +0000
@@ -1,3 +1,16 @@
+2011-08-24  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java,
+	  src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java:
+	  Repaired broken xpath expressions (the config changed in one of the last
+	  commits) and make use of the variable support in xpath expressions to
+	  replace the rivername.
+
+	* src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java:
+	  Save the rivername while initializing this artifact. This is now
+	  necessary, because each river can have its own background wms
+	  configured.
+
 2011-08-23  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java	Tue Aug 23 15:32:33 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBackgroundArtifact.java	Wed Aug 24 07:51:12 2011 +0000
@@ -32,6 +32,9 @@
     protected void initialize(Artifact artifact, Object context, CallMeta meta) {
         logger.debug("Initialize internal state with: "+ artifact.identifier());
 
+        FLYSArtifact flys = (FLYSArtifact) artifact;
+        addData("river", flys.getData("river"));
+
         List<Facet> fs = new ArrayList<Facet>();
 
         // TODO Add CallMeta
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java	Tue Aug 23 15:32:33 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java	Wed Aug 24 07:51:12 2011 +0000
@@ -1,16 +1,22 @@
 package de.intevation.flys.artifacts.states;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.xml.xpath.XPathConstants;
+
 import com.vividsolutions.jts.geom.Geometry;
 
 import org.apache.log4j.Logger;
 
+import org.w3c.dom.Document;
+
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
 
 import de.intevation.artifacts.common.utils.Config;
+import de.intevation.artifacts.common.utils.XMLUtils;
 
 import de.intevation.artifactdatabase.state.Facet;
 
@@ -31,7 +37,7 @@
     public static final String WMS_LAYER_NAME = "riveraxis";
 
     public static final String XPATH_RIVER_PROJECTION =
-        "/artifact-database/floodmap/river[@name='%RIVER%']/srid/@value";
+        "/artifact-database/floodmap/river[@name=$name]/srid/@value";
 
 
     private static final Logger logger = Logger.getLogger(RiverAxisState.class);
@@ -91,8 +97,18 @@
             facet.setExtent(bounds);
         }
 
-        String xpath = XPATH_RIVER_PROJECTION.replace("%RIVER%", river);
-        String srid  = Config.getStringXPath(xpath);
+        Map<String, String> variables = new HashMap<String, String>(1);
+        variables.put("name", river);
+
+        Document cfg = Config.getConfig();
+
+        String srid = (String) XMLUtils.xpath(
+            cfg,
+            XPATH_RIVER_PROJECTION,
+            XPathConstants.STRING,
+            null,
+            variables);
+
         facet.setSrid(srid);
 
         facets.add(facet);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java	Tue Aug 23 15:32:33 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java	Wed Aug 24 07:51:12 2011 +0000
@@ -1,14 +1,20 @@
 package de.intevation.flys.artifacts.states;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+
+import javax.xml.xpath.XPathConstants;
 
 import org.apache.log4j.Logger;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
 import de.intevation.artifacts.CallMeta;
 
 import de.intevation.artifacts.common.utils.Config;
+import de.intevation.artifacts.common.utils.XMLUtils;
 
 import de.intevation.artifactdatabase.state.Facet;
 
@@ -23,10 +29,10 @@
     public static final String I18N_DESCRIPTION = "floodmap.wmsbackground";
 
     public static final String XPATH_WMS_URL =
-        "/artifact-database/floodmap/background-layer/@url";
+        "/artifact-database/floodmap/river[@name=$name]/background-wms/@url";
 
     public static final String XPATH_WMS_LAYER =
-        "/artifact-database/floodmap/background-layer/@layer";
+        "/artifact-database/floodmap/river[@name=$name]/background-wms/@layers";
 
 
     protected String url;
@@ -41,9 +47,6 @@
         super.setup(config);
 
         logger.debug("WMSBackgroundState.setup()");
-
-        this.url   = Config.getStringXPath(XPATH_WMS_URL);
-        this.layer = Config.getStringXPath(XPATH_WMS_LAYER);
     }
 
 
@@ -58,6 +61,29 @@
         logger.debug("WMSBackgroundState.computeInit()");
 
         if (url == null || layer == null) {
+            Document cfg = Config.getConfig();
+
+            String river = artifact.getDataAsString("river");
+
+            Map<String, String> variables = new HashMap<String, String>();
+            variables.put("name", river);
+
+            url = (String) XMLUtils.xpath(
+                cfg,
+                XPATH_WMS_URL,
+                XPathConstants.STRING,
+                null,
+                variables);
+
+            layer = (String) XMLUtils.xpath(
+                cfg,
+                XPATH_WMS_LAYER,
+                XPathConstants.STRING,
+                null,
+                variables);
+        }
+
+        if (url == null || layer == null) {
             logger.warn("No background layers currently configured:");
             logger.warn("... add config for WMS url: " + XPATH_WMS_URL);
             logger.warn("... add config for WMS layer: " + XPATH_WMS_LAYER);

http://dive4elements.wald.intevation.org