changeset 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 6cf9560bd249
children 55d08706ccf2
files ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java
diffstat 2 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Apr 27 16:57:20 2011 +0000
+++ b/ChangeLog	Thu Apr 28 08:10:03 2011 +0000
@@ -1,3 +1,9 @@
+2011-04-28  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java:
+	  Added a function that creates the document that is used to set the
+	  attribute of a CollectionItem (setCollectionItemAttribute() operation).
+
 2011-04-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
--- 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