changeset 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 92027887775a
children 2de1808503be
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java
diffstat 2 files changed, 37 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java:
+	  Added a new 'if' construct similiar to XSLT:
+
+	    <dc:if test="not(dc:contains($outs, '5'))">
+	        <dc:text>'5' ist nicht in der Liste der Outs.</dc:text>
+	    </dc:if>
+
+	  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 <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.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);
                     }

http://dive4elements.wald.intevation.org