[Dive4elements-commits] [PATCH] Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion

Wald Commits scm-commit at wald.intevation.org
Thu May 23 18:14:38 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1369325671 -7200
# Node ID 4bd8bbbcdf688ada2b7c53800ee0ead643a7ecdf
# Parent  a0dbc60f78ee151857e261bc320a57daed53503f
Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.

diff -r a0dbc60f78ee -r 4bd8bbbcdf68 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java
--- 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));
             }
         }
 
diff -r a0dbc60f78ee -r 4bd8bbbcdf68 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java
--- 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();
+            }
+        });
     }
 
     /**


More information about the Dive4elements-commits mailing list