Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java @ 961:3ba4f5a88c20
Datacage template: Added a new 'if' construct similiar to XSLT
flys-artifacts/trunk@2380 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 20 Jul 2011 20:13:49 +0000 |
parents | a2b20ed3d3b4 |
children | 2de1808503be |
line wrap: on
line diff
--- 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); }