# HG changeset patch # User Ingo Weinzierl # Date 1300897432 0 # Node ID fc435da7f4717843f773299887d13c55b77a4e54 # Parent 199f0e553e3a822787a7c42d9d35c8093af74f74 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 diff -r 199f0e553e3a -r fc435da7f471 ChangeLog --- a/ChangeLog Wed Mar 23 16:20:11 2011 +0000 +++ b/ChangeLog Wed Mar 23 16:23:52 2011 +0000 @@ -1,3 +1,9 @@ +2011-03-23 Ingo Weinzierl + + * artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java: + Added a method that creates a document that is used to add an artifact + to a collection. + 2011-03-23 Ingo Weinzierl * artifact-database/src/main/resources/sql/org-h2-driver.properties, diff -r 199f0e553e3a -r fc435da7f471 artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java --- 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 * node. *