Mercurial > dive4elements > framework
changeset 114:19b86e27d0c3
New XPath constants and methods that retrieve important nodes of the DESCRIBE document.
artifacts/trunk@1328 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 18 Feb 2011 14:21:32 +0000 |
parents | 0344a20f8a93 |
children | a1200c6ed048 |
files | ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java |
diffstat | 2 files changed, 176 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ingo@intevation.de> + + * 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 <ingo@intevation.de> * artifacts-common/src/main/java/de/intevation/artifacts/common/ArtifactNamespaceContext.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 + * <i>node</i>. + * + * @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 + * <i>node</i>. + * + * @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 <i>node</i>. + * + * @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 :