changeset 7123:1a20738e9a21

Add currentKM context / request mapping to RiverUtils and use it in DiagramGenerator
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 24 Sep 2013 18:36:43 +0200
parents 038a04e001d7
children 49ceab5f2263
files artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java
diffstat 2 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Tue Sep 24 18:35:21 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Tue Sep 24 18:36:43 2013 +0200
@@ -18,6 +18,8 @@
 import java.util.List;
 import java.util.Map;
 
+import java.io.OutputStream;
+
 import javax.swing.ImageIcon;
 
 import org.apache.log4j.Logger;
@@ -25,6 +27,8 @@
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifactdatabase.state.Facet;
 
+import org.dive4elements.artifacts.CallContext;
+
 import org.dive4elements.river.artifacts.D4EArtifact;
 
 import org.dive4elements.river.exports.process.Processor;
@@ -36,6 +40,7 @@
 import org.dive4elements.river.jfree.StyledAreaSeriesCollection;
 
 import org.dive4elements.river.themes.ThemeDocument;
+import org.dive4elements.river.utils.RiverUtils;
 
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
@@ -60,6 +65,8 @@
 import org.jfree.data.xy.XYSeries;
 import org.jfree.data.xy.XYSeriesCollection;
 
+import org.w3c.dom.Document;
+
 
 /**
  * The main diagram creation class.
@@ -118,6 +125,15 @@
         diagramAttributes = da.new Instance();
     }
 
+    @Override
+    public void init(String outName, Document request,
+            OutputStream out, CallContext context) {
+        super.init(outName, request, out, context);
+
+        RiverUtils.setKMFromRequestInContext(request, context);
+    }
+
+
     /**
      * Generate the chart anew (including localized axis and all).
      */
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Tue Sep 24 18:35:21 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Tue Sep 24 18:36:43 2013 +0200
@@ -10,6 +10,7 @@
 
 import org.dive4elements.artifactdatabase.state.State;
 import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.ArtifactNamespaceContext;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.common.utils.Config;
 import org.dive4elements.artifacts.common.utils.XMLUtils;
@@ -101,6 +102,11 @@
     public static final String XPATH_FLOODMAP_MAPSERVER_TEMPLATE_PATH =
         "/artifact-database/floodmap/mapserver/templates/@path";
 
+    public static final String CURRENT_KM = "currentKm";
+
+    public static final String XPATH_CHART_CURRENTKM =
+        "/art:action/art:attributes/art:currentKm/@art:km";
+
 
     private RiverUtils() {
     }
@@ -917,5 +923,31 @@
         else if (q >= 1000d) q = Math.rint(q);
         return q;
     }
+
+    /** Parses the request and checks if it contains a currentKM setting.
+     * If this is the case the currentKM is added to the context.*/
+    public static void setKMFromRequestInContext(Document request,
+            CallContext context) {
+        Double dKm;
+        String km = XMLUtils.xpathString(
+            request,
+            XPATH_CHART_CURRENTKM,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (km == null) {
+            return;
+        }
+
+        try {
+            dKm = Double.valueOf(km);
+        } catch (NumberFormatException nfe) {
+            return;
+        }
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("currentKm = " + dKm);
+        }
+        context.putContextValue(CURRENT_KM, dKm);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org