[PATCH] Removed dc:to-date(). Added 'date' type for <dc:convert> instead

Wald Commits scm-commit at wald.intevation.org
Mon Oct 21 17:43:05 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1382370181 -7200
# Node ID 99312d2b4a207fd69188bac4b18dd9f4dec77940
# Parent  93ae1aa8ade9734ab7c65b3e029317f9be0125fe
Removed dc:to-date(). Added 'date' type for <dc:convert> instead.

diff -r 93ae1aa8ade9 -r 99312d2b4a20 artifacts/doc/datacage_ref_de.rst
--- a/artifacts/doc/datacage_ref_de.rst	Mon Oct 21 12:21:40 2013 +0200
+++ b/artifacts/doc/datacage_ref_de.rst	Mon Oct 21 17:43:01 2013 +0200
@@ -670,7 +670,5 @@
 
 ``dc:min-number`` **TODO**
 
-``dc:to-date`` **TODO**
-
 ``dc:find-all`` **TODO**
 
diff -r 93ae1aa8ade9 -r 99312d2b4a20 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Mon Oct 21 12:21:40 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Mon Oct 21 17:43:01 2013 +0200
@@ -200,14 +200,6 @@
             }
         });
 
-        addFunction("to-date", 1, new XPathFunction() {
-            @Override
-            public Object evaluate(List args) throws XPathFunctionException {
-                return toDate(args.get(0));
-            }
-        });
-
-
     }
 
     /**
@@ -540,14 +532,5 @@
             ? (Number)list
             : Double.valueOf(-Double.MAX_VALUE);
     }
-
-    public Date toDate(Object obj) {
-
-        return obj instanceof String
-            ? new Date(Long.valueOf((String)obj))
-            : obj instanceof Number
-                ? new Date(((Number)obj).longValue())
-                : null;
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 93ae1aa8ade9 -r 99312d2b4a20 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/TypeConverter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/TypeConverter.java	Mon Oct 21 12:21:40 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/TypeConverter.java	Mon Oct 21 17:43:01 2013 +0200
@@ -8,8 +8,14 @@
 
 package org.dive4elements.river.artifacts.datacage.templating;
 
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+
 public class TypeConverter
 {
+    private static Logger log = Logger.getLogger(TypeConverter.class);
+
     private TypeConverter() {
     }
 
@@ -19,18 +25,33 @@
             return object;
         }
 
-        if ("Integer".equals(type)) {
+        type = type.toLowerCase();
+
+        if ("integer".equals(type)) {
             return Integer.valueOf(object.toString());
         }
 
-        if ("Double".equals(type)) {
+        if ("double".equals(type)) {
             return Double.valueOf(object.toString());
         }
 
-        if ("String".equals(type)) {
+        if ("string".equals(type)) {
             return object.toString();
         }
 
+        if ("date".equals(type)) {
+            if (object instanceof Date) {
+                return object;
+            }
+            try {
+                return new Date((long)Double.parseDouble(object.toString()));
+            }
+            catch (NumberFormatException nfe) {
+                log.warn(nfe);
+                return null;
+            }
+        }
+
         // TODO: Add more types
 
         return object;


More information about the Dive4elements-commits mailing list