comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java @ 7960:fbab10c21e0b

Datacage: Make it possible to group a value tuple into more than one group.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 20 Jun 2014 16:26:26 +0200
parents 36e28ec7ff16
children 7021753b3797
comparison
equal deleted inserted replaced
7959:8e320b5933de 7960:fbab10c21e0b
51 51
52 /** Handles and evaluate meta-data template against dbs. */ 52 /** Handles and evaluate meta-data template against dbs. */
53 public class Builder 53 public class Builder
54 { 54 {
55 private static Logger log = Logger.getLogger(Builder.class); 55 private static Logger log = Logger.getLogger(Builder.class);
56
57 public static final Pattern MAGIC_EXPR_SEPARATOR =
58 Pattern.compile("#!#");
56 59
57 public static final Pattern STRIP_LINE_INDENT = 60 public static final Pattern STRIP_LINE_INDENT =
58 Pattern.compile("\\s*\\r?\\n\\s*"); 61 Pattern.compile("\\s*\\r?\\n\\s*");
59 62
60 public static final Pattern BRACKET_XPATH = 63 public static final Pattern BRACKET_XPATH =
504 String type 507 String type
505 ) { 508 ) {
506 List<Object []> rows = rd.getRows(); 509 List<Object []> rows = rd.getRows();
507 String [] columns = rd.getColumnLabels(); 510 String [] columns = rd.getColumnLabels();
508 511
509 XPathExpression x; 512 String [] exprs = MAGIC_EXPR_SEPARATOR.split(expr);
513
514 XPathExpression [] xs = new XPathExpression[exprs.length];
515
510 try { 516 try {
511 x = getXPathExpression(expr); 517 for (int i = 0; i < exprs.length; ++i) {
518 xs[i] = getXPathExpression(exprs[i]);
519 }
512 } 520 }
513 catch (XPathExpressionException xee) { 521 catch (XPathExpressionException xee) {
514 log.warn("Invalid expression '" + expr + "'."); 522 log.warn("Invalid expression '" + expr + "'.");
515 return Collections.<Object, ResultData>emptyMap(); 523 return Collections.<Object, ResultData>emptyMap();
516 } 524 }
522 for (Object [] row: rows) { 530 for (Object [] row: rows) {
523 frames.enter(); 531 frames.enter();
524 try { 532 try {
525 frames.put(columns, row); 533 frames.put(columns, row);
526 534
527 Object key = x.evaluate(EVAL_DOCUMENT, returnType); 535 for (XPathExpression x: xs) {
528 536 Object key = x.evaluate(EVAL_DOCUMENT, returnType);
529 ResultData group = groups.get(key); 537 ResultData group = groups.get(key);
530 538
531 if (group == null) { 539 if (group == null) {
532 group = new ResultData(rd.getColumnLabels()); 540 group = new ResultData(rd.getColumnLabels());
533 groups.put(key, group); 541 groups.put(key, group);
534 } 542 }
535 543 group.add(row);
536 group.add(row); 544 }
537 } 545 }
538 catch (XPathExpressionException xxe) { 546 catch (XPathExpressionException xxe) {
539 log.warn("unable to apply expression '" + 547 log.warn("unable to apply expression '" +
540 expr + "' to dataset."); 548 expr + "' to dataset.");
541 } 549 }

http://dive4elements.wald.intevation.org