changeset 7555:74e9768098a0

issue1542: Let MainValues have localized dates.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 12 Nov 2013 12:11:23 +0100
parents 19a133698eaf
children 7597bae608b3
files artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java	Tue Nov 12 11:47:25 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java	Tue Nov 12 12:11:23 2013 +0100
@@ -9,6 +9,7 @@
 package org.dive4elements.river.artifacts.services;
 
 import java.util.List;
+import java.text.DateFormat;
 
 import org.apache.log4j.Logger;
 
@@ -32,6 +33,9 @@
 
 import org.dive4elements.river.artifacts.model.RiverFactory;
 
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.utils.Formatter;
+
 
 /**
  * This service returns the main values of a river's gauge based on the start
@@ -44,7 +48,6 @@
     /** The logger that is used by this service.*/
     private static Logger logger = Logger.getLogger(MainValuesService.class);
 
-
     /** The XPath that points to the river definition of the incoming request.*/
     public static final String XPATH_RIVER = "/art:mainvalues/art:river/text()";
 
@@ -54,6 +57,9 @@
     /** The XPath that points to the end definition of the incoming request.*/
     public static final String XPATH_END = "/art:mainvalues/art:end/text()";
 
+    protected CallMeta callMeta;
+
+
     /**
      * The default constructor.
      */
@@ -74,6 +80,8 @@
     ) {
         logger.debug("MainValuesService.process");
 
+        this.callMeta = callMeta;
+
         River river = getRequestedRiver(data);
         if (river == null) {
             return error("no river found.");
@@ -321,12 +329,15 @@
         cr.addAttr(el, "name", namedMainValue.getName());
         cr.addAttr(el, "type", mainValueType.getName());
         if (mainValue.getTimeInterval() != null) {
-            // TODO instead of bulky toString, use i18n.
+            DateFormat df = 
+                DateFormat.getDateInstance(DateFormat.SHORT, Resources.getLocale(callMeta));
             if (mainValue.getTimeInterval().getStartTime() != null) {
-                cr.addAttr(el, "starttime", ""+mainValue.getTimeInterval().getStartTime());
+                cr.addAttr(el, "starttime",
+                    df.format(mainValue.getTimeInterval().getStartTime()));
             }
             if (mainValue.getTimeInterval().getStopTime() != null) {
-                cr.addAttr(el, "stoptime", ""+mainValue.getTimeInterval().getStopTime());
+                cr.addAttr(el, "stoptime",
+                    df.format(mainValue.getTimeInterval().getStopTime()));
             }
         }
 

http://dive4elements.wald.intevation.org