changeset 124:b7a9557957d1

Appende the static data to the static node of the DESCRIBE document. flys-artifacts/trunk@1452 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 Mar 2011 13:31:36 +0000
parents ebb1cb69d847
children 25593857b8f8
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java
diffstat 2 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Mar 10 08:38:05 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Mar 10 13:31:36 2011 +0000
@@ -1,3 +1,9 @@
+2011-03-10  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Appended
+	  the data that have been inserted in former states into the static node
+	  of the DESCRIBE.
+
 2011-03-10  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: The
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Mar 10 08:38:05 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Mar 10 13:31:36 2011 +0000
@@ -1,9 +1,13 @@
 package de.intevation.flys.artifacts;
 
 import java.util.List;
+import java.util.Set;
+
+import javax.xml.xpath.XPathConstants;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 import org.apache.log4j.Logger;
 
@@ -11,6 +15,7 @@
 import de.intevation.artifacts.CallContext;
 
 import de.intevation.artifactdatabase.ProtocolUtils;
+import de.intevation.artifactdatabase.data.StateData;
 import de.intevation.artifactdatabase.state.State;
 import de.intevation.artifactdatabase.state.StateEngine;
 import de.intevation.artifactdatabase.transition.TransitionEngine;
@@ -34,6 +39,9 @@
     /** The name of the artifact.*/
     public static final String ARTIFACT_NAME = "winfo";
 
+    /** XPath */
+    public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static";
+
 
     /**
      * The default constructor.
@@ -87,6 +95,14 @@
 
         current.describe(description, root, context, identifier());
 
+        Node ui = (Node) XMLUtils.xpath(
+            description,
+            XPATH_STATIC_UI,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        appendStaticUI(creator, ui);
+
         return description;
     }
 
@@ -99,5 +115,37 @@
     public String getName() {
         return ARTIFACT_NAME;
     }
+
+
+    /**
+     * This method appends the static data - that has already been inserted by
+     * the user - to the static node of the DESCRIBE document.
+     *
+     * @param cr The ElementCreator that is used to create new elements.
+     * @param ui The static ui node.
+     */
+    protected void appendStaticUI(XMLUtils.ElementCreator cr, Node ui) {
+        Set<String> keys = data.keySet();
+
+        // XXX This just handles single selection string values. If we need more
+        // complex (maybe multiselect) objects we should introduce a data
+        // structure for this - this structure should have a method that returns
+        // a <data> node that contains its items.
+        for (String k: keys) {
+            logger.debug("The key = " + k);
+            StateData d = getData(k);
+
+            Element dataElement = cr.create("data");
+            cr.addAttr(dataElement, "name", (String) d.getName(), true);
+            cr.addAttr(dataElement, "type", d.getType(), true);
+
+            Element itemElement = cr.create("item");
+            cr.addAttr(itemElement, "value", (String) d.getValue(), true);
+            // TODO Description (human readable) is missing
+
+            dataElement.appendChild(itemElement);
+            ui.appendChild(dataElement);
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org