changeset 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 c42a07be9aee
children 4edaf3073109
files ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java
diffstat 2 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon May 23 10:04:31 2011 +0000
+++ b/ChangeLog	Fri May 27 08:11:34 2011 +0000
@@ -1,3 +1,9 @@
+2011-05-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java:
+	  New method that creates the document that is used to set an attribute of
+	  a collection.
+
 2011-04-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/rest/JettyServer.java:
--- 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