changeset 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 0c8a6145098b
children 116b342893e3
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java
diffstat 2 files changed, 24 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sun Jul 01 11:18:59 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sun Jul 01 12:43:20 2012 +0000
@@ -1,3 +1,9 @@
+2012-07-01	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java:
+	  Remove some evidence that the authors of this software
+	  do not know Java at all.
+
 2012-07-01	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	Part of flys/issue687
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java	Sun Jul 01 11:18:59 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java	Sun Jul 01 12:43:20 2012 +0000
@@ -1,14 +1,11 @@
 package de.intevation.flys.exports.fixings;
 
-import org.w3c.dom.Element;
 import org.w3c.dom.Document;
 
 import org.apache.log4j.Logger;
 
 import java.io.OutputStream;
 
-import javax.xml.xpath.XPathConstants;
-
 import de.intevation.artifacts.ArtifactNamespaceContext;
 import de.intevation.artifacts.common.utils.XMLUtils;
 import de.intevation.artifacts.CallContext;
@@ -20,39 +17,41 @@
 {
     private static Logger logger = Logger.getLogger(FixChartGenerator.class);
 
+    public static final Double INVALID_KM = Double.valueOf(-1d);
+
     public static final String XPATH_CHART_CURRENTKM =
-        "/art:action/art:attributes/art:currentKm";
-
+        "/art:action/art:attributes/art:currentKm/@art:km";
 
     @Override
     public void init(Document request, OutputStream out, CallContext context) {
         super.init(request, out, context);
 
-        logger.debug("currentKm = " + new Double(getCurrentKmFromRequest()));
-        context.putContextValue("currentKm", new Double(getCurrentKmFromRequest()));
+        Double currentKm = getCurrentKmFromRequest(request);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("currentKm = " + currentKm);
+        }
+
+        context.putContextValue("currentKm", currentKm);
     }
 
-    public double getCurrentKmFromRequest() {
-        Element km = (Element)XMLUtils.xpath(
+    public static Double getCurrentKmFromRequest(Document request) {
+
+        String km = XMLUtils.xpathString(
             request,
             XPATH_CHART_CURRENTKM,
-            XPathConstants.NODE,
             ArtifactNamespaceContext.INSTANCE);
 
         if (km == null) {
-            return -1d;
+            return INVALID_KM;
         }
 
-        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
-
-        String currentKm = km.getAttributeNS(uri, "km");
         try {
-            double d = Double.valueOf(currentKm).doubleValue();
-            return d;
+            return Double.valueOf(km);
         }
-        catch(NumberFormatException nfe) {
-            return -1d;
+        catch (NumberFormatException nfe) {
+            return INVALID_KM;
         }
     }
 }
-
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org