Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java @ 9402:e511eb935ccd
Changed hard coded standard vegetation zone table to fetching it from the database, i18n for the standard zone names
author | mschaefer |
---|---|
date | Tue, 14 Aug 2018 14:04:01 +0200 |
parents | 4a6cc7c6716a |
children |
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 |
9299 | 11 import java.lang.reflect.InvocationTargetException; |
12 import java.lang.reflect.Method; | |
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
|
13 import java.text.SimpleDateFormat; |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
14 import java.util.ArrayList; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 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
|
16 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
|
17 import java.util.Date; |
9299 | 18 import java.util.HashMap; |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
19 import java.util.List; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import java.util.Map; |
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
|
21 import java.util.Set; |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
22 import java.util.regex.Matcher; |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
23 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
|
24 |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
25 import javax.xml.namespace.QName; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 import javax.xml.xpath.XPathFunction; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 import javax.xml.xpath.XPathFunctionException; |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
28 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
|
29 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 |
4594 | 36 /** Resolves functions (e.g. dc:contains) in Datacage/Meta-Data system. */ |
9299 | 37 public class FunctionResolver implements XPathFunctionResolver { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7969
diff
changeset
|
38 /** Home log. */ |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 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
|
40 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 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
|
42 |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
43 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
|
44 |
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
|
45 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
|
46 |
9299 | 47 Entry next; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 XPathFunction function; |
9299 | 49 int arity; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
9299 | 51 public Entry(final Entry next, final XPathFunction function, final int arity) { |
52 this.next = next; | |
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
|
53 this.function = function; |
9299 | 54 this.arity = arity; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
9299 | 57 XPathFunction find(final int arity) { |
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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 } |
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 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
|
64 } |
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 return null; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } // class Entry |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
4594 | 69 /** 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
|
70 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
|
71 |
5432
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
72 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
|
73 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 public FunctionResolver() { |
5432
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
75 this(null); |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
76 } |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
77 |
9299 | 78 public FunctionResolver(final Builder.BuildHelper buildHelper) { |
5432
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
79 this.buildHelper = buildHelper; |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
80 |
9299 | 81 this.functions = new HashMap<>(); |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
82 |
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
|
83 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
|
84 @Override |
9299 | 85 public Object evaluate(final List args) throws XPathFunctionException { |
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
|
86 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
|
87 } |
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
|
88 }); |
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 |
9299 | 90 addFunction("toString", 1, new XPathFunction() { |
91 @Override | |
92 public Object evaluate(final List args) throws XPathFunctionException { | |
93 final Object arg = args.get(0); | |
94 return arg == null ? null : arg.toString(); | |
95 } | |
96 }); | |
97 | |
7967
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
98 addFunction("lowercase", 1, new XPathFunction() { |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
99 @Override |
9299 | 100 public Object evaluate(final List args) throws XPathFunctionException { |
7967
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
101 return args.get(0).toString().toLowerCase(); |
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 }); |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
104 |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
105 addFunction("uppercase", 1, new XPathFunction() { |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
106 @Override |
9299 | 107 public Object evaluate(final List args) throws XPathFunctionException { |
7967
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
108 return args.get(0).toString().toUpperCase(); |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
109 } |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
110 }); |
6d5cbd69511a
Added dc:lowercase() dc:uppercase()
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7508
diff
changeset
|
111 |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
112 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
|
113 @Override |
9299 | 114 public Object evaluate(final 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
|
115 return contains(args); |
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 }); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
118 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
119 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
|
120 @Override |
9299 | 121 public Object evaluate(final 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
|
122 return fromValue(args); |
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 }); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
125 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
126 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
|
127 @Override |
9299 | 128 public Object evaluate(final 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
|
129 return toValue(args); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
130 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
131 }); |
5433
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
132 |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
133 addFunction("replace", 3, new XPathFunction() { |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
134 @Override |
9299 | 135 public Object evaluate(final List args) throws XPathFunctionException { |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
136 return replace(args); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
137 } |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
138 }); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
139 |
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
|
140 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
|
141 @Override |
9299 | 142 public Object evaluate(final 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
|
143 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
|
144 } |
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
|
145 }); |
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
|
146 |
5433
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
147 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
|
148 @Override |
9299 | 149 public Object evaluate(final List args) throws XPathFunctionException { |
5433
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
150 return FunctionResolver.this.buildHelper.hasResult(); |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
151 } |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
152 }); |
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
|
153 |
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
|
154 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
|
155 @Override |
9299 | 156 public Object evaluate(final List args) throws XPathFunctionException { |
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
|
157 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
|
158 } |
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
|
159 }); |
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
|
160 |
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
|
161 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
|
162 @Override |
9299 | 163 public Object evaluate(final 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
|
164 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
|
165 } |
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
|
166 }); |
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
|
167 |
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 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
|
169 @Override |
9299 | 170 public Object evaluate(final List args) throws XPathFunctionException { |
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
|
171 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
|
172 } |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
173 }); |
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
|
174 |
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 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
|
176 @Override |
9299 | 177 public Object evaluate(final List args) throws XPathFunctionException { |
178 final Object o = args.get(0); | |
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 if (o instanceof String) { |
9299 | 180 return FunctionResolver.this.buildHelper.frames.getNull((String) o, StackFrames.NULL); |
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
|
181 } |
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 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
|
183 } |
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
|
184 }); |
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
|
185 |
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 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
|
187 @Override |
9299 | 188 public Object evaluate(final List args) throws XPathFunctionException { |
189 final Object artifactName = args.get(0); | |
190 final Object stateId = args.get(1); | |
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
|
191 |
9299 | 192 return artifactName instanceof String && stateId instanceof String ? allStateSuccessors((String) artifactName, (String) stateId) |
193 : Collections.<String>emptySet(); | |
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
|
194 } |
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 }); |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
196 |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
197 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
|
198 @Override |
9299 | 199 public Object evaluate(final List args) throws XPathFunctionException { |
200 final Object needle = args.get(0); | |
201 final Object haystack = args.get(1); | |
202 return haystack instanceof String && needle instanceof String ? findAll((String) needle, (String) haystack) : Collections.<String>emptyList(); | |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
203 } |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
204 }); |
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
|
205 |
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
|
206 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
|
207 @Override |
9299 | 208 public Object evaluate(final List args) throws XPathFunctionException { |
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 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
|
210 } |
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 }); |
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 |
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 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
|
214 @Override |
9299 | 215 public Object evaluate(final List args) throws XPathFunctionException { |
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
|
216 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
|
217 } |
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 }); |
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
|
219 |
8960
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
220 addFunction("column", 1, new XPathFunction() { |
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
221 @Override |
9299 | 222 public Object evaluate(final List args) throws XPathFunctionException { |
8960
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
223 return column(args.get(0)); |
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
224 } |
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
225 }); |
9232
5030c46d8cb4
Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
8960
diff
changeset
|
226 |
5030c46d8cb4
Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
8960
diff
changeset
|
227 addFunction(FixAnalysisYearXPathFunction.ID, FixAnalysisYearXPathFunction.ARITY, new FixAnalysisYearXPathFunction(buildHelper.getContext())); |
9299 | 228 |
9402
e511eb935ccd
Changed hard coded standard vegetation zone table to fetching it from the database, i18n for the standard zone names
mschaefer
parents:
9299
diff
changeset
|
229 addFunction(DefaultVegetationZoneXPathFunction.ID, DefaultVegetationZoneXPathFunction.ARITY, |
e511eb935ccd
Changed hard coded standard vegetation zone table to fetching it from the database, i18n for the standard zone names
mschaefer
parents:
9299
diff
changeset
|
230 new DefaultVegetationZoneXPathFunction(buildHelper.getContext())); |
9299 | 231 |
232 addFunction(DataFromArtifactXPathFunction.ID, DataFromArtifactXPathFunction.ARITY, new DataFromArtifactXPathFunction(buildHelper.getContext())); | |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 |
4594 | 235 /** |
236 * Create a new function. | |
9299 | 237 * |
238 * @param name | |
239 * Name of the function. | |
240 * @param arity | |
241 * Number of arguments for function. | |
242 * @param function | |
243 * the function itself. | |
4594 | 244 */ |
9299 | 245 public void addFunction(final String name, final int arity, final XPathFunction function) { |
246 Entry entry = this.functions.get(name); | |
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
|
247 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
|
248 entry = new Entry(null, function, arity); |
9299 | 249 this.functions.put(name, entry); |
250 } else { | |
251 final Entry newEntry = new Entry(entry.next, function, arity); | |
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
|
252 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
|
253 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 @Override |
9299 | 257 public XPathFunction resolveFunction(final QName functionName, final int arity) { |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 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
|
260 return null; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 |
9299 | 263 final Entry entry = this.functions.get(functionName.getLocalPart()); |
264 return entry != null ? entry.find(arity) : null; | |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 } |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
266 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
267 /** Implementation of case-ignoring dc:contains. */ |
9299 | 268 public static Object contains(final List args) throws XPathFunctionException { |
269 final Object haystack = args.get(0); | |
270 Object needle = args.get(1); | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
271 |
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
|
272 if (needle instanceof String && !(haystack instanceof String)) { |
9299 | 273 needle = ((String) needle).toUpperCase(); |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
274 } |
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 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
277 if (haystack instanceof Collection) { |
9299 | 278 return Boolean.valueOf(((Collection) haystack).contains(needle)); |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
279 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
280 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
281 if (haystack instanceof Map) { |
9299 | 282 return Boolean.valueOf(((Map) haystack).containsKey(needle)); |
5430
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 |
9299 | 285 if (haystack instanceof Object[]) { |
286 for (final Object straw : (Object[]) haystack) { | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
287 if (straw.equals(needle)) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
288 return Boolean.TRUE; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
289 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
290 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
291 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
292 |
5629
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
293 if (haystack instanceof String && needle instanceof String) { |
9299 | 294 final String h = (String) haystack; |
295 final String n = (String) needle; | |
5629
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
296 return h.contains(n); |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
297 } |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
298 |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
299 return Boolean.FALSE; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
300 } |
9299 | 301 catch (final Exception e) { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
302 log.error(e); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
303 throw new XPathFunctionException(e); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
304 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
305 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
306 |
9299 | 307 /** |
308 * Implementation for getting the minimum value of location or distance | |
309 * dc:fromValue. | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
310 */ |
9299 | 311 public static Object fromValue(final List args) throws XPathFunctionException { |
312 final Object mode = args.get(0); | |
313 final Object locations = args.get(1); | |
314 final Object from = args.get(2); | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
315 |
9299 | 316 if ((mode instanceof String && mode.equals("location")) || (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
|
317 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
|
318 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
319 } |
9299 | 320 final String loc = ((String) locations).replace(" ", ""); |
321 final String[] split = loc.split(","); | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
322 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
|
323 return -FAR_AWAY; |
5430
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 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
326 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
|
327 for (int i = 1; i < split.length; ++i) { |
9299 | 328 final double v = Double.parseDouble(split[i]); |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
329 if (v < min) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
330 min = v; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
331 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
332 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
333 return min; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
334 } |
9299 | 335 catch (final NumberFormatException nfe) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
336 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
337 } |
9299 | 338 } else { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
339 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
|
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 } |
9299 | 342 final String f = (String) from; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
343 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
344 return Double.parseDouble(f); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
345 } |
9299 | 346 catch (final NumberFormatException nfe) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
347 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
348 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
349 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
350 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
351 |
9299 | 352 /** |
353 * Implementation for getting the maximum value of location or distance | |
354 * dc:toValue. | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
355 */ |
9299 | 356 public static Object toValue(final List args) throws XPathFunctionException { |
357 final Object mode = args.get(0); | |
358 final Object locations = args.get(1); | |
359 final Object to = args.get(2); | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
360 |
9299 | 361 if ((mode instanceof String && mode.equals("location")) || (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
|
362 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
|
363 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
364 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
365 try { |
9299 | 366 final String loc = ((String) locations).replace(" ", ""); |
367 final String[] split = loc.split(","); | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
368 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
|
369 return FAR_AWAY; |
5430
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 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
|
372 for (int i = 1; i < split.length; ++i) { |
9299 | 373 final double v = Double.parseDouble(split[i]); |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
374 if (v > max) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
375 max = v; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
376 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
377 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
378 return max; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
379 } |
9299 | 380 catch (final NumberFormatException nfe) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
381 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
382 } |
9299 | 383 } else { |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
384 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
|
385 return FAR_AWAY; |
9299 | 386 } else { |
387 final String t = (String) to; | |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
388 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
389 return Double.parseDouble(t); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
390 } |
9299 | 391 catch (final NumberFormatException nfe) { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
392 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
393 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
394 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
395 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
396 } |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
397 |
9299 | 398 /** |
399 * Implementation for doing a string replace | |
400 * dc:replace . | |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
401 */ |
9299 | 402 public static Object replace(final List args) throws XPathFunctionException { |
403 final Object haystack = args.get(0); | |
404 final Object needle = args.get(1); | |
405 final Object replacement = args.get(2); | |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
406 |
9299 | 407 if (needle instanceof String && haystack instanceof String && replacement instanceof String) { |
408 return ((String) haystack).replace((String) needle, (String) replacement); | |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
409 } |
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
|
410 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
|
411 } |
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 |
9299 | 413 /** |
414 * Implementation for doing a string replace | |
415 * dc:replace-all | |
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
|
416 */ |
9299 | 417 public static Object replaceAll(final List args) throws XPathFunctionException { |
418 final Object haystack = args.get(0); | |
419 final Object needle = args.get(1); | |
420 final Object replacement = args.get(2); | |
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
|
421 |
9299 | 422 if (needle instanceof String && haystack instanceof String && replacement instanceof String) { |
423 return ((String) haystack).replaceAll((String) needle, (String) replacement); | |
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
|
424 } |
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
|
425 return haystack; |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
426 } |
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
|
427 |
9299 | 428 public static Object dateFormat(final List args) throws XPathFunctionException { |
429 final Object pattern = args.get(0); | |
430 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
|
431 |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
432 try { |
8460
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
433 // TODO: Take locale into account. |
9299 | 434 final SimpleDateFormat format = new SimpleDateFormat((String) pattern); |
8460
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
435 |
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
436 if (date instanceof Number) { |
9299 | 437 return format.format(new Date(((Number) date).longValue())); |
8460
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
438 } |
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
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 try { |
9299 | 441 /* |
442 * Oracle does not return a date object but | |
443 * an oracle.sql.TIMESTAMP | |
444 */ | |
445 final Method meth = date.getClass().getMethod("dateValue", new Class[] {}); | |
8460
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
446 date = meth.invoke(date, new Object[] {}); |
9299 | 447 } |
448 catch (final IllegalArgumentException e) { | |
449 } | |
450 catch (final IllegalAccessException e) { | |
451 } | |
452 catch (final InvocationTargetException e) { | |
453 } | |
454 catch (final NoSuchMethodException e) { | |
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
|
455 } |
8460
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
456 |
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
457 if (date instanceof Date) { |
9299 | 458 return format.format((Date) date); |
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
|
459 } |
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
|
460 } |
9299 | 461 catch (final IllegalArgumentException iae) { |
8460
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
462 log.error(iae.getMessage()); |
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
463 } |
081a57c80540
Accept number as argument in dc:date-format().
Tom Gottfried <tom@intevation.de>
parents:
8202
diff
changeset
|
464 |
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
|
465 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
|
466 } |
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
|
467 |
9299 | 468 public static Set<String> allStateSuccessors(final String artifactName, final String stateId) { |
469 final GlobalContext gc = RiverContextFactory.getGlobalContext(); | |
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
|
470 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
|
471 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
|
472 } |
9299 | 473 final Object o = gc.get(RiverContext.TRANSITION_ENGINE_KEY); |
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
|
474 if (o instanceof TransitionEngine) { |
9299 | 475 final TransitionEngine te = (TransitionEngine) o; |
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
|
476 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
|
477 } |
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
|
478 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
|
479 } |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
480 |
9299 | 481 public static Collection<String> findAll(final String needle, final String haystack) { |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
482 |
9299 | 483 final ArrayList<String> result = new ArrayList<>(); |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
484 |
9299 | 485 final Pattern pattern = Pattern.compile(needle); |
486 final Matcher matcher = pattern.matcher(haystack); | |
7382
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
487 while (matcher.find()) { |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
488 result.add(matcher.group()); |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
489 } |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
490 return result; |
420eb5a5fde4
Datacage: Add function dc:find-all(needle, haystack).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7248
diff
changeset
|
491 } |
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
|
492 |
9299 | 493 public static Number maxNumber(final 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
|
494 if (list instanceof Collection) { |
9299 | 495 final Collection collection = (Collection) 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
|
496 double max = -Double.MAX_VALUE; |
9299 | 497 for (final Object x : collection) { |
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
|
498 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
|
499 if (x instanceof Number) { |
9299 | 500 n = (Number) x; |
501 } else if (x instanceof String) { | |
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
|
502 try { |
9299 | 503 n = Double.valueOf((String) x); |
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
|
504 } |
9299 | 505 catch (final NumberFormatException nfe) { |
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
|
506 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
|
507 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
|
508 } |
9299 | 509 } else { |
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
|
510 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
|
511 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
|
512 } |
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 |
9299 | 514 final double v = n.doubleValue(); |
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
|
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 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
|
517 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
|
518 } |
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 } |
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 |
9299 | 521 return Double.valueOf(max == -Double.MAX_VALUE ? Double.MAX_VALUE : max); |
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
|
522 } |
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 |
9299 | 524 return list instanceof Number ? (Number) list : Double.valueOf(Double.MAX_VALUE); |
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
|
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 |
9299 | 527 public static Number minNumber(final 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
|
528 if (list instanceof Collection) { |
9299 | 529 final Collection collection = (Collection) 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
|
530 double min = Double.MAX_VALUE; |
9299 | 531 for (final Object x : collection) { |
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
|
532 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
|
533 if (x instanceof Number) { |
9299 | 534 n = (Number) x; |
535 } else if (x instanceof String) { | |
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
|
536 try { |
9299 | 537 n = Double.valueOf((String) x); |
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
|
538 } |
9299 | 539 catch (final NumberFormatException nfe) { |
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
|
540 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
|
541 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
|
542 } |
9299 | 543 } else { |
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
|
544 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
|
545 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
|
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 |
9299 | 548 final double v = n.doubleValue(); |
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
|
549 |
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 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
|
551 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
|
552 } |
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 } |
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 |
9299 | 555 return Double.valueOf(min == Double.MAX_VALUE ? -Double.MAX_VALUE : min); |
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
|
556 } |
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
|
557 |
9299 | 558 return list instanceof Number ? (Number) list : Double.valueOf(-Double.MAX_VALUE); |
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
|
559 } |
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
|
560 |
9299 | 561 public static Object coalesce(final List list) { |
562 for (final Object x : list) { | |
563 if (x instanceof String && ((String) x).length() != 0) { | |
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
|
564 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
|
565 } |
9299 | 566 if (x instanceof Number && ((Number) x).doubleValue() != 0.0) { |
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
|
567 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
|
568 } |
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
|
569 } |
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
|
570 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
|
571 } |
8960
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
572 |
9299 | 573 private Object column(final Object argument) { |
574 | |
575 if (!(argument instanceof String)) | |
8960
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
576 throw new IllegalArgumentException("Argument of 'column' function must be a string"); |
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
577 |
9299 | 578 final String columnName = (String) argument; |
579 | |
580 final StackFrames frms = this.buildHelper.frames; | |
581 | |
8960
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
582 return frms.getNull(columnName); |
66ce19d2c5f1
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.
gernotbelger
parents:
8856
diff
changeset
|
583 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
584 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
585 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |