# HG changeset patch # User Sascha L. Teichmann # Date 1311192829 0 # Node ID 3ba4f5a88c202cc87b40de0c9b941e306cf48752 # Parent 92027887775ac942872cc158d2ddd5ce96bf5e4e Datacage template: Added a new 'if' construct similiar to XSLT flys-artifacts/trunk@2380 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 92027887775a -r 3ba4f5a88c20 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Jul 20 17:03:00 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Jul 20 20:13:49 2011 +0000 @@ -1,3 +1,17 @@ +2011-07-20 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java: + Added a new 'if' construct similiar to XSLT: + + + '5' ist nicht in der Liste der Outs. + + + The control flow is continued inside the 'if' if the 'test' attribute + as an XPath expression on an empty document evalutes to true. + Else the inside is skipped. There is no 'else'. Use 'choose'/'otherwise' + if you need this. + 2011-07-20 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java: diff -r 92027887775a -r 3ba4f5a88c20 flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java Wed Jul 20 17:03:00 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java Wed Jul 20 20:13:49 2011 +0000 @@ -37,8 +37,6 @@ private static final XPathFactory XPATH_FACTORY = XPathFactory.newInstance(); - - protected Document template; public class BuildHelper @@ -182,6 +180,26 @@ element.setAttribute(name, value); } + protected void ifClause(Node parent, Element current) + throws SQLException + { + String test = current.getAttribute("test"); + + if (test.length() == 0) { + log.warn("missing 'test' attribute in 'if'"); + return; + } + + Boolean result = evaluateXPath(test); + + if (result != null && result.booleanValue()) { + NodeList subs = current.getChildNodes(); + for (int i = 0, N = subs.getLength(); i < N; ++i) { + build(parent, subs.item(i)); + } + } + } + protected void choose(Node parent, Element current) throws SQLException { @@ -288,6 +306,9 @@ else if ("choose".equals(localName)) { choose(parent, (Element)current); } + else if ("if".equals(localName)) { + ifClause(parent, (Element)current); + } else if ("attribute".equals(localName)) { attribute(parent, (Element)current); }