ingo@113: /*
ingo@113: * Copyright (c) 2011 by Intevation GmbH
ingo@113: *
ingo@113: * This program is free software under the LGPL (>=v2.1)
ingo@113: * Read the file LGPL.txt coming with the software for details
ingo@113: * or visit http://www.gnu.org/licenses/ if it does not exist.
ingo@113: */
ingo@113: package de.intevation.artifacts.common.utils;
ingo@113:
ingo@114: import javax.xml.xpath.XPathConstants;
ingo@114:
ingo@113: import org.w3c.dom.Document;
ingo@113: import org.w3c.dom.Element;
ingo@114: import org.w3c.dom.Node;
ingo@114: import org.w3c.dom.NodeList;
ingo@113:
ingo@113: import de.intevation.artifacts.common.ArtifactNamespaceContext;
ingo@113:
ingo@113:
ingo@113: /**
ingo@113: * This class provides methods that help creating the artifact protocol
ingo@113: * documents DESCRIBE, FEED, ADVANCE and OUT.
ingo@113: *
ingo@113: * @author Ingo Weinzierl
ingo@113: */
ingo@113: public class ClientProtocolUtils {
ingo@113:
felix@341: /** The XPath to the current state in the DESCRIBE document. */
ingo@114: public static final String XPATH_CURRENT_STATE = "/art:result/art:state";
ingo@114:
felix@341: /** The XPath to the static UI part in the DESCRIBE document. */
ingo@114: public static final String XPATH_STATIC = "/art:result/art:ui/art:static";
ingo@114:
felix@341: /** The XPath to the dynamic UI part in the DESCRIBE document. */
ingo@114: public static final String XPATH_DYNAMIC = "/art:result/art:ui/art:dynamic";
ingo@114:
felix@341: /** The XPath to the reachable states part in the DESCRIBE document. */
ingo@114: public static final String XPATH_STATES =
ingo@114: "/art:result/art:reachable-states";
ingo@114:
felix@341: /** The XPath to the output modes in the DESCRIBE document. */
ingo@211: public static final String XPATH_OUTPUT_MODES =
ingo@211: "/art:result/art:outputmodes/art:output";
ingo@211:
ingo@114: /** The XPath to the select node relative to the dynamic UI node in the
felix@341: * DESCRIBE document. */
ingo@114: public static final String XPATH_DATA_SELECT = "art:select";
ingo@114:
ingo@114: /** The XPath to the choices nodes relative to the select node in the
felix@341: * DESCRIBE document. */
ingo@114: public static final String XPATH_DATA_ITEMS = "art:choices/art:item";
ingo@114:
ingo@370: /** The XPath that points to the min value of a range.*/
ingo@370: public static final String XPATH_MIN_NODE = "art:min/@art:value";
ingo@370:
ingo@370: /** The XPath that points to the max value of a range.*/
ingo@370: public static final String XPATH_MAX_NODE = "art:max/@art:value";
ingo@370:
ingo@371: /** The XPath that points to the default min value of a range.*/
ingo@371: public static final String XPATH_DEF_MIN = "art:min/@art:default";
ingo@371:
ingo@371: /** The XPath that points to the default max value of a range.*/
ingo@371: public static final String XPATH_DEF_MAX = "art:max/@art:default";
ingo@371:
felix@341: /** The XPath to a label in the artifact's DESCRIBE document. */
ingo@114: public static final String XPATH_LABEL = "art:label/text()";
ingo@114:
felix@341: /** The XPath to a value in the artifact's DESCRIBE document. */
ingo@114: public static final String XPATH_VALUE = "art:value/text()";
ingo@114:
ingo@114:
ingo@113: /**
ingo@113: * It should not be necessary to create instances of this class.
ingo@113: */
ingo@113: private ClientProtocolUtils() {
ingo@113: }
ingo@113:
ingo@113:
ingo@113: /**
ingo@113: * This method creates a new CREATE document.
ingo@113: *
ingo@113: * @return the CREATE document.
ingo@113: */
ingo@113: public static Document newCreateDocument(String factory) {
ingo@293: return newCreateDocument(factory, null);
ingo@293: }
ingo@293:
ingo@293:
ingo@293: /**
ingo@293: * This method creates a new CREATE document.
ingo@293: *
ingo@293: * @return the CREATE document.
ingo@293: */
ingo@293: public static Document newCreateDocument(String factory, String uuid) {
ingo@300: return newCreateDocument(factory, uuid, null);
ingo@300: }
ingo@300:
sascha@325: public static Document newCreateDocument(
sascha@325: String factory,
sascha@325: String uuid,
sascha@325: String ids
sascha@325: ) {
sascha@325: return newCreateDocument(factory, uuid, ids, null);
sascha@325: }
ingo@300:
ingo@300: /**
ingo@300: * This method creates a new CREATE document.
ingo@300: *
ingo@300: * @return the CREATE document.
ingo@300: */
ingo@300: public static Document newCreateDocument(
sascha@325: String factory,
sascha@325: String uuid,
sascha@325: String ids,
sascha@325: CreationFilter filter
sascha@325: ) {
ingo@113: Document doc = XMLUtils.newDocument();
ingo@113:
ingo@113: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
ingo@113: doc,
ingo@113: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@113: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@113:
ingo@113: Element action = cr.create("action");
ingo@113: Element type = cr.create("type");
ingo@113: Element fac = cr.create("factory");
ingo@113:
ingo@113: type.setAttribute("name", "create");
ingo@113: fac.setAttribute("name", factory);
ingo@113:
ingo@113: action.appendChild(type);
ingo@113: action.appendChild(fac);
ingo@113:
ingo@293: if (uuid != null) {
ingo@293: Element templ = cr.create("template");
ingo@293: templ.setAttribute("uuid", uuid);
ingo@293: action.appendChild(templ);
ingo@293: }
ingo@293:
ingo@300: if (ids != null) {
ingo@324: Element id = cr.create("ids");
ingo@300: id.setAttribute("value", ids);
ingo@300: action.appendChild(id);
ingo@300: }
ingo@293:
sascha@325: if (filter != null) {
sascha@325: action.appendChild(filter.toXML(cr));
sascha@325: }
sascha@325:
ingo@113: doc.appendChild(action);
ingo@113:
ingo@113: return doc;
ingo@113: }
ingo@114:
ingo@114:
ingo@114: /**
ingo@203: * This method creates a new FEED document.
ingo@203: *
ingo@203: * @param theUuid The identifier of the artifact.
ingo@203: * @param theHash The hash of the artifact.
ingo@203: * @param theData An array that contains key/value pairs that represent the
ingo@203: * data that should be included in the FEED document.
ingo@203: *
ingo@203: * @return the FEED document.
ingo@203: */
ingo@203: public static Document newFeedDocument(
ingo@203: String theUuid,
ingo@203: String theHash,
ingo@203: String[][] theData)
ingo@203: {
ingo@203: Document doc = XMLUtils.newDocument();
ingo@203:
ingo@203: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
ingo@203: doc,
ingo@203: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@203: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@203:
ingo@203: Element action = cr.create("action");
ingo@203: Element type = cr.create("type");
ingo@203: Element uuid = cr.create("uuid");
ingo@203: Element hash = cr.create("hash");
ingo@203: Element data = cr.create("data");
ingo@203:
ingo@203: // XXX It is not nice that the type has no attribute namespace, but to
ingo@203: // be backward compatible, we don't change this now.
ingo@203: cr.addAttr(type, "name", "feed", false);
ingo@203: cr.addAttr(uuid, "value", theUuid, true);
ingo@203: cr.addAttr(hash, "value", theHash, true);
ingo@203:
ingo@203: for (String[] kvp: theData) {
ingo@203: Element input = cr.create("input");
ingo@203: cr.addAttr(input, "name", kvp[0], true);
ingo@203: cr.addAttr(input, "value", kvp[1], true);
ingo@203:
ingo@203: data.appendChild(input);
ingo@203: }
ingo@203:
ingo@203: action.appendChild(type);
ingo@203: action.appendChild(uuid);
ingo@203: action.appendChild(hash);
ingo@203: action.appendChild(data);
ingo@203:
ingo@203: doc.appendChild(action);
ingo@203:
ingo@203: return doc;
ingo@203: }
ingo@203:
ingo@203:
ingo@203: /**
ingo@240: * This method creates a new DESCRIBE document.
ingo@240: *
ingo@240: * @param theUuid The identifier of the artifact.
ingo@240: * @param theHash The hash of the artifact.
ingo@240: * @param ui If true, the UI part is included.
ingo@240: *
ingo@240: * @return the DESCRIBE document.
ingo@240: */
ingo@240: public static Document newDescribeDocument(
ingo@240: String theUuid,
ingo@240: String theHash,
ingo@240: boolean incUI)
ingo@240: {
ingo@240: Document doc = XMLUtils.newDocument();
ingo@240:
ingo@240: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
ingo@240: doc,
ingo@240: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@240: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@240:
ingo@240: Element action = cr.create("action");
ingo@240: Element type = cr.create("type");
ingo@240: Element uuid = cr.create("uuid");
ingo@240: Element hash = cr.create("hash");
ingo@240: Element ui = cr.create("include-ui");
ingo@240:
ingo@240: // XXX It is not nice that the type has no attribute namespace, but to
ingo@240: // be backward compatible, we don't change this now.
ingo@240: cr.addAttr(type, "name", "describe", false);
ingo@240: cr.addAttr(uuid, "value", theUuid, true);
ingo@240: cr.addAttr(hash, "value", theHash, true);
ingo@240:
ingo@240: ui.setTextContent(incUI ? "true" : "false");
ingo@240:
ingo@240: action.appendChild(type);
ingo@240: action.appendChild(uuid);
ingo@240: action.appendChild(hash);
ingo@240: action.appendChild(ui);
ingo@240:
ingo@240: doc.appendChild(action);
ingo@240:
ingo@240: return doc;
ingo@240: }
ingo@240:
ingo@240:
ingo@240: /**
ingo@204: * This method creates a new ADVANCE document.
ingo@204: *
ingo@204: * @param theUuid The identifier of the artifact.
ingo@204: * @param theHash The hash of the artifact.
ingo@204: * @param theTarget The target state identifier.
ingo@204: *
ingo@204: * @return the ADVANCE document.
ingo@204: */
ingo@204: public static Document newAdvanceDocument(
ingo@204: String theUuid,
ingo@204: String theHash,
ingo@204: String theTarget)
ingo@204: {
ingo@204: Document doc = XMLUtils.newDocument();
ingo@204:
ingo@204: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
ingo@204: doc,
ingo@204: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@204: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@204:
ingo@204: Element action = cr.create("action");
ingo@204: Element type = cr.create("type");
ingo@204: Element uuid = cr.create("uuid");
ingo@204: Element hash = cr.create("hash");
ingo@204: Element target = cr.create("target");
ingo@204:
ingo@204: // XXX It is not nice that the type has no attribute namespace, but to
ingo@204: // be backward compatible, we don't change this now.
ingo@204: cr.addAttr(type, "name", "advance", false);
ingo@204: cr.addAttr(uuid, "value", theUuid, true);
ingo@204: cr.addAttr(hash, "value", theHash, true);
ingo@204: cr.addAttr(target, "name", theTarget, true);
ingo@204:
ingo@204: action.appendChild(type);
ingo@204: action.appendChild(uuid);
ingo@204: action.appendChild(hash);
ingo@204: action.appendChild(target);
ingo@204:
ingo@204: doc.appendChild(action);
ingo@204:
ingo@204: return doc;
ingo@204: }
ingo@204:
ingo@204:
ingo@204: /**
ingo@172: * This method creates a new document that is used to create new artifact
ingo@172: * collections in the artifact server.
ingo@172: *
ingo@172: * @param name Optional name of the collection.
ingo@172: *
ingo@172: * @return the document to create new collections.
ingo@172: */
ingo@172: public static Document newCreateCollectionDocument(String name) {
ingo@172: Document doc = XMLUtils.newDocument();
ingo@172:
ingo@172: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
ingo@172: doc,
ingo@172: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@172: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@172:
ingo@172: Element action = cr.create("action");
ingo@172: Element type = cr.create("type");
ingo@212: Element collection = cr.create("collection");
ingo@220: Element attribute = cr.create("attribute");
ingo@172:
ingo@172: cr.addAttr(type, "name", "create");
ingo@172: cr.addAttr(collection, "name", name != null ? name : "");
ingo@172:
ingo@172: action.appendChild(type);
ingo@212: type.appendChild(collection);
ingo@220: collection.appendChild(attribute);
ingo@172:
ingo@172: doc.appendChild(action);
ingo@172:
ingo@172: return doc;
ingo@172: }
ingo@172:
ingo@172:
ingo@172: /**
ingo@214: * This method creates a new Document that is used to add an artifact to a
ingo@214: * collection in the artifact server.
ingo@214: *
ingo@214: * @param artId The identifier of the artifact that should be added.
felix@341: * @param attr A document that contains attributes for the artifact's
ingo@214: * life in the collection.
ingo@214: *
ingo@214: * @return the document to add an artifact into a collection.
ingo@214: */
ingo@214: public static Document newAddArtifactDocument(String artId, Document attr) {
ingo@214: Document doc = XMLUtils.newDocument();
ingo@214:
ingo@214: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
ingo@214: doc,
ingo@214: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@214: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@214:
ingo@214: Element action = cr.create("action");
ingo@214: Element type = cr.create("type");
ingo@214: Element artifact = cr.create("artifact");
ingo@214: Element attribute = cr.create("attribute");
ingo@214:
ingo@214: cr.addAttr(artifact, "uuid", artId);
ingo@214: cr.addAttr(type, "name", "addartifact");
ingo@214:
ingo@214: if (attr != null) {
ingo@214: attr.appendChild(attr);
ingo@214: }
ingo@214:
ingo@214: action.appendChild(type);
ingo@214: type.appendChild(artifact);
ingo@214: artifact.appendChild(attribute);
ingo@214:
ingo@214: doc.appendChild(action);
ingo@214:
ingo@214: return doc;
ingo@214: }
ingo@214:
ingo@214:
ingo@214: /**
felix@341: * Create a new Document that is used to remove an artifact from a
felix@341: * collection in the artifact server.
felix@341: *
felix@341: * @param artId The identifier of the artifact that should be added.
felix@341: *
felix@341: * @return the document to add an artifact into a collection.
felix@341: */
felix@341: public static Document newRemoveArtifactDocument(String artId) {
felix@341: Document doc = XMLUtils.newDocument();
felix@341:
felix@341: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
felix@341: doc,
felix@341: ArtifactNamespaceContext.NAMESPACE_URI,
felix@341: ArtifactNamespaceContext.NAMESPACE_PREFIX);
felix@341:
felix@341: Element action = cr.create("action");
felix@341: Element type = cr.create("type");
felix@341: Element artifact = cr.create("artifact");
felix@341:
felix@341: cr.addAttr(artifact, "uuid", artId);
felix@341: cr.addAttr(type, "name", "removeartifact");
felix@341:
felix@341: action.appendChild(type);
felix@341: type.appendChild(artifact);
felix@341:
felix@341: doc.appendChild(action);
felix@341:
felix@341: return doc;
felix@341: }
felix@341:
felix@341:
felix@341: /**
ingo@223: * This method creates a new Document that is used to trigger the DESCRIBE
ingo@223: * operation of a collection in the artifact server.
ingo@223: *
ingo@223: * @param uuid The identifier of the collection that should be described.
ingo@223: *
ingo@223: * @return the document to describe a collection.
ingo@223: */
ingo@223: public static Document newDescribeCollectionDocument(String uuid) {
ingo@223: Document doc = XMLUtils.newDocument();
ingo@223:
ingo@223: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
ingo@223: doc,
ingo@223: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@223: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@223:
ingo@223: Element action = cr.create("action");
ingo@223: Element type = cr.create("type");
ingo@223: cr.addAttr(type, "name", "describe");
ingo@223:
ingo@223: action.appendChild(type);
ingo@223:
ingo@223: doc.appendChild(action);
ingo@223:
ingo@223: return doc;
ingo@223: }
ingo@223:
ingo@223:
ingo@239:
ingo@239: /**
ingo@239: * This function builds a document that is used as request document of the
ingo@239: * out() operation of Collections.
ingo@239: *
ingo@239: * @param uuid The identifier of the collection.
ingo@261: * @param mode The name of the desired output mode.
ingo@239: * @param type The name of the desired output type.
ingo@239: *
ingo@239: * @return the request document.
ingo@239: */
ingo@261: public static Document newOutCollectionDocument(
ingo@261: String uuid,
ingo@261: String mode,
ingo@261: String type) {
ingo@261: return newOutCollectionDocument(uuid, mode, type, null);
ingo@258: }
ingo@258:
ingo@258:
ingo@258: /**
ingo@258: * This function builds a document that is used as request document of the
ingo@258: * out() operation of Collections. The document attr might be used to
ingo@258: * adjust some settings specific to the output.
ingo@258: *
ingo@258: * @param uuid The identifier of the collection.
ingo@261: * @param mode The name of the desired output mode.
ingo@258: * @param type The name of the desired output type.
ingo@258: * @param attr A document that contains settings specific to the output.
ingo@258: *
ingo@258: * @return the request document.
ingo@258: */
ingo@258: public static Document newOutCollectionDocument(
ingo@258: String uuid,
ingo@261: String mode,
ingo@258: String type,
ingo@258: Document attr)
ingo@258: {
ingo@239: Document doc = XMLUtils.newDocument();
ingo@239:
ingo@239: XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
ingo@239: doc,
ingo@239: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@239: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@239:
ingo@270: Element action = cr.create("action");
ingo@239:
ingo@261: cr.addAttr(action, "name", mode, true);
ingo@239: cr.addAttr(action, "type", type, true);
ingo@239:
ingo@239: doc.appendChild(action);
ingo@239:
ingo@258: if (attr != null) {
ingo@258: Node root = attr.getFirstChild();
ingo@258:
ingo@258: if (root != null) {
ingo@270: action.appendChild(doc.importNode(root, true));
ingo@258: }
ingo@258: }
ingo@258:
ingo@239: return doc;
ingo@239: }
ingo@239:
ingo@239:
ingo@223: /**
ingo@255: * This function creates a document that is used to set the attribute of a
ingo@267: * Collection.
ingo@267: *
ingo@267: * @param uuid The identifier of the Collection.
ingo@267: * @param attr The new attribute value for the Collection.
ingo@267: *
ingo@267: * @return the document that is used to set the attribute.
ingo@267: */
ingo@267: public static Document newSetAttributeDocument(
ingo@267: String uuid,
ingo@267: Document attr)
ingo@267: {
ingo@267: Node root = attr != null ? attr.getFirstChild() : null;
ingo@267:
ingo@267: if (root == null) {
ingo@267: return null;
ingo@267: }
ingo@267:
ingo@267: Document doc = XMLUtils.newDocument();
ingo@267:
ingo@267: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
ingo@267: doc,
ingo@267: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@267: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@267:
ingo@267: Element action = ec.create("action");
ingo@267: Element type = ec.create("type");
ingo@267: Element collection = ec.create("collection");
ingo@267:
ingo@267: ec.addAttr(type, "name", "setattribute", false);
ingo@267: ec.addAttr(collection, "uuid", uuid, false);
ingo@267:
ingo@267: doc.appendChild(action);
ingo@267: action.appendChild(type);
ingo@267: type.appendChild(collection);
ingo@267:
ingo@267: collection.appendChild(doc.importNode(root, true));
ingo@267:
ingo@267: return doc;
ingo@267: }
ingo@267:
ingo@267: /**
ingo@267: * This function creates a document that is used to set the attribute of a
ingo@255: * CollectionItem.
ingo@255: *
ingo@255: * @param uuid The identifier of the CollectionItem.
ingo@255: * @param attr The new attribute value for the CollectionItem.
ingo@255: *
ingo@255: * @return the document that is used to set the attribute.
ingo@255: */
ingo@255: public static Document newSetItemAttributeDocument(
ingo@255: String uuid,
ingo@255: Document attr)
ingo@255: {
ingo@255: Node root = attr.getFirstChild();
ingo@255:
ingo@255: if (root == null) {
ingo@255: return null;
ingo@255: }
ingo@255:
ingo@255: Document doc = XMLUtils.newDocument();
ingo@255:
ingo@255: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
ingo@255: doc,
ingo@255: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@255: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@255:
ingo@255: Element action = ec.create("action");
ingo@255: Element type = ec.create("type");
ingo@255: Element artifact = ec.create("artifact");
ingo@255:
ingo@255: ec.addAttr(type, "name", "setitemattribute");
ingo@255: ec.addAttr(artifact, "uuid", uuid);
ingo@255:
ingo@255: doc.appendChild(action);
ingo@255: action.appendChild(type);
ingo@255: type.appendChild(artifact);
ingo@255:
ingo@255: artifact.appendChild(doc.importNode(root, true));
ingo@255:
ingo@255: return doc;
ingo@255: }
ingo@255:
ingo@255:
ingo@255: /**
ingo@285: * This function creates a document that is used to set the time-to-live
ingo@285: * of a collection.
ingo@285: *
ingo@285: * @param ttl The ttl for the Collection.
ingo@285: *
ingo@285: * @return the document that is used to set the time-to-live.
ingo@285: */
ingo@285: public static Document newSetCollectionTTLDocument(String ttl) {
ingo@285: Document doc = XMLUtils.newDocument();
ingo@285:
ingo@285: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
ingo@285: doc,
ingo@285: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@285: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@285:
ingo@285: Element action = ec.create("action");
ingo@285: Element type = ec.create("type");
ingo@285: Element ttlEl = ec.create("ttl");
ingo@285:
ingo@285: ec.addAttr(type, "name", "settimetolive");
ingo@285: ec.addAttr(ttlEl, "value", ttl);
ingo@285:
ingo@285: doc.appendChild(action);
ingo@285: action.appendChild(type);
ingo@285: type.appendChild(ttlEl);
ingo@285:
ingo@285: return doc;
ingo@285: }
ingo@285:
ingo@285:
ingo@285: /**
ingo@285: * This function creates a document that is used to set the name of a
ingo@285: * collection.
ingo@285: *
ingo@285: * @param name The name for the Collection.
ingo@285: *
ingo@285: * @return the document that is used to set the name of a collection.
ingo@285: */
ingo@285: public static Document newSetCollectionNameDocument(String name) {
ingo@285: Document doc = XMLUtils.newDocument();
ingo@285:
ingo@285: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
ingo@285: doc,
ingo@285: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@285: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@285:
ingo@285: Element action = ec.create("action");
ingo@285: Element type = ec.create("type");
ingo@285: Element coll = ec.create("collection");
ingo@285:
ingo@285: ec.addAttr(type, "name", "setname");
ingo@285: ec.addAttr(coll, "name", name);
ingo@285:
ingo@285: doc.appendChild(action);
ingo@285: action.appendChild(type);
ingo@285: type.appendChild(coll);
ingo@285:
ingo@285: return doc;
ingo@285: }
ingo@285:
ingo@285:
ingo@285: /**
ingo@285: * This function creates a document that is used to delete an existing
ingo@285: * collection.
ingo@285: *
ingo@285: * @return the document that is used to delete an existing collection.
ingo@285: */
ingo@285: public static Document newDeleteCollectionDocument() {
ingo@285: Document doc = XMLUtils.newDocument();
ingo@285:
ingo@285: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
ingo@285: doc,
ingo@285: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@285: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@285:
ingo@285: Element action = ec.create("action");
ingo@285: Element type = ec.create("type");
ingo@285:
ingo@285: ec.addAttr(type, "name", "delete");
ingo@285:
ingo@285: doc.appendChild(action);
ingo@285: action.appendChild(type);
ingo@285:
ingo@285: return doc;
ingo@285: }
ingo@285:
ingo@285:
ingo@285: /**
ingo@114: * Returns string value found by {@link XPATH_LABEL} relative to
ingo@114: * node.
ingo@114: *
ingo@114: * @param node A node.
ingo@114: *
ingo@114: * @return the string value found by {@link XPATH_LABEL}.
ingo@114: */
ingo@114: public static String getLabel(Node node) {
ingo@114: return (String) XMLUtils.xpath(
ingo@114: node,
ingo@114: XPATH_LABEL,
ingo@114: XPathConstants.STRING,
ingo@114: ArtifactNamespaceContext.INSTANCE);
ingo@114: }
ingo@114:
ingo@114:
ingo@114: /**
ingo@114: * Returns string value found by {@link XPATH_VALUE} relative to
ingo@114: * node.
ingo@114: *
ingo@114: * @param node A node.
ingo@114: *
ingo@114: * @return the string value found by {@link XPATH_VALUE}.
ingo@114: */
ingo@114: public static String getValue(Node node) {
ingo@114: return (String) XMLUtils.xpath(
ingo@114: node,
ingo@114: XPATH_VALUE,
ingo@114: XPathConstants.STRING,
ingo@114: ArtifactNamespaceContext.INSTANCE);
ingo@114: }
ingo@114:
ingo@114:
ingo@114: /**
ingo@114: * This method returns the static UI part of the artifact's DESCRIBE
ingo@114: * document.
ingo@114: *
ingo@114: * @param description The document returned by the artifact server's
ingo@114: * DESCRIBE operation.
ingo@114: *
ingo@114: * @return the static UI node.
ingo@114: */
ingo@114: public static Node getStaticUI(Document description) {
ingo@114: return (Node) XMLUtils.xpath(
ingo@114: description,
ingo@114: XPATH_STATIC,
ingo@114: XPathConstants.NODE,
ingo@114: ArtifactNamespaceContext.INSTANCE);
ingo@114: }
ingo@114:
ingo@114:
ingo@114: /**
ingo@114: * This method returns the dynamic UI part of the artifact's DESCRIBE
ingo@114: * document.
ingo@114: *
ingo@114: * @param description The document returned by the artifact server's
ingo@114: * DESCRIBE operation.
ingo@114: *
ingo@114: * @return the dynamic UI node.
ingo@114: */
ingo@114: public static Node getDynamicUI(Document description) {
ingo@114: return (Node) XMLUtils.xpath(
ingo@114: description,
ingo@114: XPATH_DYNAMIC,
ingo@114: XPathConstants.NODE,
ingo@114: ArtifactNamespaceContext.INSTANCE);
ingo@114: }
ingo@114:
ingo@114:
ingo@114: /**
ingo@114: * This method returns the current state node contained in the DESCRIBE
ingo@114: * document.
ingo@114: *
ingo@114: * @param description The document returned by the artifact server's
ingo@114: * DESCRIBE operation.
ingo@114: *
ingo@114: * @return the node containing information about the current state.
ingo@114: */
ingo@114: public static Node getCurrentState(Document description) {
ingo@114: return (Node) XMLUtils.xpath(
ingo@114: description,
ingo@114: XPATH_CURRENT_STATE,
ingo@114: XPathConstants.NODE,
ingo@114: ArtifactNamespaceContext.INSTANCE);
ingo@114: }
ingo@114:
ingo@114:
ingo@114: /**
ingo@114: * This method returns the node that contains information about the
ingo@114: * reachable states of the artifact in the artifact's DESCRIBE document.
ingo@114: *
ingo@114: * @param description The document returned by the artifact server's
ingo@114: * DESCRIBE operation.
ingo@114: *
ingo@114: * @return the node that contains the reachable states.
ingo@114: */
ingo@114: public static Node getReachableStates(Document description) {
ingo@114: return (Node) XMLUtils.xpath(
ingo@114: description,
ingo@114: XPATH_STATES,
ingo@114: XPathConstants.NODE,
ingo@114: ArtifactNamespaceContext.INSTANCE);
ingo@114: }
ingo@114:
ingo@114:
ingo@114: /**
ingo@211: * This method returns the output mode nodes of the DESCRIBE document.
ingo@211: *
ingo@211: * @param description The document returned by the artifact server's
ingo@211: * DESCRIBE operation.
ingo@211: *
ingo@211: * @return the node that contains the output modes.
ingo@211: */
ingo@211: public static NodeList getOutputModes(Document description) {
ingo@211: return (NodeList) XMLUtils.xpath(
ingo@211: description,
ingo@211: XPATH_OUTPUT_MODES,
ingo@211: XPathConstants.NODESET,
ingo@211: ArtifactNamespaceContext.INSTANCE);
ingo@211: }
ingo@211:
ingo@211:
ingo@211: /**
ingo@114: * Returns the node found by {@link XPATH_DATA_SELECT}.
ingo@114: *
ingo@114: * @param dynamicNode The dynamic UI node of the DESCRIBE document.
ingo@114: *
ingo@114: * @return the select node found in the dynamic UI node.
ingo@114: */
ingo@208: public static NodeList getSelectNode(Node dynamicNode) {
ingo@208: return (NodeList) XMLUtils.xpath(
ingo@114: dynamicNode,
ingo@114: XPATH_DATA_SELECT,
ingo@208: XPathConstants.NODESET,
ingo@114: ArtifactNamespaceContext.INSTANCE);
ingo@114: }
ingo@114:
ingo@114:
ingo@114: /**
ingo@114: * Returns the items that could be found in the node.
ingo@114: *
ingo@114: * @param node A select node.
ingo@114: *
ingo@114: * @return the choices nodes as node list.
ingo@114: */
ingo@114: public static NodeList getItemNodes(Node node) {
ingo@114: return (NodeList) XMLUtils.xpath(
ingo@114: node,
ingo@114: XPATH_DATA_ITEMS,
ingo@114: XPathConstants.NODESET,
ingo@114: ArtifactNamespaceContext.INSTANCE);
ingo@114: }
ingo@370:
ingo@370:
ingo@370: public static String getMinNode(Node parent) {
ingo@370: return (String) XMLUtils.xpath(
ingo@370: parent,
ingo@370: XPATH_MIN_NODE,
ingo@370: XPathConstants.STRING,
ingo@370: ArtifactNamespaceContext.INSTANCE);
ingo@370: }
ingo@370:
ingo@370:
ingo@370: public static String getMaxNode(Node parent) {
ingo@370: return (String) XMLUtils.xpath(
ingo@370: parent,
ingo@370: XPATH_MAX_NODE,
ingo@370: XPathConstants.STRING,
ingo@370: ArtifactNamespaceContext.INSTANCE);
ingo@370: }
ingo@371:
ingo@371:
ingo@371: public static String getDefMin(Node parent) {
ingo@371: return (String) XMLUtils.xpath(
ingo@371: parent,
ingo@371: XPATH_DEF_MIN,
ingo@371: XPathConstants.STRING,
ingo@371: ArtifactNamespaceContext.INSTANCE);
ingo@371: }
ingo@371:
ingo@371:
ingo@371: public static String getDefMax(Node parent) {
ingo@371: return (String) XMLUtils.xpath(
ingo@371: parent,
ingo@371: XPATH_DEF_MAX,
ingo@371: XPathConstants.STRING,
ingo@371: ArtifactNamespaceContext.INSTANCE);
ingo@371: }
ingo@113: }
ingo@113: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :