changeset 6080:4bd8bbbcdf68

Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 23 May 2013 18:14:31 +0200
parents a0dbc60f78ee
children cdd9759b15b6
files artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java
diffstat 2 files changed, 30 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java	Thu May 23 17:32:45 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java	Thu May 23 18:14:31 2013 +0200
@@ -582,7 +582,10 @@
         {
             log.debug("dc:message");
             if (log.isInfoEnabled()) {
-                String value = expand(current.getTextContent());
+                String value = current.getTextContent();
+                if (value.indexOf('{') >= 0) { // Performance tweak
+                    value = expandXPathValue(value);
+                }
                 log.info("MESSAGE: " + value);
             }
         }
@@ -831,23 +834,27 @@
             return sb.toString();
         }
 
+        protected String expandXPathValue(String value) {
+            StringBuffer sb = new StringBuffer();
+            Matcher m = BRACKET_XPATH.matcher(value);
+            while (m.find()) {
+                String expr = m.group(1);
+                Object result = evaluateXPath(expr, XPathConstants.STRING);
+                if (result instanceof String) {
+                    m.appendReplacement(sb, (String)result);
+                }
+                else {
+                    m.appendReplacement(sb, "");
+                }
+            }
+            m.appendTail(sb);
+            return sb.toString();
+        }
+
         protected void evaluateAttributeValue(Attr attr) {
             String value = attr.getValue();
-            if (value.indexOf('{') >= 0) {
-                StringBuffer sb = new StringBuffer();
-                Matcher m = BRACKET_XPATH.matcher(value);
-                while (m.find()) {
-                    String expr = m.group(1);
-                    Object result = evaluateXPath(expr, XPathConstants.STRING);
-                    if (result instanceof String) {
-                        m.appendReplacement(sb, (String)result);
-                    }
-                    else {
-                        m.appendReplacement(sb, "");
-                    }
-                }
-                m.appendTail(sb);
-                attr.setValue(sb.toString());
+            if (value.indexOf('{') >= 0) { // Performance tweak
+                attr.setValue(expandXPathValue(value));
             }
         }
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Thu May 23 17:32:45 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Thu May 23 18:14:31 2013 +0200
@@ -117,6 +117,13 @@
                 return dateFormat(args);
             }
         });
+
+        addFunction("dump-variables", 0, new XPathFunction() {
+            @Override
+            public Object evaluate(List args) throws XPathFunctionException {
+                return FunctionResolver.this.buildHelper.frames.dump();
+            }
+        });
     }
 
     /**

http://dive4elements.wald.intevation.org