changeset 5561:f8a4ee86d276

Add dc:replace function for datacage
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 04 Apr 2013 16:07:24 +0200
parents ccda0a49a97f
children 7be6785ad7b9
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 :

http://dive4elements.wald.intevation.org