# HG changeset patch # User Andre Heinecke # Date 1365084444 -7200 # Node ID f8a4ee86d2765bd03dcde9ff061671f0065b723a # Parent ccda0a49a97f199b04e7ef76a1fb5365360e6758 Add dc:replace function for datacage diff -r ccda0a49a97f -r f8a4ee86d276 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java Thu Apr 04 16:07:02 2013 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java Thu Apr 04 16:07:24 2013 +0200 @@ -75,6 +75,13 @@ } }); + addFunction("replace", 3, new XPathFunction() { + @Override + public Object evaluate(List args) throws XPathFunctionException { + return replace(args); + } + }); + addFunction("has-result", 0, new XPathFunction() { @Override public Object evaluate(List args) throws XPathFunctionException { @@ -251,5 +258,23 @@ return 99999d; } } + + /** Implementation for doing a string replace + * dc:replace + */ + public Object replace(List args) throws XPathFunctionException { + Object haystack = args.get(0); + Object needle = args.get(1); + Object replacement = args.get(2); + + if (needle instanceof String && + haystack instanceof String && + replacement instanceof String) { + return ((String)haystack).replace( + (String)needle, (String)replacement); + } else { + return haystack; + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :