changeset 4902:e1566938d04c

Added new functions to datacage templating language. * get minimum of location/distance: dc:fromValue($ld_mode, $ld_locations, $ld_from) - returns -Double.MAX_VALUE if no min exists. * get maximum of location/distance: dc:toValue($ld_mode, $ld_locations, $ld_to) - returns Double.MAX_VALUE if no max exists.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 29 Jan 2013 17:11:26 +0100 (2013-01-29)
parents 1071aacd042c
children 5ab87837622f
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java
diffstat 1 files changed, 88 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java	Tue Jan 29 17:06:50 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java	Tue Jan 29 17:11:26 2013 +0100
@@ -82,6 +82,94 @@
         });
     }
 
+    static {
+        /** Implementation for getting the minimum value of location or distance
+         *  dc:fromValue. */
+        FUNCTIONS.addFunction("fromValue", 3, new XPathFunction() {
+            @Override
+            public Object evaluate(List args) throws XPathFunctionException {
+                Object mode      = args.get(0);
+                Object locations = args.get(1);
+                Object from      = args.get(2);
+
+                if (!(mode instanceof String)){
+                    return -Double.MAX_VALUE;
+                }
+
+                if (mode.equals("locations")) {
+                    if (!(locations instanceof String)) {
+                        return -Double.MAX_VALUE;
+                    }
+                    else {
+                        String loc = ((String)locations).replace(" ", "");
+                        String[] split = loc.split(",");
+                        return split[0];
+                    }
+                }
+                else if (mode.equals("distance")) {
+                    if (!(from instanceof String)) {
+                        return -Double.MAX_VALUE;
+                    }
+                    String f = (String)from;
+                    try {
+                        return Double.parseDouble(f);
+                    }
+                    catch(NumberFormatException nfe) {
+                        return -Double.MAX_VALUE;
+                    }
+                }
+                else {
+                    return -Double.MAX_VALUE;
+                }
+            }
+        });
+    }
+
+    static {
+        /** Implementation for getting the maximum value of location or distance
+         *  dc:toValue. */
+        FUNCTIONS.addFunction("toValue", 3, new XPathFunction() {
+            @Override
+            public Object evaluate(List args) throws XPathFunctionException {
+                Object mode      = args.get(0);
+                Object locations = args.get(1);
+                Object to        = args.get(2);
+
+                if (!(mode instanceof String)){
+                    return Double.MAX_VALUE;
+                }
+
+                if (mode.equals("locations")) {
+                    if (!(locations instanceof String)) {
+                        return Double.MAX_VALUE;
+                    }
+                    else {
+                        String loc = ((String)locations).replace(" ", "");
+                        String[] split = loc.split(",");
+                        return split[split.length - 1];
+                    }
+                }
+                else if (mode.equals("distance")) {
+                    if (!(to instanceof String)) {
+                        return Double.MAX_VALUE;
+                    }
+                    else {
+                        String t = (String)to;
+                        try {
+                            return Double.parseDouble(t);
+                        }
+                        catch(NumberFormatException nfe) {
+                            return Double.MAX_VALUE;
+                        }
+                    }
+                }
+                else {
+                    return Double.MAX_VALUE;
+                }
+            }
+        });
+    }
+
     /** List of functions. */
     protected List<Entry> functions;
 

http://dive4elements.wald.intevation.org