[Dive4elements-commits] [PATCH] Datacage: Repaired and simplified dc:filter code

Wald Commits scm-commit at wald.intevation.org
Thu May 2 21:23:59 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1367522624 -7200
# Node ID 9a3ca7532f2a190a5fa68df4d0d234d90a223d9b
# Parent  f59ff0ddc00486365f69b1123382f6e6cd8ab9db
Datacage: Repaired and simplified dc:filter code.

diff -r f59ff0ddc004 -r 9a3ca7532f2a 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 02 20:55:08 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java	Thu May 02 21:23:44 2013 +0200
@@ -263,9 +263,21 @@
                 && !connectionsStack.peek().getB().isEmpty();
         }
 
-        protected ResultData createFilteredResultData(ResultData rd, String filter) {
+        protected ResultData createFilteredResultData(
+            ResultData rd,
+            String     filter
+        ) {
             if (filter == null) return rd;
 
+            XPathExpression x;
+            try {
+                x = getXPathExpression(filter);
+            }
+            catch (XPathExpressionException xee) {
+                log.warn("Invalid filter expression '" + filter + "'.");
+                return rd;
+            }
+
             List<Object []> rows = rd.getRows();
             String [] columns = rd.getColumnLabels();
 
@@ -275,21 +287,22 @@
                 frames.enter();
                 try {
                     frames.put(columns, row);
-                    boolean traverse = filter == null;
+                    Object result = x.evaluate(
+                        EVAL_DOCUMENT, XPathConstants.BOOLEAN);
 
-                    if (!traverse) {
-                        Boolean b = evaluateXPathToBoolean(filter);
-                        traverse = b != null && b;
-                    }
-                    if (traverse) {
+                    if (result instanceof Boolean && (Boolean)result) {
                         filtered.add(row);
                     }
                 }
+                catch (XPathExpressionException xee) {
+                    log.warn("unable to apply filter expression '" +
+                        filter + "' to dataset.");
+                }
                 finally {
                     frames.leave();
                 }
             }
-            return new ResultData(rd.getColumnLabels(), filtered);
+            return new ResultData(columns, filtered);
         }
 
         protected void filter(Node parent, Element current)


More information about the Dive4elements-commits mailing list