[Dive4elements-commits] [PATCH 2 of 4] Parse start and end time of an observation

Wald Commits scm-commit at wald.intevation.org
Mon Oct 29 10:05:11 CET 2012


# HG changeset patch
# User Björn Ricks <bjoern.ricks at intevation.de>
# Date 1351501015 -3600
# Node ID b6f2ecaa67044d326f1d70315ca2a923414995ec
# Parent  82c1e911dd715df9158abc3fb719bc11c8e279a6
Parse start and end time of an observation

Parse start and end time of an observation from the artifact server xml
response.

diff -r 82c1e911dd71 -r b6f2ecaa6704 flys-client/src/main/java/de/intevation/flys/client/server/RiverInfoServiceImpl.java
--- a/flys-client/src/main/java/de/intevation/flys/client/server/RiverInfoServiceImpl.java	Mon Oct 29 09:54:31 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/RiverInfoServiceImpl.java	Mon Oct 29 09:56:55 2012 +0100
@@ -1,7 +1,11 @@
 package de.intevation.flys.client.server;
 
+import java.text.DateFormat;
+import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
+import java.util.Locale;
 import javax.xml.xpath.XPathConstants;
 
 import org.apache.log4j.Logger;
@@ -47,6 +51,9 @@
 
     private static final String XPATH_GAUGES = "/art:river-info/art:gauges/art:gauge";
 
+    public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance(
+        DateFormat.SHORT, Locale.GERMANY);
+
     public RiverInfo getGauges(String river) throws ServerException {
         logger.info("RiverInfoServiceImpl.getRiverInfo");
 
@@ -170,6 +177,19 @@
         }
     }
 
+    private Date parseDate(String value) {
+        if (value == null || value.isEmpty()) {
+            return null;
+        }
+        try {
+            return DATE_FORMAT.parse(value);
+        }
+        catch(ParseException e) {
+            logger.error(e, e);
+            return null;
+        }
+    }
+
     private List<MeasurementStation> createMeasurementStations(
             Document result, String rivername, boolean kmup) {
 
@@ -208,6 +228,10 @@
                         ArtifactNamespaceContext.NAMESPACE_URI, "id");
                 String moperator = stationele.getAttributeNS(
                         ArtifactNamespaceContext.NAMESPACE_URI, "operator");
+                String mstarttime = stationele.getAttributeNS(
+                        ArtifactNamespaceContext.NAMESPACE_URI, "starttime");
+                String mstoptime = stationele.getAttributeNS(
+                        ArtifactNamespaceContext.NAMESPACE_URI, "stoptime");
 
                 logger.debug("Found measurement station with name " + mname);
 
@@ -221,7 +245,9 @@
                         kmup,
                         riverside,
                         mtype,
-                        moperator
+                        moperator,
+                        parseDate(mstarttime),
+                        parseDate(mstoptime)
                         );
 
                 mstations.add(station);


More information about the Dive4elements-commits mailing list