[PATCH 5 of 6] Add currentKM context / request mapping to RiverUtils and use it in DiagramGenerator

Wald Commits scm-commit at wald.intevation.org
Tue Sep 24 18:37:49 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1380040603 -7200
# Node ID 1a20738e9a21d05d64a649e83726180eb1f47b15
# Parent  038a04e001d7de54ad79ee230c371264f0229377
Add currentKM context / request mapping to RiverUtils and use it in DiagramGenerator

diff -r 038a04e001d7 -r 1a20738e9a21 artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java
--- 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).
      */
diff -r 038a04e001d7 -r 1a20738e9a21 artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java
--- 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 :


More information about the Dive4elements-commits mailing list