# HG changeset patch # User Raimund Renkert # Date 1359475886 -3600 # Node ID e1566938d04cc39b1faef0444d87f2fb24760860 # Parent 1071aacd042c6034a3343a86389bb91379ef7a11 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. diff -r 1071aacd042c -r e1566938d04c flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java --- 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 functions;