changeset 5892:9a3ca7532f2a

Datacage: Repaired and simplified dc:filter code.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 02 May 2013 21:23:44 +0200
parents f59ff0ddc004
children c1abd48a03e2
files artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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)

http://dive4elements.wald.intevation.org