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 is re-entrant and thread-safe. If using the
110 * default instance, it is inadvisable to call
111 * {@link #registerFunction(String, String, Function)}
112 * as that will extend the global function context, affecting other
113 * users. 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 * <li>upper-case(..)</li>
124 * <li>lower-case(..)</li>
125 * <li>ends-with(..)</li>
126 * </ul>
127 *
128 * @see FunctionContext
129 * @see org.jaxen.function
130 * @see org.jaxen.function.xslt
131 * @see org.jaxen.function.ext
132 *
133 * @author <a href="mailto:bob@werken.com">bob mcwhirter</a>
134 */
135 public class XPathFunctionContext extends SimpleFunctionContext
136 {
137 private static XPathFunctionContext instance = new XPathFunctionContext();
138
139 /*** Retrieve the default function context
140 *
141 * @return the default function context
142 */
143 public static FunctionContext getInstance()
144 {
145 return instance;
146 }
147
148 /*** Create a new XPath function context.
149 * All core XPath and Jaxen extension functions are registered.
150 */
151 public XPathFunctionContext()
152 {
153 registerFunction( null,
154 "boolean",
155 new BooleanFunction() );
156
157 registerFunction( null,
158 "ceiling",
159 new CeilingFunction() );
160
161 registerFunction( null,
162 "concat",
163 new ConcatFunction() );
164
165 registerFunction( null,
166 "contains",
167 new ContainsFunction() );
168
169 registerFunction( null,
170 "count",
171 new CountFunction() );
172
173 registerFunction( null,
174 "false",
175 new FalseFunction() );
176
177 registerFunction( null,
178 "floor",
179 new FloorFunction() );
180
181 registerFunction( null,
182 "id",
183 new IdFunction() );
184
185 registerFunction( null,
186 "lang",
187 new LangFunction() );
188
189 registerFunction( null,
190 "last",
191 new LastFunction() );
192
193 registerFunction( null,
194 "local-name",
195 new LocalNameFunction() );
196
197 registerFunction( null,
198 "name",
199 new NameFunction() );
200
201 registerFunction( null,
202 "namespace-uri",
203 new NamespaceUriFunction() );
204
205 registerFunction( null,
206 "normalize-space",
207 new NormalizeSpaceFunction() );
208
209 registerFunction( null,
210 "not",
211 new NotFunction() );
212
213 registerFunction( null,
214 "number",
215 new NumberFunction() );
216
217 registerFunction( null,
218 "position",
219 new PositionFunction() );
220
221 registerFunction( null,
222 "round",
223 new RoundFunction() );
224
225 registerFunction( null,
226 "starts-with",
227 new StartsWithFunction() );
228
229 registerFunction( null,
230 "string",
231 new StringFunction() );
232
233 registerFunction( null,
234 "string-length",
235 new StringLengthFunction() );
236
237 registerFunction( null,
238 "substring-after",
239 new SubstringAfterFunction() );
240
241 registerFunction( null,
242 "substring-before",
243 new SubstringBeforeFunction() );
244
245 registerFunction( null,
246 "substring",
247 new SubstringFunction() );
248
249 registerFunction( null,
250 "sum",
251 new SumFunction() );
252
253 registerFunction( null,
254 "true",
255 new TrueFunction() );
256
257 registerFunction( null,
258 "translate",
259 new TranslateFunction() );
260
261
262 registerFunction( null,
263 "document",
264 new DocumentFunction() );
265
266
267
268
269
270 registerFunction( null,
271 "matrix-concat",
272 new MatrixConcatFunction() );
273
274 registerFunction( null,
275 "evaluate",
276 new EvaluateFunction() );
277
278 registerFunction( null,
279 "lower-case",
280 new LowerFunction() );
281
282 registerFunction( null,
283 "upper-case",
284 new UpperFunction() );
285
286 registerFunction( null,
287 "ends-with",
288 new EndsWithFunction() );
289
290 }
291 }