Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java @ 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).
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 30 May 2013 06:04:00 +0200 |
parents | 4bd8bbbcdf68 |
children | 4edad3e414cb |
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; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.util.Collection; |
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.util.Date; |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
14 import java.util.List; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 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
|
16 import java.util.HashMap; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
5784
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
18 import java.lang.reflect.InvocationTargetException; |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
19 import java.lang.reflect.Method; |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
20 |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
21 import javax.xml.namespace.QName; |
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
22 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 import javax.xml.xpath.XPathFunction; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import javax.xml.xpath.XPathFunctionException; |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4926
diff
changeset
|
25 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
|
26 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 import org.apache.log4j.Logger; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
4594 | 29 |
30 /** 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
|
31 public class FunctionResolver |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 implements XPathFunctionResolver |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 { |
4594 | 34 /** Home logger. */ |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 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
|
36 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 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
|
38 |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
39 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
|
40 |
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
|
41 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
|
42 |
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
|
43 Entry next; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 XPathFunction function; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 int arity; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
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
|
47 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
|
48 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
|
49 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
|
50 this.arity = arity; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
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 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 } |
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 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
|
60 } |
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 null; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 } // class Entry |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
4594 | 65 /** 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
|
66 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
|
67 |
5432
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
68 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
|
69 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
70 |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 public FunctionResolver() { |
5432
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
72 this(null); |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
73 } |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
74 |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
75 public FunctionResolver(Builder.BuildHelper buildHelper) { |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
76 this.buildHelper = buildHelper; |
d0f5bc8064f1
pass BuildHelper to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5430
diff
changeset
|
77 |
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
|
78 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
|
79 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
80 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
|
81 @Override |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
82 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
|
83 return contains(args); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
84 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
85 }); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
86 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
87 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
|
88 @Override |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
89 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
|
90 return fromValue(args); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
91 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
92 }); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
93 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
94 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
|
95 @Override |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
96 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
|
97 return toValue(args); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
98 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
99 }); |
5433
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
100 |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
101 addFunction("replace", 3, new XPathFunction() { |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
102 @Override |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
103 public Object evaluate(List args) throws XPathFunctionException { |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
104 return replace(args); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
105 } |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
106 }); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
107 |
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
|
108 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
|
109 @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
|
110 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
|
111 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
|
112 } |
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
|
113 }); |
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
|
114 |
5433
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
115 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
|
116 @Override |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
117 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
|
118 return FunctionResolver.this.buildHelper.hasResult(); |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
119 } |
df32d7518f55
Expose function dc:has-result to Function Resolver.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5432
diff
changeset
|
120 }); |
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
|
121 |
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
|
122 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
|
123 @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
|
124 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
|
125 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
|
126 } |
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
|
127 }); |
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
|
128 |
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
|
129 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
|
130 @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
|
131 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
|
132 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
|
133 } |
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
|
134 }); |
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
|
135 |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
136 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
|
137 @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
|
138 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
|
139 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
|
140 } |
4bd8bbbcdf68
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
141 }); |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 |
4594 | 144 /** |
145 * Create a new function. | |
146 * @param name Name of the function. | |
147 * @param arity Number of arguments for function. | |
148 * @param function the function itself. | |
149 */ | |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 } |
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
|
156 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
|
157 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
|
158 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
|
159 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 @Override |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 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
|
164 |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 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
|
166 return null; |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 |
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
|
169 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
|
170 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
|
171 ? 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
|
172 : null; |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 } |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
174 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
175 /** Implementation of case-ignoring dc:contains. */ |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
176 public Object contains(List args) throws XPathFunctionException { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
177 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
|
178 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
|
179 |
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
|
180 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
|
181 needle = ((String)needle).toUpperCase(); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
182 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
183 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
184 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
185 if (haystack instanceof Collection) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
186 return Boolean.valueOf( |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
187 ((Collection)haystack).contains(needle)); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
188 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
189 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
190 if (haystack instanceof Map) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
191 return Boolean.valueOf( |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
192 ((Map)haystack).containsKey(needle)); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
193 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
194 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
195 if (haystack instanceof Object []) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
196 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
|
197 if (straw.equals(needle)) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
198 return Boolean.TRUE; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
199 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
200 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
201 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
202 |
5629
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
203 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
|
204 String h = (String)haystack; |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
205 String n = (String)needle; |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
206 return h.contains(n); |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
207 } |
ce982943ab46
Datacage: dc:contains() is now able to process strings
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5608
diff
changeset
|
208 |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
209 return Boolean.FALSE; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
210 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
211 catch (Exception e) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
212 log.error(e); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
213 throw new XPathFunctionException(e); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
214 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
215 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
216 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
217 /** 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
|
218 * dc:fromValue. |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
219 */ |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
220 public Object fromValue(List args) throws XPathFunctionException { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
225 if (!(mode instanceof String)){ |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
226 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
227 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
228 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
229 if (mode.equals("locations")) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
230 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
|
231 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
232 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
233 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
|
234 String[] split = loc.split(","); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
235 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
|
236 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
237 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
238 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 if (v < min) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
243 min = v; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
244 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
245 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
246 return min; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
247 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
248 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
|
249 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
250 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
251 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
252 else if (mode.equals("distance")) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
253 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
|
254 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
255 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
256 String f = (String)from; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
257 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
258 return Double.parseDouble(f); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
259 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
260 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
|
261 return -FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
262 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
263 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
264 else { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
265 return -FAR_AWAY; |
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 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
268 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
269 /** 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
|
270 * dc:toValue. |
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 public Object toValue(List args) throws XPathFunctionException { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
277 if (!(mode instanceof String)){ |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
278 return FAR_AWAY; |
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 (mode.equals("locations")) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
282 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
|
283 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
284 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
285 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
286 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
|
287 String[] split = loc.split(","); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
288 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
|
289 return FAR_AWAY; |
5430
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 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
|
292 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
|
293 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
|
294 if (v > max) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
295 max = v; |
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 return max; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
299 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
300 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
|
301 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
302 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
303 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
304 else if (mode.equals("distance")) { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
305 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
|
306 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
307 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
308 else { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
309 String t = (String)to; |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
310 try { |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
311 return Double.parseDouble(t); |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
312 } |
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
|
313 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
|
314 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
315 } |
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 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
318 else { |
5604
7e837c5c377b
Datacage: toValue/fromValue: Use constant instead of hard coded number.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5561
diff
changeset
|
319 return FAR_AWAY; |
5430
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
320 } |
ba489a16f4d8
Datacage Function Resolver: Lift from static to object space.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5164
diff
changeset
|
321 } |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
322 |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
323 /** Implementation for doing a string replace |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
324 * dc:replace |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
325 */ |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
326 public Object replace(List args) throws XPathFunctionException { |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
327 Object haystack = args.get(0); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
328 Object needle = args.get(1); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
329 Object replacement = args.get(2); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
330 |
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
|
331 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
|
332 && 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
|
333 && replacement instanceof String) { |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
334 return ((String)haystack).replace( |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
335 (String)needle, (String)replacement); |
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
336 } |
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
|
337 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
|
338 } |
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
|
339 |
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
|
340 /** 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
|
341 * 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
|
342 */ |
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
|
343 public Object replaceAll(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
|
344 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
|
345 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
|
346 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
|
347 |
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
|
348 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
|
349 && 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
|
350 && 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
|
351 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
|
352 (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
|
353 } |
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
|
354 return haystack; |
5561
f8a4ee86d276
Add dc:replace function for datacage
Andre Heinecke <aheinecke@intevation.de>
parents:
5433
diff
changeset
|
355 } |
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
|
356 |
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
|
357 public Object dateFormat(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
|
358 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
|
359 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
|
360 |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
361 try { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
362 // 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
|
363 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
|
364 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
|
365 } catch (IllegalArgumentException e) { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
366 } catch (IllegalAccessException e) { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
367 } catch (InvocationTargetException e) { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
368 } catch (NoSuchMethodException e) { |
efbbfe32e9fe
Fix dateFormat for Oracle by invoking dateValue on demand
Andre Heinecke <aheinecke@intevation.de>
parents:
5630
diff
changeset
|
369 } |
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
|
370 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
|
371 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
|
372 // 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
|
373 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
|
374 } |
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
|
375 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
|
376 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
|
377 } |
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
|
378 } |
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
|
379 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
|
380 } |
998
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
381 } |
b81626b10cb7
Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
382 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |