diff artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java @ 255:efbad8c5c0e5

Improved the ClientProtocolUtils - new function to create a document that is used to set the attribute of a CollectionItem. artifacts/trunk@1753 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 28 Apr 2011 08:10:03 +0000
parents c0bc172ec7b2
children c41b300b02c3
line wrap: on
line diff
--- a/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Wed Apr 27 16:57:20 2011 +0000
+++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Thu Apr 28 08:10:03 2011 +0000
@@ -370,6 +370,49 @@
 
 
     /**
+     * This function creates a document that is used to set the attribute of a
+     * CollectionItem.
+     *
+     * @param uuid The identifier of the CollectionItem.
+     * @param attr The new attribute value for the CollectionItem.
+     *
+     * @return the document that is used to set the attribute.
+     */
+    public static Document newSetItemAttributeDocument(
+        String uuid,
+        Document attr)
+    {
+        Node root = attr.getFirstChild();
+
+        if (root == null) {
+            return null;
+        }
+
+        Document doc = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            doc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element action   = ec.create("action");
+        Element type     = ec.create("type");
+        Element artifact = ec.create("artifact");
+
+        ec.addAttr(type, "name", "setitemattribute");
+        ec.addAttr(artifact, "uuid", uuid);
+
+        doc.appendChild(action);
+        action.appendChild(type);
+        type.appendChild(artifact);
+
+        artifact.appendChild(doc.importNode(root, true));
+
+        return doc;
+    }
+
+
+    /**
      * Returns string value found by {@link XPATH_LABEL} relative to
      * <i>node</i>.
      *

http://dive4elements.wald.intevation.org