Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/injector/FixWQInjector.java @ 8251:c7ca9c228314
Added context injectors for discharge curves.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 10 Sep 2014 10:01:11 +0200 |
parents | |
children | 10917ec29625 |
comparison
equal
deleted
inserted
replaced
8240:61fd22f65bd4 | 8251:c7ca9c228314 |
---|---|
1 package org.dive4elements.river.exports.injector; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 import org.dive4elements.artifacts.Artifact; | |
5 import org.dive4elements.artifacts.ArtifactNamespaceContext; | |
6 import org.dive4elements.artifacts.CallContext; | |
7 import org.dive4elements.artifacts.ContextInjector; | |
8 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
9 import org.dive4elements.river.artifacts.D4EArtifact; | |
10 import org.dive4elements.river.artifacts.access.RangeAccess; | |
11 import org.w3c.dom.Document; | |
12 import org.w3c.dom.Element; | |
13 | |
14 import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; | |
15 | |
16 | |
17 public class FixWQInjector | |
18 implements ContextInjector | |
19 { | |
20 private static final Logger log = Logger.getLogger(FixWQInjector.class); | |
21 | |
22 public static final Double INVALID_KM = Double.valueOf(-1d); | |
23 public static final String XPATH_CHART_CURRENTKM = | |
24 "/art:action/art:attributes/art:currentKm/@art:km"; | |
25 @Override | |
26 public void setup(Element cfg) { | |
27 | |
28 } | |
29 | |
30 @Override | |
31 public void injectContext( | |
32 CallContext ctx, | |
33 Artifact artifact, | |
34 Document request) { | |
35 Double km = getCurrentKmFromRequest(request); | |
36 if (km == Double.NaN) { | |
37 RangeAccess access = new RangeAccess((D4EArtifact)artifact); | |
38 km = access.getFrom(); | |
39 log.debug("from access"); | |
40 } | |
41 log.debug("current km: " + km); | |
42 ctx.putContextValue(CURRENT_KM, km); | |
43 } | |
44 | |
45 private Double getCurrentKmFromRequest(Document request) { | |
46 | |
47 String km = XMLUtils.xpathString( | |
48 request, | |
49 XPATH_CHART_CURRENTKM, | |
50 ArtifactNamespaceContext.INSTANCE); | |
51 | |
52 if (km == null) { | |
53 return Double.NaN; | |
54 } | |
55 | |
56 try { | |
57 return Double.valueOf(km); | |
58 } | |
59 catch (NumberFormatException nfe) { | |
60 return Double.NaN; | |
61 } | |
62 } | |
63 } |