1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 package org.jaxen;
64
65 import org.jaxen.function.BooleanFunction;
66 import org.jaxen.function.CeilingFunction;
67 import org.jaxen.function.ConcatFunction;
68 import org.jaxen.function.ContainsFunction;
69 import org.jaxen.function.CountFunction;
70 import org.jaxen.function.FalseFunction;
71 import org.jaxen.function.FloorFunction;
72 import org.jaxen.function.IdFunction;
73 import org.jaxen.function.LangFunction;
74 import org.jaxen.function.LastFunction;
75 import org.jaxen.function.LocalNameFunction;
76 import org.jaxen.function.NameFunction;
77 import org.jaxen.function.NamespaceUriFunction;
78 import org.jaxen.function.NormalizeSpaceFunction;
79 import org.jaxen.function.NotFunction;
80 import org.jaxen.function.NumberFunction;
81 import org.jaxen.function.PositionFunction;
82 import org.jaxen.function.RoundFunction;
83 import org.jaxen.function.StartsWithFunction;
84 import org.jaxen.function.StringFunction;
85 import org.jaxen.function.StringLengthFunction;
86 import org.jaxen.function.SubstringAfterFunction;
87 import org.jaxen.function.SubstringBeforeFunction;
88 import org.jaxen.function.SubstringFunction;
89 import org.jaxen.function.SumFunction;
90 import org.jaxen.function.TranslateFunction;
91 import org.jaxen.function.TrueFunction;
92 import org.jaxen.function.ext.EndsWithFunction;
93 import org.jaxen.function.ext.EvaluateFunction;
94 import org.jaxen.function.ext.LowerFunction;
95 import org.jaxen.function.ext.MatrixConcatFunction;
96 import org.jaxen.function.ext.UpperFunction;
97 import org.jaxen.function.xslt.DocumentFunction;
98
99 /*** A <code>FunctionContext</code> implementing the core XPath
100 * function library, with extensions.
101 *
102 * <p>
103 * The core XPath function library is provided through this
104 * implementation of <code>FunctionContext</code>. Additionally,
105 * extension functions have been provided, as enumerated below.
106 * </p>
107 *
108 * <p>
109 * This class implements a <i>Singleton</i> pattern (see {@link #getInstance}),
110 * as it is perfectly re-entrant and thread-safe. If using the
111 * singleton, it is inadvisable to call {@link #registerFunction(String, String, Function)}
112 * as that will extend the global function context, affecting other
113 * users of the singleton. But that's your call, really, now isn't
114 * it? That may be what you really want to do.
115 * </p>
116 *
117 * <p>
118 * Extension functions:
119 *
120 * <ul>
121 * <li>matrix-concat(..)</li>
122 * <li>evaluate(..)</li>
123 * </ul>
124 *
125 * @see FunctionContext
126 *
127 * @author <a href="mailto:bob@werken.com">bob mcwhirter</a>
128 */
129 public class XPathFunctionContext extends SimpleFunctionContext
130 {
131 /*** Singleton implementation.
132 */
133 private static class Singleton
134 {
135 /*** Singleton instance.
136 */
137 private static XPathFunctionContext instance = new XPathFunctionContext();
138 }
139
140 /*** Retrieve the singleton instance.
141 *
142 * @return the singleton instance
143 */
144 public static FunctionContext getInstance()
145 {
146 return Singleton.instance;
147 }
148
149 /*** Construct.
150 *
151 * <p>
152 * Construct with all core XPath functions registered.
153 * </p>
154 */
155 public XPathFunctionContext()
156 {
157
158 registerFunction( null,
159 "boolean",
160 new BooleanFunction() );
161
162 registerFunction( null,
163 "ceiling",
164 new CeilingFunction() );
165
166 registerFunction( null,
167 "concat",
168 new ConcatFunction() );
169
170 registerFunction( null,
171 "contains",
172 new ContainsFunction() );
173
174 registerFunction( null,
175 "count",
176 new CountFunction() );
177
178 registerFunction( null,
179 "document",
180 new DocumentFunction() );
181
182 registerFunction( null,
183 "false",
184 new FalseFunction() );
185
186 registerFunction( null,
187 "floor",
188 new FloorFunction() );
189
190 registerFunction( null,
191 "id",
192 new IdFunction() );
193
194 registerFunction( null,
195 "lang",
196 new LangFunction() );
197
198 registerFunction( null,
199 "last",
200 new LastFunction() );
201
202 registerFunction( null,
203 "local-name",
204 new LocalNameFunction() );
205
206 registerFunction( null,
207 "name",
208 new NameFunction() );
209
210 registerFunction( null,
211 "namespace-uri",
212 new NamespaceUriFunction() );
213
214 registerFunction( null,
215 "normalize-space",
216 new NormalizeSpaceFunction() );
217
218 registerFunction( null,
219 "not",
220 new NotFunction() );
221
222 registerFunction( null,
223 "number",
224 new NumberFunction() );
225
226 registerFunction( null,
227 "position",
228 new PositionFunction() );
229
230 registerFunction( null,
231 "round",
232 new RoundFunction() );
233
234 registerFunction( null,
235 "starts-with",
236 new StartsWithFunction() );
237
238 registerFunction( null,
239 "string",
240 new StringFunction() );
241
242 registerFunction( null,
243 "string-length",
244 new StringLengthFunction() );
245
246 registerFunction( null,
247 "substring-after",
248 new SubstringAfterFunction() );
249
250 registerFunction( null,
251 "substring-before",
252 new SubstringBeforeFunction() );
253
254 registerFunction( null,
255 "substring",
256 new SubstringFunction() );
257
258 registerFunction( null,
259 "sum",
260 new SumFunction() );
261
262 registerFunction( null,
263 "true",
264 new TrueFunction() );
265
266 registerFunction( null,
267 "translate",
268 new TranslateFunction() );
269
270
271
272
273
274
275 registerFunction( null,
276 "matrix-concat",
277 new MatrixConcatFunction() );
278
279 registerFunction( null,
280 "evaluate",
281 new EvaluateFunction() );
282
283 registerFunction( null,
284 "lower-case",
285 new LowerFunction() );
286
287 registerFunction( null,
288 "upper-case",
289 new UpperFunction() );
290
291 registerFunction( null,
292 "ends-with",
293 new EndsWithFunction() );
294
295 }
296 }