Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java @ 3221:06ae0258269b
More braindead code removal.
flys-artifacts/trunk@4844 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 01 Jul 2012 12:43:20 +0000 |
parents | 960307cf2adc |
children | 3732e1bab0aa |
comparison
equal
deleted
inserted
replaced
3220:0c8a6145098b | 3221:06ae0258269b |
---|---|
1 package de.intevation.flys.exports.fixings; | 1 package de.intevation.flys.exports.fixings; |
2 | 2 |
3 import org.w3c.dom.Element; | |
4 import org.w3c.dom.Document; | 3 import org.w3c.dom.Document; |
5 | 4 |
6 import org.apache.log4j.Logger; | 5 import org.apache.log4j.Logger; |
7 | 6 |
8 import java.io.OutputStream; | 7 import java.io.OutputStream; |
9 | |
10 import javax.xml.xpath.XPathConstants; | |
11 | 8 |
12 import de.intevation.artifacts.ArtifactNamespaceContext; | 9 import de.intevation.artifacts.ArtifactNamespaceContext; |
13 import de.intevation.artifacts.common.utils.XMLUtils; | 10 import de.intevation.artifacts.common.utils.XMLUtils; |
14 import de.intevation.artifacts.CallContext; | 11 import de.intevation.artifacts.CallContext; |
15 | 12 |
18 public abstract class FixChartGenerator | 15 public abstract class FixChartGenerator |
19 extends XYChartGenerator | 16 extends XYChartGenerator |
20 { | 17 { |
21 private static Logger logger = Logger.getLogger(FixChartGenerator.class); | 18 private static Logger logger = Logger.getLogger(FixChartGenerator.class); |
22 | 19 |
20 public static final Double INVALID_KM = Double.valueOf(-1d); | |
21 | |
23 public static final String XPATH_CHART_CURRENTKM = | 22 public static final String XPATH_CHART_CURRENTKM = |
24 "/art:action/art:attributes/art:currentKm"; | 23 "/art:action/art:attributes/art:currentKm/@art:km"; |
25 | |
26 | 24 |
27 @Override | 25 @Override |
28 public void init(Document request, OutputStream out, CallContext context) { | 26 public void init(Document request, OutputStream out, CallContext context) { |
29 super.init(request, out, context); | 27 super.init(request, out, context); |
30 | 28 |
31 logger.debug("currentKm = " + new Double(getCurrentKmFromRequest())); | 29 Double currentKm = getCurrentKmFromRequest(request); |
32 context.putContextValue("currentKm", new Double(getCurrentKmFromRequest())); | 30 |
31 if (logger.isDebugEnabled()) { | |
32 logger.debug("currentKm = " + currentKm); | |
33 } | |
34 | |
35 context.putContextValue("currentKm", currentKm); | |
33 } | 36 } |
34 | 37 |
35 public double getCurrentKmFromRequest() { | 38 public static Double getCurrentKmFromRequest(Document request) { |
36 Element km = (Element)XMLUtils.xpath( | 39 |
40 String km = XMLUtils.xpathString( | |
37 request, | 41 request, |
38 XPATH_CHART_CURRENTKM, | 42 XPATH_CHART_CURRENTKM, |
39 XPathConstants.NODE, | |
40 ArtifactNamespaceContext.INSTANCE); | 43 ArtifactNamespaceContext.INSTANCE); |
41 | 44 |
42 if (km == null) { | 45 if (km == null) { |
43 return -1d; | 46 return INVALID_KM; |
44 } | 47 } |
45 | 48 |
46 String uri = ArtifactNamespaceContext.NAMESPACE_URI; | |
47 | |
48 String currentKm = km.getAttributeNS(uri, "km"); | |
49 try { | 49 try { |
50 double d = Double.valueOf(currentKm).doubleValue(); | 50 return Double.valueOf(km); |
51 return d; | |
52 } | 51 } |
53 catch(NumberFormatException nfe) { | 52 catch (NumberFormatException nfe) { |
54 return -1d; | 53 return INVALID_KM; |
55 } | 54 } |
56 } | 55 } |
57 } | 56 } |
58 | 57 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |