diff artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java @ 267:72de5c373c9b

Enhanced the ClientProtocolUtils with a method to create a document that sets the attribute of a collection. artifacts/trunk@2014 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 27 May 2011 08:11:34 +0000
parents f3d970a832ff
children 89f6de49803d
line wrap: on
line diff
--- a/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Mon May 23 10:04:31 2011 +0000
+++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Fri May 27 08:11:34 2011 +0000
@@ -407,6 +407,48 @@
 
     /**
      * This function creates a document that is used to set the attribute of a
+     * Collection.
+     *
+     * @param uuid The identifier of the Collection.
+     * @param attr The new attribute value for the Collection.
+     *
+     * @return the document that is used to set the attribute.
+     */
+    public static Document newSetAttributeDocument(
+        String uuid,
+        Document attr)
+    {
+        Node root = attr != null ? attr.getFirstChild() : null;
+
+        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 collection = ec.create("collection");
+
+        ec.addAttr(type, "name", "setattribute", false);
+        ec.addAttr(collection, "uuid", uuid, false);
+
+        doc.appendChild(action);
+        action.appendChild(type);
+        type.appendChild(collection);
+
+        collection.appendChild(doc.importNode(root, true));
+
+        return doc;
+    }
+
+    /**
+     * This function creates a document that is used to set the attribute of a
      * CollectionItem.
      *
      * @param uuid The identifier of the CollectionItem.

http://dive4elements.wald.intevation.org