diff gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 464:70df44021a9f

Next step of changing the concept how to use the user interface. Adapted namespaces and replaced FISArtifact with a ProxyArtifact. gnv-artifacts/trunk@525 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Sat, 09 Jan 2010 17:55:45 +0000
parents 3ddc22aab764
children b7bb66440cc8
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Sat Jan 09 16:58:53 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Sat Jan 09 17:55:45 2010 +0000
@@ -21,6 +21,8 @@
 import org.w3c.dom.NodeList;
 
 import de.intevation.artifactdatabase.Config;
+import de.intevation.artifactdatabase.XMLUtils;
+import de.intevation.artifacts.ArtifactNamespaceContext;
 import de.intevation.artifacts.CallMeta;
 import de.intevation.gnv.artifacts.GNVArtifactBase;
 import de.intevation.gnv.artifacts.cache.CacheFactory;
@@ -37,7 +39,6 @@
 import de.intevation.gnv.state.describedata.NamedCollection;
 import de.intevation.gnv.state.describedata.SingleValueDescribeData;
 import de.intevation.gnv.state.exception.StateException;
-import de.intevation.gnv.utils.ArtifactXMLUtilities;
 import de.intevation.gnv.utils.InputValidator;
 
 /**
@@ -519,21 +520,34 @@
         log.debug("StateBase.describe");
         Collection<Object> descibeData = this.getDescibeData(uuid);
         if (descibeData != null) {
-            ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities();
             Iterator<Object> it = descibeData.iterator();
-            Node staticNode = xmlutilities.createArtifactElement(document,
-                    "static");
-            Node dynamic = xmlutilities.createArtifactElement(document,
-                    "dynamic");
+
+            XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+                document,
+                ArtifactNamespaceContext.NAMESPACE_URI,
+                ArtifactNamespaceContext.NAMESPACE_PREFIX
+            );
+            Node staticNode  = creator.create("static");
+            Node dynamic     = creator.create("dynamic");
+
             rootNode.appendChild(staticNode);
             rootNode.appendChild(dynamic);
+
+            XMLUtils.ElementCreator xCreator = new XMLUtils.ElementCreator(
+                document,
+                XMLUtils.XFORM_URL,
+                XMLUtils.XFORM_PREFIX
+            );
+
             while (it.hasNext()) {
                 Object o = it.next();
                 if ((!it.hasNext() && dataName != null)) {
-                    appendToDynamicNode(document, dynamic, callMeta, o);
+                    appendToDynamicNode(
+                        xCreator, document, dynamic, callMeta, o);
                 }
                 else {
-                    appendToStaticNode(document, staticNode, callMeta, o);
+                    appendToStaticNode(
+                        xCreator, document, staticNode, callMeta, o);
                 }
             }
         }
@@ -541,10 +555,11 @@
 
 
     protected void appendToStaticNode(
-        Document document,
-        Node     staticNode,
-        CallMeta callMeta,
-        Object   o
+        XMLUtils.ElementCreator creator,
+        Document                document,
+        Node                    staticNode,
+        CallMeta                callMeta,
+        Object                  o
     ) {
         if (o instanceof Collection<?>) {
             String name = null;
@@ -558,17 +573,13 @@
                 name = names[names.length - 1].toString();
             }
 
-            log.debug("Name of attribute: " + name);
-            Element selectNode = ArtifactXMLUtilities.createXFormElement(
-                    document, multiselect ? "select" : "select1");
-            selectNode.setAttribute("ref", name);
+            Element selectNode = creator.create(multiselect?"select":"select1");
+            creator.addAttr(selectNode, "ref", name);
 
-            Element lableNode = ArtifactXMLUtilities.createXFormElement(
-                    document, "label");
+            Element lableNode = creator.create("label");
             lableNode.setTextContent(RessourceFactory.getInstance()
                     .getRessource(callMeta.getLanguages(), name, name));
-            Element choiceNode = ArtifactXMLUtilities.createXFormElement(
-                    document, "choices");
+            Element choiceNode = creator.create("choices");
 
             Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o;
             Iterator<KeyValueDescibeData> resultIt = values.iterator();
@@ -576,22 +587,17 @@
                 KeyValueDescibeData result = resultIt.next();
 
                 if (result.isSelected()) {
-                    Element itemNode = ArtifactXMLUtilities.createXFormElement(
-                            document, "item");
+                    Element itemNode = creator.create("item");
 
-                    itemNode.setAttribute("selected", "true");
+                    creator.addAttr(itemNode, "selected", "true");
 
-                    Element choiceLableNode =
-                        ArtifactXMLUtilities.createXFormElement(
-                            document, "label");
+                    Element choiceLableNode = creator.create("label");
                     choiceLableNode.setTextContent(result.getValue());
                     itemNode.appendChild(choiceLableNode);
 
-                    Element choicValueNode =
-                        ArtifactXMLUtilities.createXFormElement(
-                            document, "value");
-                    choicValueNode.setTextContent("" + result.getKey());
-                    itemNode.appendChild(choicValueNode);
+                    Element choiceValueNode = creator.create("value");
+                    choiceValueNode.setTextContent("" + result.getKey());
+                    itemNode.appendChild(choiceValueNode);
                     choiceNode.appendChild(itemNode);
                 }
             }
@@ -602,6 +608,7 @@
         }
         else if (o instanceof MinMaxDescribeData) {
             appendMinMaxDescribeData(
+                creator,
                 document,
                 staticNode,
                 callMeta,
@@ -609,6 +616,7 @@
         }
         else if (o instanceof SingleValueDescribeData) {
             appendSingleValueDescribeData(
+                creator,
                 document,
                 staticNode,
                 callMeta,
@@ -618,10 +626,11 @@
 
 
     protected void appendToDynamicNode(
-        Document document,
-        Node     dynamicNode,
-        CallMeta callMeta,
-        Object   o
+        XMLUtils.ElementCreator creator,
+        Document                document,
+        Node                    dynamicNode,
+        CallMeta                callMeta,
+        Object                  o
     ) {
         if (o instanceof Collection<?>) {
             String name = null;
@@ -633,37 +642,31 @@
             } else {
                 Object[] names = this.inputValueNames.toArray();
                 name = names[names.length - 1].toString();
-            }
+            } 
 
-            Element selectNode = ArtifactXMLUtilities.createXFormElement(
-                    document, multiselect ? "select" : "select1");
-            selectNode.setAttribute("ref", name);
+            Element selectNode = creator.create(multiselect?"select":"select1");
+            creator.addAttr(selectNode, "ref", name);
 
-            Element lableNode = ArtifactXMLUtilities.createXFormElement(
-                    document, "label");
+            Element lableNode = creator.create("label");
             lableNode.setTextContent(RessourceFactory.getInstance()
                     .getRessource(callMeta.getLanguages(), name, name));
-            Element choiceNode = ArtifactXMLUtilities.createXFormElement(
-                    document, "choices");
+            Element choiceNode = creator.create("choices");
 
             Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o;
             Iterator<KeyValueDescibeData> resultIt = values.iterator();
             while (resultIt.hasNext()) {
                 KeyValueDescibeData result = resultIt.next();
-                Element itemNode = ArtifactXMLUtilities.createXFormElement(
-                        document, "item");
+                Element itemNode = creator.create("item");
 
                 if (result.isSelected()) {
                     itemNode.setAttribute("selected", "true");
                 }
 
-                Element choiceLableNode =
-                    ArtifactXMLUtilities.createXFormElement(document, "label");
+                Element choiceLableNode = creator.create("label");
                 choiceLableNode.setTextContent(result.getValue());
                 itemNode.appendChild(choiceLableNode);
 
-                Element choicValueNode = ArtifactXMLUtilities.createXFormElement(
-                    document, "value");
+                Element choicValueNode = creator.create("value");
                 choicValueNode.setTextContent("" + result.getKey());
                 itemNode.appendChild(choicValueNode);
                 choiceNode.appendChild(itemNode);
@@ -675,6 +678,7 @@
         }
         else if (o instanceof MinMaxDescribeData) {
             appendMinMaxDescribeData(
+                creator,
                 document,
                 dynamicNode,
                 callMeta,
@@ -682,6 +686,7 @@
         }
         else if (o instanceof SingleValueDescribeData) {
             appendSingleValueDescribeData(
+                creator,
                 document,
                 dynamicNode,
                 callMeta,
@@ -691,10 +696,11 @@
 
 
     protected void appendMinMaxDescribeData(
-        Document document,
-        Node     node,
-        CallMeta callMeta,
-        Object   o
+        XMLUtils.ElementCreator creator,
+        Document                document,
+        Node                    node,
+        CallMeta                callMeta,
+        Object                  o
     ) {
         MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o;
         Object min = minMaxDescibeData.getMinValue();
@@ -709,11 +715,9 @@
             max = DateUtils.getPatternedDateAmer(d);
         }
 
-        Element groupNode = ArtifactXMLUtilities.createXFormElement(
-                document, "group");
-        groupNode.setAttribute("ref", minMaxDescibeData.getName());
-        Element groupNodeLableNode =
-            ArtifactXMLUtilities.createXFormElement(document, "label");
+        Element groupNode = creator.create("group");
+        creator.addAttr(groupNode, "ref", minMaxDescibeData.getName());
+        Element groupNodeLableNode = creator.create("label");
         groupNodeLableNode.setTextContent(RessourceFactory
                 .getInstance().getRessource(
                         callMeta.getLanguages(),
@@ -721,35 +725,29 @@
                         minMaxDescibeData.getName()));
         groupNode.appendChild(groupNodeLableNode);
 
-        Element inputMinNode = ArtifactXMLUtilities.createXFormElement(
-                document, "input");
-        inputMinNode.setAttribute("ref", MINVALUEFIELDNAME);
-        Element inputMinLableNode = ArtifactXMLUtilities
-                .createXFormElement(document, "label");
+        Element inputMinNode = creator.create("input");
+        creator.addAttr(inputMinNode, "ref", MINVALUEFIELDNAME);
+        Element inputMinLableNode = creator.create("label");
         inputMinLableNode.setTextContent(RessourceFactory
                 .getInstance().getRessource(
                         callMeta.getLanguages(), MINVALUEFIELDNAME,
                         MINVALUEFIELDNAME));
         inputMinNode.appendChild(inputMinLableNode);
 
-        Element inputMinValueNode = ArtifactXMLUtilities.createXFormElement(
-            document, "value");
+        Element inputMinValueNode = creator.create("value");
         inputMinValueNode.setTextContent(min.toString());
         inputMinNode.appendChild(inputMinValueNode);
 
-        Element inputMaxNode = ArtifactXMLUtilities.createXFormElement(
-                document, "input");
-        inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME);
-        Element inputMaxLableNode = ArtifactXMLUtilities.createXFormElement(
-            document, "label");
+        Element inputMaxNode = creator.create("input");
+        creator.addAttr(inputMaxNode, "ref", MAXVALUEFIELDNAME);
+        Element inputMaxLableNode = creator.create("label");
         inputMaxLableNode.setTextContent(RessourceFactory
                 .getInstance().getRessource(
                         callMeta.getLanguages(), MAXVALUEFIELDNAME,
                         MAXVALUEFIELDNAME));
         inputMaxNode.appendChild(inputMaxLableNode);
 
-        Element inputMaxValueNode = ArtifactXMLUtilities.createXFormElement(
-            document, "value");
+        Element inputMaxValueNode = creator.create("value");
         inputMaxValueNode.setTextContent(max.toString());
         inputMaxNode.appendChild(inputMaxValueNode);
 
@@ -762,18 +760,18 @@
 
 
     protected void appendSingleValueDescribeData(
-        Document document,
-        Node     node,
-        CallMeta callMeta,
-        Object   o
+        XMLUtils.ElementCreator creator,
+        Document                document,
+        Node                    node,
+        CallMeta                callMeta,
+        Object                  o
     ) {
         SingleValueDescribeData svdb = (SingleValueDescribeData) o;
 
-        Element groupNode = ArtifactXMLUtilities.createXFormElement(
-                document, "group");
-        groupNode.setAttribute("ref",  svdb.getName());
-        Element groupNodeLableNode = ArtifactXMLUtilities.createXFormElement(
-            document, "label");
+        Element groupNode = creator.create("group");
+        creator.addAttr(groupNode, "ref",  svdb.getName());
+
+        Element groupNodeLableNode = creator.create("label");
         groupNodeLableNode.setTextContent(RessourceFactory
                 .getInstance().getRessource(
                         callMeta.getLanguages(),
@@ -781,17 +779,14 @@
                         svdb.getName()));
         groupNode.appendChild(groupNodeLableNode);
 
-        Element inputNode = ArtifactXMLUtilities.createXFormElement(
-                document, "input");
-        inputNode.setAttribute("ref", svdb.getName());
+        Element inputNode = creator.create("input");
+        creator.addAttr(inputNode, "ref", svdb.getName());
 
-        Element inputLableNode = ArtifactXMLUtilities.createXFormElement(
-                document, "label");
+        Element inputLableNode = creator.create("label");
         inputLableNode.setTextContent("");
         inputNode.appendChild(inputLableNode);
 
-        Element inputValueNode = ArtifactXMLUtilities.createXFormElement(
-                document, "value");
+        Element inputValueNode = creator.create("value");
         inputValueNode.setTextContent(svdb.getValue());
         inputNode.appendChild(inputValueNode);
 
@@ -834,3 +829,4 @@
         return this.inputData != null ? this.inputData.values() : null;
     }
 }
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org