changeset 1105:adb52a2005e7

Moved code to extract the river srid defined in the global configuration into FLYSUtils. flys-artifacts/trunk@2608 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Aug 2011 08:09:52 +0000
parents 9383a4608d9f
children e9f66d63bdd0
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java
diffstat 3 files changed, 54 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Aug 29 09:26:56 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Aug 30 08:09:52 2011 +0000
@@ -1,3 +1,12 @@
+2011-08-30  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/FLYSUtils.java: Added a function
+	  that extracts the SRID defined in the global configuration file for a
+	  given river.
+
+	* src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java:
+	  Removed the code that extracts the river SRID - use FLYSUtils instead.
+
 2011-08-29  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Use FLYSUtils.getRiver instead of WINFOArtifact.getRiver.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java	Mon Aug 29 09:26:56 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java	Tue Aug 30 08:09:52 2011 +0000
@@ -1,23 +1,15 @@
 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;
 
 import de.intevation.flys.model.RiverAxis;
@@ -27,6 +19,7 @@
 import de.intevation.flys.artifacts.model.WMSLayerFacet;
 import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+import de.intevation.flys.utils.FLYSUtils;
 import de.intevation.flys.utils.GeometryUtils;
 
 
@@ -36,8 +29,6 @@
 
     public static final String WMS_LAYER_NAME = "riveraxis";
 
-    public static final String XPATH_RIVER_PROJECTION =
-        "/artifact-database/floodmap/river[@name=$name]/srid/@value";
 
 
     private static final Logger logger = Logger.getLogger(RiverAxisState.class);
@@ -97,19 +88,7 @@
             facet.setExtent(bounds);
         }
 
-        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);
+        facet.setSrid(FLYSUtils.getRiverSrid(artifact));
 
         facets.add(facet);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Mon Aug 29 09:26:56 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Tue Aug 30 08:09:52 2011 +0000
@@ -1,7 +1,17 @@
 package de.intevation.flys.utils;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Document;
+
 import gnu.trove.TDoubleArrayList;
 
+import de.intevation.artifacts.common.utils.Config;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.RiverFactory;
 import de.intevation.flys.model.River;
@@ -10,6 +20,9 @@
 
     public static enum KM_MODE { RANGE, LOCATIONS, NONE };
 
+    public static final String XPATH_RIVER_PROJECTION =
+        "/artifact-database/floodmap/river[@name=$name]/srid/@value";
+
 
     private FLYSUtils() {
     }
@@ -115,4 +128,34 @@
             ? RiverFactory.getRiver(sRiver)
             : null;
     }
+
+
+    /**
+     * Extracts the SRID defined in the global configuration for the river
+     * specified in <i>artifact</i>.
+     *
+     * @param artifact The FLYSArtifact that stores the name of the river.
+     *
+     * @return the SRID as string (e.g. "31466").
+     */
+    public static String getRiverSrid(FLYSArtifact artifact) {
+        String river = artifact.getDataAsString("river");
+
+        if (river == null || river.length() == 0) {
+            return null;
+        }
+
+        Map<String, String> variables = new HashMap<String, String>(1);
+        variables.put("name", river);
+
+        Document cfg = Config.getConfig();
+
+        return (String) XMLUtils.xpath(
+            cfg,
+            XPATH_RIVER_PROJECTION,
+            XPathConstants.STRING,
+            null,
+            variables);
+    }
 }
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org