diff artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java @ 214:fc435da7f471

Enhanced the ClientProtocolUtils with a method that creates a document that is used to add an artifact to a collection. artifacts/trunk@1551 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 23 Mar 2011 16:23:52 +0000
parents d7042094f7b7
children ecfc33a4ba3d
line wrap: on
line diff
--- a/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Wed Mar 23 16:20:11 2011 +0000
+++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Wed Mar 23 16:23:52 2011 +0000
@@ -225,6 +225,46 @@
 
 
     /**
+     * This method creates a new Document that is used to add an artifact to a
+     * collection in the artifact server.
+     *
+     * @param artId The identifier of the artifact that should be added.
+     * @param attr A document that contains attributes for the attribute's
+     * life in the collection.
+     *
+     * @return the document to add an artifact into a collection.
+     */
+    public static Document newAddArtifactDocument(String artId, Document attr) {
+        Document doc = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
+            doc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element action    = cr.create("action");
+        Element type      = cr.create("type");
+        Element artifact  = cr.create("artifact");
+        Element attribute = cr.create("attribute");
+
+        cr.addAttr(artifact, "uuid", artId);
+        cr.addAttr(type, "name", "addartifact");
+
+        if (attr != null) {
+            attr.appendChild(attr);
+        }
+
+        action.appendChild(type);
+        type.appendChild(artifact);
+        artifact.appendChild(attribute);
+
+        doc.appendChild(action);
+
+        return doc;
+    }
+
+
+    /**
      * Returns string value found by {@link XPATH_LABEL} relative to
      * <i>node</i>.
      *

http://dive4elements.wald.intevation.org