# HG changeset patch # User Ingo Weinzierl # Date 1298038892 0 # Node ID 19b86e27d0c380c808c472403de46d05a50ac328 # Parent 0344a20f8a93ee5cca3339d9ddfba93f759dcb35 New XPath constants and methods that retrieve important nodes of the DESCRIBE document. artifacts/trunk@1328 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 0344a20f8a93 -r 19b86e27d0c3 ChangeLog --- a/ChangeLog Wed Feb 16 15:26:38 2011 +0000 +++ b/ChangeLog Fri Feb 18 14:21:32 2011 +0000 @@ -1,3 +1,9 @@ +2011-02-18 Ingo Weinzierl + + * artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java: + Added XPath constants and some method that retrieve important nodes of the + DESCRIBE document. + 2011-02-16 Ingo Weinzierl * artifacts-common/src/main/java/de/intevation/artifacts/common/ArtifactNamespaceContext.java: diff -r 0344a20f8a93 -r 19b86e27d0c3 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 Feb 16 15:26:38 2011 +0000 +++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java Fri Feb 18 14:21:32 2011 +0000 @@ -7,8 +7,12 @@ */ package de.intevation.artifacts.common.utils; +import javax.xml.xpath.XPathConstants; + import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import de.intevation.artifacts.common.ArtifactNamespaceContext; @@ -21,6 +25,34 @@ */ public class ClientProtocolUtils { + /** The XPath to the current state in the DESCRIBE document.*/ + public static final String XPATH_CURRENT_STATE = "/art:result/art:state"; + + /** The XPath to the static UI part in the DESCRIBE document.*/ + public static final String XPATH_STATIC = "/art:result/art:ui/art:static"; + + /** The XPath to the dynamic UI part in the DESCRIBE document.*/ + public static final String XPATH_DYNAMIC = "/art:result/art:ui/art:dynamic"; + + /** The XPath to the reachable states part in the DESCRIBE document.*/ + public static final String XPATH_STATES = + "/art:result/art:reachable-states"; + + /** The XPath to the select node relative to the dynamic UI node in the + * DESCRIBE document.*/ + public static final String XPATH_DATA_SELECT = "art:select"; + + /** The XPath to the choices nodes relative to the select node in the + * DESCRIBE document.*/ + public static final String XPATH_DATA_ITEMS = "art:choices/art:item"; + + /** The XPath to a label in the artifact's DESCRIBE document.*/ + public static final String XPATH_LABEL = "art:label/text()"; + + /** The XPath to a value in the artifact's DESCRIBE document.*/ + public static final String XPATH_VALUE = "art:value/text()"; + + /** * It should not be necessary to create instances of this class. */ @@ -55,5 +87,143 @@ return doc; } + + + /** + * Returns string value found by {@link XPATH_LABEL} relative to + * node. + * + * @param node A node. + * + * @return the string value found by {@link XPATH_LABEL}. + */ + public static String getLabel(Node node) { + return (String) XMLUtils.xpath( + node, + XPATH_LABEL, + XPathConstants.STRING, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * Returns string value found by {@link XPATH_VALUE} relative to + * node. + * + * @param node A node. + * + * @return the string value found by {@link XPATH_VALUE}. + */ + public static String getValue(Node node) { + return (String) XMLUtils.xpath( + node, + XPATH_VALUE, + XPathConstants.STRING, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * This method returns the static UI part of the artifact's DESCRIBE + * document. + * + * @param description The document returned by the artifact server's + * DESCRIBE operation. + * + * @return the static UI node. + */ + public static Node getStaticUI(Document description) { + return (Node) XMLUtils.xpath( + description, + XPATH_STATIC, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * This method returns the dynamic UI part of the artifact's DESCRIBE + * document. + * + * @param description The document returned by the artifact server's + * DESCRIBE operation. + * + * @return the dynamic UI node. + */ + public static Node getDynamicUI(Document description) { + return (Node) XMLUtils.xpath( + description, + XPATH_DYNAMIC, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * This method returns the current state node contained in the DESCRIBE + * document. + * + * @param description The document returned by the artifact server's + * DESCRIBE operation. + * + * @return the node containing information about the current state. + */ + public static Node getCurrentState(Document description) { + return (Node) XMLUtils.xpath( + description, + XPATH_CURRENT_STATE, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * This method returns the node that contains information about the + * reachable states of the artifact in the artifact's DESCRIBE document. + * + * @param description The document returned by the artifact server's + * DESCRIBE operation. + * + * @return the node that contains the reachable states. + */ + public static Node getReachableStates(Document description) { + return (Node) XMLUtils.xpath( + description, + XPATH_STATES, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * Returns the node found by {@link XPATH_DATA_SELECT}. + * + * @param dynamicNode The dynamic UI node of the DESCRIBE document. + * + * @return the select node found in the dynamic UI node. + */ + public static Node getSelectNode(Node dynamicNode) { + return (Node) XMLUtils.xpath( + dynamicNode, + XPATH_DATA_SELECT, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + } + + + /** + * Returns the items that could be found in the node. + * + * @param node A select node. + * + * @return the choices nodes as node list. + */ + public static NodeList getItemNodes(Node node) { + return (NodeList) XMLUtils.xpath( + node, + XPATH_DATA_ITEMS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :