[Dive4elements-commits] [PATCH 1 of 8] Added filter to elements in datacage templating. (most work done by Sascha T.)
Wald Commits
scm-commit at wald.intevation.org
Thu Mar 14 17:27:29 CET 2013
# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1363277384 -3600
# Node ID e60f65540cc24c92c052041baf118a42be15564f
# Parent ffa5eaad3a7b8518f235660a5ba67353a09d7872
Added filter to elements in datacage templating. (most work done by Sascha T.).
diff -r ffa5eaad3a7b -r e60f65540cc2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Thu Mar 14 16:49:32 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Thu Mar 14 17:09:44 2013 +0100
@@ -236,6 +236,36 @@
}
}
+
+ protected ResultData createFilteredResultData(ResultData rd, String filter) {
+ if (filter == null) return rd;
+
+ List<Object []> rows = rd.getRows();
+ String [] columns = rd.getColumnLabels();
+
+ List<Object []> filtered = new ArrayList<Object[]>(rows.size());
+
+ for (Object [] row: rows) {
+ frames.enter();
+ try {
+ frames.put(columns, row);
+ boolean traverse = filter == null;
+
+ if (!traverse) {
+ Boolean b = evaluateXPathToBoolean(filter);
+ traverse = b != null && b;
+ }
+ if (traverse) {
+ filtered.add(row);
+ }
+ }
+ finally {
+ frames.leave();
+ }
+ }
+ return new ResultData(rd.getColumnLabels(), filtered);
+ }
+
/**
* Kind of foreach over results of a statement within a context.
*/
@@ -249,6 +279,12 @@
return;
}
+ String filter = current.getAttribute("filter");
+
+ if ((filter = filter.trim()).length() == 0) {
+ filter = null;
+ }
+
NodeList subs = current.getChildNodes();
int S = subs.getLength();
@@ -257,29 +293,45 @@
return;
}
+ Pair<Builder.NamedConnection, ResultData> pair =
+ connectionsStack.peek();
+
ResultData rd = connectionsStack.peek().getB();
+ ResultData orig = rd;
- String [] columns = rd.getColumnLabels();
+ if (filter != null) {
+ ResultData rdCopy = createFilteredResultData(rd, filter);
+ pair.setB(rdCopy);
+ rd = rdCopy;
+ }
+ try {
+ String [] columns = rd.getColumnLabels();
- //if (log.isDebugEnabled()) {
- // log.debug("pushing vars: "
- // + java.util.Arrays.toString(columns));
- //}
+ //if (log.isDebugEnabled()) {
+ // log.debug("pushing vars: "
+ // + java.util.Arrays.toString(columns));
+ //}
- for (Object [] row: rd.getRows()) {
- frames.enter();
- try {
- frames.put(columns, row);
- //if (log.isDebugEnabled()) {
- // log.debug("current vars: " + frames.dump());
- //}
- for (int i = 0; i < S; ++i) {
- build(parent, subs.item(i));
+ for (Object [] row: rd.getRows()) {
+ frames.enter();
+ try {
+ frames.put(columns, row);
+ //if (log.isDebugEnabled()) {
+ // log.debug("current vars: " + frames.dump());
+ //}
+ for (int i = 0; i < S; ++i) {
+ build(parent, subs.item(i));
+ }
+ }
+ finally {
+ frames.leave();
}
}
- finally {
- frames.leave();
- }
+ }
+ finally {
+ if (filter != null) {
+ pair.setB(orig);
+ }
}
}
diff -r ffa5eaad3a7b -r e60f65540cc2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/ResultData.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/ResultData.java Thu Mar 14 16:49:32 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/ResultData.java Thu Mar 14 17:09:44 2013 +0100
@@ -25,6 +25,11 @@
public ResultData() {
rows = new ArrayList<Object []>();
}
+
+ public ResultData(String [] columns, List<Object []> rows) {
+ this.columns = columns;
+ this.rows = rows;
+ }
public ResultData(ResultSetMetaData meta)
throws SQLException
More information about the Dive4elements-commits
mailing list