comparison artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java @ 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 8ce06db80857
comparison
equal deleted inserted replaced
113:0344a20f8a93 114:19b86e27d0c3
5 * Read the file LGPL.txt coming with the software for details 5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist. 6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */ 7 */
8 package de.intevation.artifacts.common.utils; 8 package de.intevation.artifacts.common.utils;
9 9
10 import javax.xml.xpath.XPathConstants;
11
10 import org.w3c.dom.Document; 12 import org.w3c.dom.Document;
11 import org.w3c.dom.Element; 13 import org.w3c.dom.Element;
14 import org.w3c.dom.Node;
15 import org.w3c.dom.NodeList;
12 16
13 import de.intevation.artifacts.common.ArtifactNamespaceContext; 17 import de.intevation.artifacts.common.ArtifactNamespaceContext;
14 18
15 19
16 /** 20 /**
19 * 23 *
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
21 */ 25 */
22 public class ClientProtocolUtils { 26 public class ClientProtocolUtils {
23 27
28 /** The XPath to the current state in the DESCRIBE document.*/
29 public static final String XPATH_CURRENT_STATE = "/art:result/art:state";
30
31 /** The XPath to the static UI part in the DESCRIBE document.*/
32 public static final String XPATH_STATIC = "/art:result/art:ui/art:static";
33
34 /** The XPath to the dynamic UI part in the DESCRIBE document.*/
35 public static final String XPATH_DYNAMIC = "/art:result/art:ui/art:dynamic";
36
37 /** The XPath to the reachable states part in the DESCRIBE document.*/
38 public static final String XPATH_STATES =
39 "/art:result/art:reachable-states";
40
41 /** The XPath to the select node relative to the dynamic UI node in the
42 * DESCRIBE document.*/
43 public static final String XPATH_DATA_SELECT = "art:select";
44
45 /** The XPath to the choices nodes relative to the select node in the
46 * DESCRIBE document.*/
47 public static final String XPATH_DATA_ITEMS = "art:choices/art:item";
48
49 /** The XPath to a label in the artifact's DESCRIBE document.*/
50 public static final String XPATH_LABEL = "art:label/text()";
51
52 /** The XPath to a value in the artifact's DESCRIBE document.*/
53 public static final String XPATH_VALUE = "art:value/text()";
54
55
24 /** 56 /**
25 * It should not be necessary to create instances of this class. 57 * It should not be necessary to create instances of this class.
26 */ 58 */
27 private ClientProtocolUtils() { 59 private ClientProtocolUtils() {
28 } 60 }
53 85
54 doc.appendChild(action); 86 doc.appendChild(action);
55 87
56 return doc; 88 return doc;
57 } 89 }
90
91
92 /**
93 * Returns string value found by {@link XPATH_LABEL} relative to
94 * <i>node</i>.
95 *
96 * @param node A node.
97 *
98 * @return the string value found by {@link XPATH_LABEL}.
99 */
100 public static String getLabel(Node node) {
101 return (String) XMLUtils.xpath(
102 node,
103 XPATH_LABEL,
104 XPathConstants.STRING,
105 ArtifactNamespaceContext.INSTANCE);
106 }
107
108
109 /**
110 * Returns string value found by {@link XPATH_VALUE} relative to
111 * <i>node</i>.
112 *
113 * @param node A node.
114 *
115 * @return the string value found by {@link XPATH_VALUE}.
116 */
117 public static String getValue(Node node) {
118 return (String) XMLUtils.xpath(
119 node,
120 XPATH_VALUE,
121 XPathConstants.STRING,
122 ArtifactNamespaceContext.INSTANCE);
123 }
124
125
126 /**
127 * This method returns the static UI part of the artifact's DESCRIBE
128 * document.
129 *
130 * @param description The document returned by the artifact server's
131 * DESCRIBE operation.
132 *
133 * @return the static UI node.
134 */
135 public static Node getStaticUI(Document description) {
136 return (Node) XMLUtils.xpath(
137 description,
138 XPATH_STATIC,
139 XPathConstants.NODE,
140 ArtifactNamespaceContext.INSTANCE);
141 }
142
143
144 /**
145 * This method returns the dynamic UI part of the artifact's DESCRIBE
146 * document.
147 *
148 * @param description The document returned by the artifact server's
149 * DESCRIBE operation.
150 *
151 * @return the dynamic UI node.
152 */
153 public static Node getDynamicUI(Document description) {
154 return (Node) XMLUtils.xpath(
155 description,
156 XPATH_DYNAMIC,
157 XPathConstants.NODE,
158 ArtifactNamespaceContext.INSTANCE);
159 }
160
161
162 /**
163 * This method returns the current state node contained in the DESCRIBE
164 * document.
165 *
166 * @param description The document returned by the artifact server's
167 * DESCRIBE operation.
168 *
169 * @return the node containing information about the current state.
170 */
171 public static Node getCurrentState(Document description) {
172 return (Node) XMLUtils.xpath(
173 description,
174 XPATH_CURRENT_STATE,
175 XPathConstants.NODE,
176 ArtifactNamespaceContext.INSTANCE);
177 }
178
179
180 /**
181 * This method returns the node that contains information about the
182 * reachable states of the artifact in the artifact's DESCRIBE document.
183 *
184 * @param description The document returned by the artifact server's
185 * DESCRIBE operation.
186 *
187 * @return the node that contains the reachable states.
188 */
189 public static Node getReachableStates(Document description) {
190 return (Node) XMLUtils.xpath(
191 description,
192 XPATH_STATES,
193 XPathConstants.NODE,
194 ArtifactNamespaceContext.INSTANCE);
195 }
196
197
198 /**
199 * Returns the node found by {@link XPATH_DATA_SELECT}.
200 *
201 * @param dynamicNode The dynamic UI node of the DESCRIBE document.
202 *
203 * @return the select node found in the dynamic UI node.
204 */
205 public static Node getSelectNode(Node dynamicNode) {
206 return (Node) XMLUtils.xpath(
207 dynamicNode,
208 XPATH_DATA_SELECT,
209 XPathConstants.NODE,
210 ArtifactNamespaceContext.INSTANCE);
211 }
212
213
214 /**
215 * Returns the items that could be found in the <i>node</i>.
216 *
217 * @param node A select node.
218 *
219 * @return the choices nodes as node list.
220 */
221 public static NodeList getItemNodes(Node node) {
222 return (NodeList) XMLUtils.xpath(
223 node,
224 XPATH_DATA_ITEMS,
225 XPathConstants.NODESET,
226 ArtifactNamespaceContext.INSTANCE);
227 }
58 } 228 }
59 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 229 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org