Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java @ 5561:f8a4ee86d276
Add dc:replace function for datacage
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 04 Apr 2013 16:07:24 +0200 |
parents | df32d7518f55 |
children | 7e837c5c377b |
comparison
equal
deleted
inserted
replaced
5560:ccda0a49a97f | 5561:f8a4ee86d276 |
---|---|
70 | 70 |
71 addFunction("toValue", 3, new XPathFunction() { | 71 addFunction("toValue", 3, new XPathFunction() { |
72 @Override | 72 @Override |
73 public Object evaluate(List args) throws XPathFunctionException { | 73 public Object evaluate(List args) throws XPathFunctionException { |
74 return toValue(args); | 74 return toValue(args); |
75 } | |
76 }); | |
77 | |
78 addFunction("replace", 3, new XPathFunction() { | |
79 @Override | |
80 public Object evaluate(List args) throws XPathFunctionException { | |
81 return replace(args); | |
75 } | 82 } |
76 }); | 83 }); |
77 | 84 |
78 addFunction("has-result", 0, new XPathFunction() { | 85 addFunction("has-result", 0, new XPathFunction() { |
79 @Override | 86 @Override |
249 } | 256 } |
250 else { | 257 else { |
251 return 99999d; | 258 return 99999d; |
252 } | 259 } |
253 } | 260 } |
261 | |
262 /** Implementation for doing a string replace | |
263 * dc:replace | |
264 */ | |
265 public Object replace(List args) throws XPathFunctionException { | |
266 Object haystack = args.get(0); | |
267 Object needle = args.get(1); | |
268 Object replacement = args.get(2); | |
269 | |
270 if (needle instanceof String && | |
271 haystack instanceof String && | |
272 replacement instanceof String) { | |
273 return ((String)haystack).replace( | |
274 (String)needle, (String)replacement); | |
275 } else { | |
276 return haystack; | |
277 } | |
278 } | |
254 } | 279 } |
255 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 280 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |