Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java @ 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 | 4713bc0cc0ee |
children | f2f34d722807 |
line wrap: on
line diff
--- 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 :