# HG changeset patch # User Ingo Weinzierl # Date 1296838359 0 # Node ID 39d9391059bd04b122f6a85d836c6addd0f091be # Parent ece0fdb07975de96881171ce5447e0dbad24bca4 Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents. artifacts/trunk@1295 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ece0fdb07975 -r 39d9391059bd ChangeLog --- a/ChangeLog Fri Feb 04 10:50:53 2011 +0000 +++ b/ChangeLog Fri Feb 04 16:52:39 2011 +0000 @@ -1,3 +1,9 @@ +2011-02-04 Ingo Weinzierl + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java: + New. This class provides functions that should help creating the artifact + protocol documents of the services describe, feed, advance and out. + 2011-02-04 Ingo Weinzierl * artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java: diff -r ece0fdb07975 -r 39d9391059bd artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java Fri Feb 04 16:52:39 2011 +0000 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.artifactdatabase; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import de.intevation.artifacts.common.utils.XMLUtils; + + +/** + * This class provides methods that help creating the artifact protocol + * documents describe, feed, advance and out. + * + * @author Ingo Weinzierl + */ +public class ProtocolUtils { + + /** + * It should not be necessary to create instances of this class. + */ + private ProtocolUtils() {} + + + /** + * This method creates a node that might be used for the artifact protocol. + * + * @param creator The ElementCreator that is used to create the node. + * @param nodeName The node name. + * @param attrName The names of optional attributes. + * @param value The values for the optional attributes. + * + * @return the created node. + */ + public static Element createArtNode( + XMLUtils.ElementCreator creator, + String nodeName, String[] attrName, String[] value) + { + Element typeNode = creator.create(nodeName); + + if (attrName != null && value != null) { + for (int i = 0; i < attrName.length; i++) { + if (i < value.length) { + creator.addAttr(typeNode, attrName[i], value[i], true); + } + else { + break; + } + } + } + + return typeNode; + } + + + /** + * This method creates the root node for all artifact protocol documents. + * + * @param creator The ElementCreator used to create new elements. + * + * @return the root node for the artifact protocol document. + */ + public static Element createRootNode(XMLUtils.ElementCreator creator) { + return createArtNode(creator, "result", null, null); + } + + + /** + * This method appends the three necessary nodes type, uuid + * and hash of the describe document to root node. + * + * @param creator The ElementCreator that is used to create new nodes. + * @param root The root node of the describe document. + * @param uuid The UUID of the artifact. + * @param hash The hash if the artifact. + */ + public static void appendDescribeHeader( + XMLUtils.ElementCreator creator, Element root, String uuid, String hash) + { + root.appendChild(createArtNode( + creator, + "type", + new String[] {"name"}, + new String[] {"describe"})); + + root.appendChild(createArtNode( + creator, + "uuid", + new String[] {"value"}, + new String[] {uuid})); + + root.appendChild(createArtNode( + creator, + "hash", + new String[] {"value"}, + new String[] {hash})); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: