Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromRequestInjector.java @ 8584:ce325339e9ba
(issue1754) Add range to W / Bed difference export.
This also fixes the Title layout in waterlevel report and
removes the year/epoch field from the english beddifference report.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 16 Mar 2015 17:38:08 +0100 |
parents | 16dc2da05aef |
children | 5e38e2924c07 |
line wrap: on
line source
package org.dive4elements.river.exports.injector; import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.ArtifactNamespaceContext; import org.dive4elements.artifacts.CallContext; import org.dive4elements.artifacts.ContextInjector; import org.dive4elements.artifacts.common.utils.XMLUtils; import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.access.RangeAccess; import org.w3c.dom.Document; import org.w3c.dom.Element; import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; public class KmFromRequestInjector implements ContextInjector { private static final Logger log = Logger.getLogger(KmFromRequestInjector.class); public static final String XPATH_CHART_CURRENTKM = "/art:action/art:attributes/art:currentKm/@art:km"; @Override public void setup(Element cfg) { } @Override public void injectContext( CallContext ctx, Artifact artifact, Document request ) { if (ctx.getContextValue(CURRENT_KM) instanceof Number) { return; } Double km = getCurrentKmFromRequest(request); if (Double.isNaN(km)) { RangeAccess access = new RangeAccess((D4EArtifact)artifact); km = access.getFrom(); } ctx.putContextValue(CURRENT_KM, km); } private Double getCurrentKmFromRequest(Document request) { String km = XMLUtils.xpathString( request, XPATH_CHART_CURRENTKM, ArtifactNamespaceContext.INSTANCE); if (km == null) { return Double.NaN; } try { return Double.valueOf(km); } catch (NumberFormatException nfe) { return Double.NaN; } } }