Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java @ 8202:e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:58:17 +0200 |
parents | 912cf4ec09d1 |
children | 081a57c80540 |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5890
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5890
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5784
diff
changeset
|
9 package org.dive4elements.river.artifacts.datacage.templating; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
5608
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
11 import java.text.SimpleDateFormat; |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
12 import java.util.ArrayList; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import java.util.Collection; |
6933
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
14 import java.util.Collections; |
5608
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
15 import java.util.Date; |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
16 import java.util.List; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.util.Map; |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
18 import java.util.HashMap; |
6933
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
19 import java.util.Set; |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
20 import java.util.regex.Matcher; |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
21 import java.util.regex.Pattern; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
5784
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
23 import java.lang.reflect.InvocationTargetException; |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
24 import java.lang.reflect.Method; |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
25 |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
26 import javax.xml.namespace.QName; |
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
27 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 import javax.xml.xpath.XPathFunction; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 import javax.xml.xpath.XPathFunctionException; |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
30 import javax.xml.xpath.XPathFunctionResolver; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 import org.apache.log4j.Logger; |
6933
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
33 import org.dive4elements.artifactdatabase.transition.TransitionEngine; |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
34 import org.dive4elements.artifacts.GlobalContext; |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
35 import org.dive4elements.river.artifacts.context.RiverContext; |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
36 import org.dive4elements.river.artifacts.context.RiverContextFactory; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
4594 | 38 |
39 /** Resolves functions (e.g. dc:contains) in Datacage/Meta-Data system. */ | |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 public class FunctionResolver |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 implements XPathFunctionResolver |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7969
diff
changeset
|
43 /** Home log. */ |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 private static Logger log = Logger.getLogger(FunctionResolver.class); |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 public static final String FUNCTION_NAMESPACE_URI = "dc"; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
48 public static final double FAR_AWAY = 99999d; |
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
49 |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
50 protected static final class Entry { |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
52 Entry next; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 XPathFunction function; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 int arity; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
56 public Entry(Entry next, XPathFunction function, int arity) { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
57 this.next = next; |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
58 this.function = function; |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
59 this.arity = arity; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
62 XPathFunction find(int arity) { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
63 Entry current = this; |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
64 while (current != null) { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
65 if (current.arity == arity) { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
66 return current.function; |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
67 } |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
68 current = current.next; |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
69 } |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
70 return null; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } // class Entry |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
4594 | 74 /** List of functions. */ |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
75 protected Map<String, Entry> functions; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
5432
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
77 protected Builder.BuildHelper buildHelper; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
78 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
79 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 public FunctionResolver() { |
5432
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
81 this(null); |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
82 } |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
83 |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
84 public FunctionResolver(Builder.BuildHelper buildHelper) { |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
85 this.buildHelper = buildHelper; |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
86 |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
87 functions = new HashMap<String, Entry>(); |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
88 |
7968
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
89 addFunction("coalesce", 2, new XPathFunction() { |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
90 @Override |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
91 public Object evaluate(List args) throws XPathFunctionException { |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
92 return coalesce(args); |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
93 } |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
94 }); |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
95 |
7967
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
96 addFunction("lowercase", 1, new XPathFunction() { |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
97 @Override |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
98 public Object evaluate(List args) throws XPathFunctionException { |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
99 return args.get(0).toString().toLowerCase(); |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
100 } |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
101 }); |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
102 |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
103 addFunction("uppercase", 1, new XPathFunction() { |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
104 @Override |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
105 public Object evaluate(List args) throws XPathFunctionException { |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
106 return args.get(0).toString().toUpperCase(); |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
107 } |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
108 }); |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
109 |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
110 addFunction("contains", 2, new XPathFunction() { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
111 @Override |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
112 public Object evaluate(List args) throws XPathFunctionException { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
113 return contains(args); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
114 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
115 }); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
116 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
117 addFunction("fromValue", 3, new XPathFunction() { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
118 @Override |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
119 public Object evaluate(List args) throws XPathFunctionException { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
120 return fromValue(args); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
121 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
122 }); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
123 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
124 addFunction("toValue", 3, new XPathFunction() { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
125 @Override |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
126 public Object evaluate(List args) throws XPathFunctionException { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
127 return toValue(args); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
128 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
129 }); |
5433
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
130 |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
131 addFunction("replace", 3, new XPathFunction() { |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
132 @Override |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
133 public Object evaluate(List args) throws XPathFunctionException { |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
134 return replace(args); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
135 } |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
136 }); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
137 |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
138 addFunction("replace-all", 3, new XPathFunction() { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
139 @Override |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
140 public Object evaluate(List args) throws XPathFunctionException { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
141 return replaceAll(args); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
142 } |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
143 }); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
144 |
5433
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
145 addFunction("has-result", 0, new XPathFunction() { |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
146 @Override |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
147 public Object evaluate(List args) throws XPathFunctionException { |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
148 return FunctionResolver.this.buildHelper.hasResult(); |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
149 } |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
150 }); |
5608
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
151 |
5890
6ea004d51203
Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
152 addFunction("group-key", 0, new XPathFunction() { |
6ea004d51203
Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
153 @Override |
6ea004d51203
Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
154 public Object evaluate(List args) throws XPathFunctionException { |
6ea004d51203
Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
155 return FunctionResolver.this.buildHelper.getGroupKey(); |
6ea004d51203
Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
156 } |
6ea004d51203
Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
157 }); |
6ea004d51203
Datacage: Introduced <dc:group epxr="xpath" type="type"> ... </dc:group> and XPath function dc:group-key().
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
158 |
5608
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
159 addFunction("date-format", 2, new XPathFunction() { |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
160 @Override |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
161 public Object evaluate(List args) throws XPathFunctionException { |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
162 return dateFormat(args); |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
163 } |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
164 }); |
6080
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
165 |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
166 addFunction("dump-variables", 0, new XPathFunction() { |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
167 @Override |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
168 public Object evaluate(List args) throws XPathFunctionException { |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
169 return FunctionResolver.this.buildHelper.frames.dump(); |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
170 } |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
171 }); |
6180
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
172 |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
173 addFunction("get", 1, new XPathFunction() { |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
174 @Override |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
175 public Object evaluate(List args) throws XPathFunctionException { |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
176 Object o = args.get(0); |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
177 if (o instanceof String) { |
6181
65f278bd4ef5
Let get return a value
Andre Heinecke <aheinecke@intevation.de>
parents:
6180
diff
changeset
|
178 return FunctionResolver.this.buildHelper.frames.getNull( |
6180
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
179 (String)o, StackFrames.NULL); |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
180 } |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
181 return StackFrames.NULL; |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
182 } |
e30d396defa5
Datacage: Added function dc:get('var-name'). Returns content of variable var-name or NULL if not
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6176
diff
changeset
|
183 }); |
6933
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
184 |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
185 addFunction("all-state-successors", 2, new XPathFunction() { |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
186 @Override |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
187 public Object evaluate(List args) throws XPathFunctionException { |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
188 Object artifactName = args.get(0); |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
189 Object stateId = args.get(1); |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
190 |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
191 return artifactName instanceof String |
7248
1dff8e71c4d6
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6933
diff
changeset
|
192 && stateId instanceof String |
6933
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
193 ? allStateSuccessors((String)artifactName, (String)stateId) |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
194 : Collections.<String>emptySet(); |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
195 } |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
196 }); |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
197 |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
198 addFunction("find-all", 2, new XPathFunction() { |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
199 @Override |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
200 public Object evaluate(List args) throws XPathFunctionException { |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
201 Object needle = args.get(0); |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
202 Object haystack = args.get(1); |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
203 return haystack instanceof String |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
204 && needle instanceof String |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
205 ? findAll((String)needle, (String)haystack) |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
206 : Collections.<String>emptyList(); |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
207 } |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
208 }); |
7383
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
209 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
210 addFunction("max-number", 1, new XPathFunction() { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
211 @Override |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
212 public Object evaluate(List args) throws XPathFunctionException { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
213 return maxNumber(args.get(0)); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
214 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
215 }); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
216 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
217 addFunction("min-number", 1, new XPathFunction() { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
218 @Override |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
219 public Object evaluate(List args) throws XPathFunctionException { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
220 return minNumber(args.get(0)); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
221 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
222 }); |
7384
ef310e272fb5
Datacage: Add function dc:to-date(number) which converts a epoch base number to a date object.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7383
diff
changeset
|
223 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 |
4594 | 226 /** |
227 * Create a new function. | |
228 * @param name Name of the function. | |
229 * @param arity Number of arguments for function. | |
230 * @param function the function itself. | |
231 */ | |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 public void addFunction(String name, int arity, XPathFunction function) { |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
233 Entry entry = functions.get(name); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
234 if (entry == null) { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
235 entry = new Entry(null, function, arity); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
236 functions.put(name, entry); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
237 } |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
238 else { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
239 Entry newEntry = new Entry(entry.next, function, arity); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
240 entry.next = newEntry; |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
241 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 @Override |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 public XPathFunction resolveFunction(QName functionName, int arity) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 if (!functionName.getNamespaceURI().equals(FUNCTION_NAMESPACE_URI)) { |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 return null; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
251 Entry entry = functions.get(functionName.getLocalPart()); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
252 return entry != null |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
253 ? entry.find(arity) |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
254 : null; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 } |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
256 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
257 /** Implementation of case-ignoring dc:contains. */ |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
258 public static Object contains(List args) throws XPathFunctionException { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
259 Object haystack = args.get(0); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
260 Object needle = args.get(1); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
261 |
5630
619da3fa7a8b
Datacage: fix dc:contains() Do not uppercase needle if its not a container search.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5629
diff
changeset
|
262 if (needle instanceof String && !(haystack instanceof String)) { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
263 needle = ((String)needle).toUpperCase(); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
264 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
265 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
266 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
267 if (haystack instanceof Collection) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
268 return Boolean.valueOf( |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
269 ((Collection)haystack).contains(needle)); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
270 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
271 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
272 if (haystack instanceof Map) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
273 return Boolean.valueOf( |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
274 ((Map)haystack).containsKey(needle)); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
275 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
276 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
277 if (haystack instanceof Object []) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
278 for (Object straw: (Object [])haystack) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
279 if (straw.equals(needle)) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
280 return Boolean.TRUE; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
281 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
282 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
283 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
284 |
5629
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
285 if (haystack instanceof String && needle instanceof String) { |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
286 String h = (String)haystack; |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
287 String n = (String)needle; |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
288 return h.contains(n); |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
289 } |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
290 |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
291 return Boolean.FALSE; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
292 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
293 catch (Exception e) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
294 log.error(e); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
295 throw new XPathFunctionException(e); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
296 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
297 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
298 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
299 /** Implementation for getting the minimum value of location or distance |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
300 * dc:fromValue. |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
301 */ |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
302 public static Object fromValue(List args) throws XPathFunctionException { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
303 Object mode = args.get(0); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
304 Object locations = args.get(1); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
305 Object from = args.get(2); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
306 |
7248
1dff8e71c4d6
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6933
diff
changeset
|
307 if ((mode instanceof String && mode.equals("location")) || |
6448
00aa1bc72a65
Set tokm and fromkm to location if we are at a location to apply km-filtering correctly
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6323
diff
changeset
|
308 (locations instanceof String && !((String)locations).isEmpty())) { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
309 if (!(locations instanceof String)) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
310 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
311 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
312 String loc = ((String)locations).replace(" ", ""); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
313 String[] split = loc.split(","); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
314 if (split.length < 1) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
315 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
316 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
317 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
318 double min = Double.parseDouble(split[0]); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
319 for (int i = 1; i < split.length; ++i) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
320 double v = Double.parseDouble(split[i]); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
321 if (v < min) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
322 min = v; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
323 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
324 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
325 return min; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
326 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
327 catch (NumberFormatException nfe) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
328 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
329 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
330 } |
6176
4edad3e414cb
Fix km filtering in Datacage, we default to mode distance now
Andre Heinecke <aheinecke@intevation.de>
parents:
6126
diff
changeset
|
331 else { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
332 if (!(from instanceof String)) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
333 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
334 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
335 String f = (String)from; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
336 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
337 return Double.parseDouble(f); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
338 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
339 catch(NumberFormatException nfe) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
340 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
341 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
342 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
343 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
344 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
345 /** Implementation for getting the maximum value of location or distance |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
346 * dc:toValue. |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
347 */ |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
348 public static Object toValue(List args) throws XPathFunctionException { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
349 Object mode = args.get(0); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
350 Object locations = args.get(1); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
351 Object to = args.get(2); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
352 |
6448
00aa1bc72a65
Set tokm and fromkm to location if we are at a location to apply km-filtering correctly
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6323
diff
changeset
|
353 if ((mode instanceof String && mode.equals("location")) || |
00aa1bc72a65
Set tokm and fromkm to location if we are at a location to apply km-filtering correctly
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6323
diff
changeset
|
354 (locations instanceof String && !((String)locations).isEmpty())) { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
355 if (!(locations instanceof String)) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
356 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
357 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
358 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
359 String loc = ((String)locations).replace(" ", ""); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
360 String[] split = loc.split(","); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
361 if (split.length < 1) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
362 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
363 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
364 double max = Double.parseDouble(split[0]); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
365 for (int i = 1; i < split.length; ++i) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
366 double v = Double.parseDouble(split[i]); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
367 if (v > max) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
368 max = v; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
369 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
370 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
371 return max; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
372 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
373 catch (NumberFormatException nfe) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
374 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
375 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
376 } |
6176
4edad3e414cb
Fix km filtering in Datacage, we default to mode distance now
Andre Heinecke <aheinecke@intevation.de>
parents:
6126
diff
changeset
|
377 else { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
378 if (!(to instanceof String)) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
379 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
380 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
381 else { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
382 String t = (String)to; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
383 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
384 return Double.parseDouble(t); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
385 } |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
386 catch (NumberFormatException nfe) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
387 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
388 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
389 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
390 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
391 } |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
392 |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
393 /** Implementation for doing a string replace |
7508
02841af5feff
cosmetics - full stop.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7403
diff
changeset
|
394 * dc:replace . |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
395 */ |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
396 public static Object replace(List args) throws XPathFunctionException { |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
397 Object haystack = args.get(0); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
398 Object needle = args.get(1); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
399 Object replacement = args.get(2); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
400 |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
401 if (needle instanceof String |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
402 && haystack instanceof String |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
403 && replacement instanceof String) { |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
404 return ((String)haystack).replace( |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
405 (String)needle, (String)replacement); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
406 } |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
407 return haystack; |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
408 } |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
409 |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
410 /** Implementation for doing a string replace |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
411 * dc:replace-all |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
412 */ |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
413 public static Object replaceAll(List args) throws XPathFunctionException { |
6126
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
414 Object haystack = args.get(0); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
415 Object needle = args.get(1); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
416 Object replacement = args.get(2); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
417 |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
418 if (needle instanceof String |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
419 && haystack instanceof String |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
420 && replacement instanceof String) { |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
421 return ((String)haystack).replaceAll( |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
422 (String)needle, (String)replacement); |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
423 } |
57fb50f8c9fc
Datacage: Added function dc:replace-all(haystack, needle, replacement) to do regular expression replacements. Mapped to Java's String haystack.replaceAll(needle, replacement).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6080
diff
changeset
|
424 return haystack; |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
425 } |
5608
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
426 |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
427 public static Object dateFormat(List args) throws XPathFunctionException { |
5608
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
428 Object pattern = args.get(0); |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
429 Object date = args.get(1); |
5784
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
430 |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
431 try { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
432 // Oracle does not return a date object but an oracle.sql.TIMESTAMP |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
433 Method meth = date.getClass().getMethod("dateValue", new Class[] {}); |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
434 date = meth.invoke(date, new Object [] {}); |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
435 } catch (IllegalArgumentException e) { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
436 } catch (IllegalAccessException e) { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
437 } catch (InvocationTargetException e) { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
438 } catch (NoSuchMethodException e) { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
439 } |
5608
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
440 if (pattern instanceof String && date instanceof Date) { |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
441 try { |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
442 // TODO: Take locale into account. |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
443 return new SimpleDateFormat((String)pattern).format((Date)date); |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
444 } |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
445 catch (IllegalArgumentException iae) { |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
446 throw new XPathFunctionException(iae); |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
447 } |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
448 } |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
449 return ""; |
62513c9183ba
Datacage: Added dc:date-format to function resolver. Args: dc:date-format(pattern, date)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5604
diff
changeset
|
450 } |
6933
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
451 |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
452 public static Set<String> allStateSuccessors(String artifactName, String stateId) { |
6933
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
453 GlobalContext gc = RiverContextFactory.getGlobalContext(); |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
454 if (gc == null) { |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
455 return Collections.<String>emptySet(); |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
456 } |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
457 Object o = gc.get(RiverContext.TRANSITION_ENGINE_KEY); |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
458 if (o instanceof TransitionEngine) { |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
459 TransitionEngine te = (TransitionEngine)o; |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
460 return te.allRecursiveSuccessorStateIds(artifactName, stateId); |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
461 } |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
462 return Collections.<String>emptySet(); |
468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6448
diff
changeset
|
463 } |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
464 |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
465 public static Collection<String> findAll(String needle, String haystack) { |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
466 |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
467 ArrayList<String> result = new ArrayList<String>(); |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
468 |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
469 Pattern pattern = Pattern.compile(needle); |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
470 Matcher matcher = pattern.matcher(haystack); |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
471 while (matcher.find()) { |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
472 result.add(matcher.group()); |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
473 } |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
474 return result; |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
475 } |
7383
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
476 |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
477 public static Number maxNumber(Object list) { |
7383
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
478 if (list instanceof Collection) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
479 Collection collection = (Collection)list; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
480 double max = -Double.MAX_VALUE; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
481 for (Object x: collection) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
482 Number n; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
483 if (x instanceof Number) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
484 n = (Number)x; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
485 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
486 else if (x instanceof String) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
487 try { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
488 n = Double.valueOf((String)x); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
489 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
490 catch (NumberFormatException nfe) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
491 log.warn("'" + x + "' is not a number."); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
492 continue; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
493 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
494 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
495 else { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
496 log.warn("'" + x + "' is not a number."); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
497 continue; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
498 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
499 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
500 double v = n.doubleValue(); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
501 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
502 if (v > max) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
503 max = v; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
504 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
505 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
506 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
507 return Double.valueOf(max == -Double.MAX_VALUE |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
508 ? Double.MAX_VALUE |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
509 : max); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
510 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
511 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
512 return list instanceof Number |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
513 ? (Number)list |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
514 : Double.valueOf(Double.MAX_VALUE); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
515 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
516 |
7969
912cf4ec09d1
Datacage function resolver: Declare static functions static.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7968
diff
changeset
|
517 public static Number minNumber(Object list) { |
7383
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
518 if (list instanceof Collection) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
519 Collection collection = (Collection)list; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
520 double min = Double.MAX_VALUE; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
521 for (Object x: collection) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
522 Number n; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
523 if (x instanceof Number) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
524 n = (Number)x; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
525 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
526 else if (x instanceof String) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
527 try { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
528 n = Double.valueOf((String)x); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
529 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
530 catch (NumberFormatException nfe) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
531 log.warn("'" + x + "' is not a number."); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
532 continue; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
533 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
534 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
535 else { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
536 log.warn("'" + x + "' is not a number."); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
537 continue; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
538 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
539 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
540 double v = n.doubleValue(); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
541 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
542 if (v < min) { |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
543 min = v; |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
544 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
545 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
546 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
547 return Double.valueOf(min == Double.MAX_VALUE |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
548 ? -Double.MAX_VALUE |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
549 : min); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
550 } |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
551 |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
552 return list instanceof Number |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
553 ? (Number)list |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
554 : Double.valueOf(-Double.MAX_VALUE); |
36a194156f15
Datacage: Added dc:min-number(list) and dc:max-number(list) to extract the numerical
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7382
diff
changeset
|
555 } |
7968
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
556 |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
557 public static Object coalesce(List list) { |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
558 for (Object x: list) { |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
559 if (x instanceof String && ((String)x).length() != 0) { |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
560 return x; |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
561 } |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
562 if (x instanceof Number && ((Number)x).doubleValue() != 0.0) { |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
563 return x; |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
564 } |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
565 } |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
566 return StackFrames.NULL; |
09c9920e6f24
Added dc:coalesce(a, b). Returns first element which is not empty or not zero.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7967
diff
changeset
|
567 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
568 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
569 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |