changeset 4288:b6f2ecaa6704

Parse start and end time of an observation Parse start and end time of an observation from the artifact server xml response.
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 29 Oct 2012 09:56:55 +0100
parents 82c1e911dd71
children 3fffd7d5d67d
files flys-client/src/main/java/de/intevation/flys/client/server/RiverInfoServiceImpl.java
diffstat 1 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);

http://dive4elements.wald.intevation.org