[PATCH] Datacage: Make it possible to group a value tuple into more than one group
Wald Commits
scm-commit at wald.intevation.org
Fri Jun 20 16:26:30 CEST 2014
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1403274386 -7200
# Node ID fbab10c21e0ba072a3cf949bdde78a836d422630
# Parent 8e320b5933dea471672ff2c2624a0fbedb8cdcd1
Datacage: Make it possible to group a value tuple into more than one group.
diff -r 8e320b5933de -r fbab10c21e0b artifacts/doc/datacage_ref_de.rst
--- a/artifacts/doc/datacage_ref_de.rst Fri Jun 20 13:45:54 2014 +0200
+++ b/artifacts/doc/datacage_ref_de.rst Fri Jun 20 16:26:26 2014 +0200
@@ -407,6 +407,16 @@
</marke>
</marken>
+Der Expr-Ausdruck kann mittels der Zeichenfolge '#!#' innerhalb des Ausdrucks
+in mehrere Ausdrücke zerlegt werden. Damit ist es möglich, einen Wert
+in mehrere Kategorien einzusortieren. Wird z.B. ein Film über den Zeitraum
+von zwei Jahren gedreht und man möchte eine Liste von Filmen nach ihren
+Produktionsjahren gruppieren, sollte der Film im Resulat in beiden Jahren auftauchen.
+
+.. code:: xml
+
+ <dc:group expr="$start_jahr #!# $end_jahr">
+
Datensätze auffalten
~~~~~~~~~~~~~~~~~~~~
diff -r 8e320b5933de -r fbab10c21e0b 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 Fri Jun 20 13:45:54 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java Fri Jun 20 16:26:26 2014 +0200
@@ -54,6 +54,9 @@
{
private static Logger log = Logger.getLogger(Builder.class);
+ public static final Pattern MAGIC_EXPR_SEPARATOR =
+ Pattern.compile("#!#");
+
public static final Pattern STRIP_LINE_INDENT =
Pattern.compile("\\s*\\r?\\n\\s*");
@@ -506,9 +509,14 @@
List<Object []> rows = rd.getRows();
String [] columns = rd.getColumnLabels();
- XPathExpression x;
+ String [] exprs = MAGIC_EXPR_SEPARATOR.split(expr);
+
+ XPathExpression [] xs = new XPathExpression[exprs.length];
+
try {
- x = getXPathExpression(expr);
+ for (int i = 0; i < exprs.length; ++i) {
+ xs[i] = getXPathExpression(exprs[i]);
+ }
}
catch (XPathExpressionException xee) {
log.warn("Invalid expression '" + expr + "'.");
@@ -524,16 +532,16 @@
try {
frames.put(columns, row);
- Object key = x.evaluate(EVAL_DOCUMENT, returnType);
+ for (XPathExpression x: xs) {
+ Object key = x.evaluate(EVAL_DOCUMENT, returnType);
+ ResultData group = groups.get(key);
- ResultData group = groups.get(key);
-
- if (group == null) {
- group = new ResultData(rd.getColumnLabels());
- groups.put(key, group);
+ if (group == null) {
+ group = new ResultData(rd.getColumnLabels());
+ groups.put(key, group);
+ }
+ group.add(row);
}
-
- group.add(row);
}
catch (XPathExpressionException xxe) {
log.warn("unable to apply expression '" +
More information about the Dive4Elements-commits
mailing list