changeset 7403:99312d2b4a20

Removed dc:to-date(). Added 'date' type for <dc:convert> instead.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 21 Oct 2013 17:43:01 +0200
parents 93ae1aa8ade9
children 6599ee317069
files artifacts/doc/datacage_ref_de.rst artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/TypeConverter.java
diffstat 3 files changed, 24 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- 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**
 
--- 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 :
--- 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;

http://dive4elements.wald.intevation.org