comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java @ 6080:4bd8bbbcdf68

Datacage: Introduced dc:dump-variables() and modified dc:message to use XPath expansion.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 23 May 2013 18:14:31 +0200
parents c7777feea223
children 47775e3a8cf6
comparison
equal deleted inserted replaced
6079:a0dbc60f78ee 6080:4bd8bbbcdf68
580 protected void message(Node parent, Element current) 580 protected void message(Node parent, Element current)
581 throws SQLException 581 throws SQLException
582 { 582 {
583 log.debug("dc:message"); 583 log.debug("dc:message");
584 if (log.isInfoEnabled()) { 584 if (log.isInfoEnabled()) {
585 String value = expand(current.getTextContent()); 585 String value = current.getTextContent();
586 if (value.indexOf('{') >= 0) { // Performance tweak
587 value = expandXPathValue(value);
588 }
586 log.info("MESSAGE: " + value); 589 log.info("MESSAGE: " + value);
587 } 590 }
588 } 591 }
589 592
590 /** 593 /**
829 } 832 }
830 m.appendTail(sb); 833 m.appendTail(sb);
831 return sb.toString(); 834 return sb.toString();
832 } 835 }
833 836
837 protected String expandXPathValue(String value) {
838 StringBuffer sb = new StringBuffer();
839 Matcher m = BRACKET_XPATH.matcher(value);
840 while (m.find()) {
841 String expr = m.group(1);
842 Object result = evaluateXPath(expr, XPathConstants.STRING);
843 if (result instanceof String) {
844 m.appendReplacement(sb, (String)result);
845 }
846 else {
847 m.appendReplacement(sb, "");
848 }
849 }
850 m.appendTail(sb);
851 return sb.toString();
852 }
853
834 protected void evaluateAttributeValue(Attr attr) { 854 protected void evaluateAttributeValue(Attr attr) {
835 String value = attr.getValue(); 855 String value = attr.getValue();
836 if (value.indexOf('{') >= 0) { 856 if (value.indexOf('{') >= 0) { // Performance tweak
837 StringBuffer sb = new StringBuffer(); 857 attr.setValue(expandXPathValue(value));
838 Matcher m = BRACKET_XPATH.matcher(value);
839 while (m.find()) {
840 String expr = m.group(1);
841 Object result = evaluateXPath(expr, XPathConstants.STRING);
842 if (result instanceof String) {
843 m.appendReplacement(sb, (String)result);
844 }
845 else {
846 m.appendReplacement(sb, "");
847 }
848 }
849 m.appendTail(sb);
850 attr.setValue(sb.toString());
851 } 858 }
852 } 859 }
853 860
854 protected void build(Node parent, Node current) 861 protected void build(Node parent, Node current)
855 throws SQLException 862 throws SQLException

http://dive4elements.wald.intevation.org