Mercurial > dive4elements > framework
comparison artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/ClientProtocolUtils.java @ 472:783cc1b6b615
Moved directories to org.dive4elements
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 10:53:15 +0200 |
parents | artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java@831d317547eb |
children | 415df0fc4fa1 |
comparison
equal
deleted
inserted
replaced
471:1a87cb24a446 | 472:783cc1b6b615 |
---|---|
1 /* | |
2 * Copyright (c) 2011 by Intevation GmbH | |
3 * | |
4 * This program is free software under the LGPL (>=v2.1) | |
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. | |
7 */ | |
8 package de.intevation.artifacts.common.utils; | |
9 | |
10 import javax.xml.xpath.XPathConstants; | |
11 | |
12 import org.w3c.dom.Document; | |
13 import org.w3c.dom.Element; | |
14 import org.w3c.dom.Node; | |
15 import org.w3c.dom.NodeList; | |
16 | |
17 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
18 | |
19 | |
20 /** | |
21 * This class provides methods that help creating the artifact protocol | |
22 * documents DESCRIBE, FEED, ADVANCE and OUT. | |
23 * | |
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
25 */ | |
26 public class ClientProtocolUtils { | |
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 output modes in the DESCRIBE document. */ | |
42 public static final String XPATH_OUTPUT_MODES = | |
43 "/art:result/art:outputmodes/art:output"; | |
44 | |
45 /** The XPath to the select node relative to the dynamic UI node in the | |
46 * DESCRIBE document. */ | |
47 public static final String XPATH_DATA_SELECT = "art:select"; | |
48 | |
49 /** The XPath to the choices nodes relative to the select node in the | |
50 * DESCRIBE document. */ | |
51 public static final String XPATH_DATA_ITEMS = "art:choices/art:item"; | |
52 | |
53 /** The XPath that points to the min value of a range.*/ | |
54 public static final String XPATH_MIN_NODE = "art:min/@art:value"; | |
55 | |
56 /** The XPath that points to the max value of a range.*/ | |
57 public static final String XPATH_MAX_NODE = "art:max/@art:value"; | |
58 | |
59 /** The XPath that points to the default min value of a range.*/ | |
60 public static final String XPATH_DEF_MIN = "art:min/@art:default"; | |
61 | |
62 /** The XPath that points to the default max value of a range.*/ | |
63 public static final String XPATH_DEF_MAX = "art:max/@art:default"; | |
64 | |
65 /** The XPath to a label in the artifact's DESCRIBE document. */ | |
66 public static final String XPATH_LABEL = "art:label/text()"; | |
67 | |
68 /** The XPath to a value in the artifact's DESCRIBE document. */ | |
69 public static final String XPATH_VALUE = "art:value/text()"; | |
70 | |
71 | |
72 /** | |
73 * It should not be necessary to create instances of this class. | |
74 */ | |
75 private ClientProtocolUtils() { | |
76 } | |
77 | |
78 | |
79 /** | |
80 * This method creates a new CREATE document. | |
81 * | |
82 * @return the CREATE document. | |
83 */ | |
84 public static Document newCreateDocument(String factory) { | |
85 return newCreateDocument(factory, null); | |
86 } | |
87 | |
88 | |
89 /** | |
90 * This method creates a new CREATE document. | |
91 * | |
92 * @return the CREATE document. | |
93 */ | |
94 public static Document newCreateDocument(String factory, String uuid) { | |
95 return newCreateDocument(factory, uuid, null); | |
96 } | |
97 | |
98 public static Document newCreateDocument( | |
99 String factory, | |
100 String uuid, | |
101 String ids | |
102 ) { | |
103 return newCreateDocument(factory, uuid, ids, null); | |
104 } | |
105 | |
106 /** | |
107 * This method creates a new CREATE document. | |
108 * | |
109 * @return the CREATE document. | |
110 */ | |
111 public static Document newCreateDocument( | |
112 String factory, | |
113 String uuid, | |
114 String ids, | |
115 CreationFilter filter | |
116 ) { | |
117 Document doc = XMLUtils.newDocument(); | |
118 | |
119 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
120 doc, | |
121 ArtifactNamespaceContext.NAMESPACE_URI, | |
122 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
123 | |
124 Element action = cr.create("action"); | |
125 Element type = cr.create("type"); | |
126 Element fac = cr.create("factory"); | |
127 | |
128 type.setAttribute("name", "create"); | |
129 fac.setAttribute("name", factory); | |
130 | |
131 action.appendChild(type); | |
132 action.appendChild(fac); | |
133 | |
134 if (uuid != null) { | |
135 Element templ = cr.create("template"); | |
136 templ.setAttribute("uuid", uuid); | |
137 action.appendChild(templ); | |
138 } | |
139 | |
140 if (ids != null) { | |
141 Element id = cr.create("ids"); | |
142 id.setAttribute("value", ids); | |
143 action.appendChild(id); | |
144 } | |
145 | |
146 if (filter != null) { | |
147 action.appendChild(filter.toXML(cr)); | |
148 } | |
149 | |
150 doc.appendChild(action); | |
151 | |
152 return doc; | |
153 } | |
154 | |
155 | |
156 /** | |
157 * This method creates a new FEED document. | |
158 * | |
159 * @param theUuid The identifier of the artifact. | |
160 * @param theHash The hash of the artifact. | |
161 * @param theData An array that contains key/value pairs that represent the | |
162 * data that should be included in the FEED document. | |
163 * | |
164 * @return the FEED document. | |
165 */ | |
166 public static Document newFeedDocument( | |
167 String theUuid, | |
168 String theHash, | |
169 String[][] theData) | |
170 { | |
171 Document doc = XMLUtils.newDocument(); | |
172 | |
173 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
174 doc, | |
175 ArtifactNamespaceContext.NAMESPACE_URI, | |
176 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
177 | |
178 Element action = cr.create("action"); | |
179 Element type = cr.create("type"); | |
180 Element uuid = cr.create("uuid"); | |
181 Element hash = cr.create("hash"); | |
182 Element data = cr.create("data"); | |
183 | |
184 // XXX It is not nice that the type has no attribute namespace, but to | |
185 // be backward compatible, we don't change this now. | |
186 cr.addAttr(type, "name", "feed", false); | |
187 cr.addAttr(uuid, "value", theUuid, true); | |
188 cr.addAttr(hash, "value", theHash, true); | |
189 | |
190 for (String[] kvp: theData) { | |
191 Element input = cr.create("input"); | |
192 cr.addAttr(input, "name", kvp[0], true); | |
193 cr.addAttr(input, "value", kvp[1], true); | |
194 | |
195 data.appendChild(input); | |
196 } | |
197 | |
198 action.appendChild(type); | |
199 action.appendChild(uuid); | |
200 action.appendChild(hash); | |
201 action.appendChild(data); | |
202 | |
203 doc.appendChild(action); | |
204 | |
205 return doc; | |
206 } | |
207 | |
208 | |
209 /** | |
210 * This method creates a new DESCRIBE document. | |
211 * | |
212 * @param theUuid The identifier of the artifact. | |
213 * @param theHash The hash of the artifact. | |
214 * @param ui If true, the UI part is included. | |
215 * | |
216 * @return the DESCRIBE document. | |
217 */ | |
218 public static Document newDescribeDocument( | |
219 String theUuid, | |
220 String theHash, | |
221 boolean incUI) | |
222 { | |
223 Document doc = XMLUtils.newDocument(); | |
224 | |
225 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
226 doc, | |
227 ArtifactNamespaceContext.NAMESPACE_URI, | |
228 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
229 | |
230 Element action = cr.create("action"); | |
231 Element type = cr.create("type"); | |
232 Element uuid = cr.create("uuid"); | |
233 Element hash = cr.create("hash"); | |
234 Element ui = cr.create("include-ui"); | |
235 | |
236 // XXX It is not nice that the type has no attribute namespace, but to | |
237 // be backward compatible, we don't change this now. | |
238 cr.addAttr(type, "name", "describe", false); | |
239 cr.addAttr(uuid, "value", theUuid, true); | |
240 cr.addAttr(hash, "value", theHash, true); | |
241 | |
242 ui.setTextContent(incUI ? "true" : "false"); | |
243 | |
244 action.appendChild(type); | |
245 action.appendChild(uuid); | |
246 action.appendChild(hash); | |
247 action.appendChild(ui); | |
248 | |
249 doc.appendChild(action); | |
250 | |
251 return doc; | |
252 } | |
253 | |
254 | |
255 /** | |
256 * This method creates a new ADVANCE document. | |
257 * | |
258 * @param theUuid The identifier of the artifact. | |
259 * @param theHash The hash of the artifact. | |
260 * @param theTarget The target state identifier. | |
261 * | |
262 * @return the ADVANCE document. | |
263 */ | |
264 public static Document newAdvanceDocument( | |
265 String theUuid, | |
266 String theHash, | |
267 String theTarget) | |
268 { | |
269 Document doc = XMLUtils.newDocument(); | |
270 | |
271 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
272 doc, | |
273 ArtifactNamespaceContext.NAMESPACE_URI, | |
274 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
275 | |
276 Element action = cr.create("action"); | |
277 Element type = cr.create("type"); | |
278 Element uuid = cr.create("uuid"); | |
279 Element hash = cr.create("hash"); | |
280 Element target = cr.create("target"); | |
281 | |
282 // XXX It is not nice that the type has no attribute namespace, but to | |
283 // be backward compatible, we don't change this now. | |
284 cr.addAttr(type, "name", "advance", false); | |
285 cr.addAttr(uuid, "value", theUuid, true); | |
286 cr.addAttr(hash, "value", theHash, true); | |
287 cr.addAttr(target, "name", theTarget, true); | |
288 | |
289 action.appendChild(type); | |
290 action.appendChild(uuid); | |
291 action.appendChild(hash); | |
292 action.appendChild(target); | |
293 | |
294 doc.appendChild(action); | |
295 | |
296 return doc; | |
297 } | |
298 | |
299 | |
300 /** | |
301 * This method creates a new document that is used to create new artifact | |
302 * collections in the artifact server. | |
303 * | |
304 * @param name <b>Optional</b> name of the collection. | |
305 * | |
306 * @return the document to create new collections. | |
307 */ | |
308 public static Document newCreateCollectionDocument(String name) { | |
309 Document doc = XMLUtils.newDocument(); | |
310 | |
311 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
312 doc, | |
313 ArtifactNamespaceContext.NAMESPACE_URI, | |
314 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
315 | |
316 Element action = cr.create("action"); | |
317 Element type = cr.create("type"); | |
318 Element collection = cr.create("collection"); | |
319 Element attribute = cr.create("attribute"); | |
320 | |
321 cr.addAttr(type, "name", "create"); | |
322 cr.addAttr(collection, "name", name != null ? name : ""); | |
323 | |
324 action.appendChild(type); | |
325 type.appendChild(collection); | |
326 collection.appendChild(attribute); | |
327 | |
328 doc.appendChild(action); | |
329 | |
330 return doc; | |
331 } | |
332 | |
333 | |
334 /** | |
335 * This method creates a new Document that is used to add an artifact to a | |
336 * collection in the artifact server. | |
337 * | |
338 * @param artId The identifier of the artifact that should be added. | |
339 * @param attr A document that contains attributes for the artifact's | |
340 * life in the collection. | |
341 * | |
342 * @return the document to add an artifact into a collection. | |
343 */ | |
344 public static Document newAddArtifactDocument(String artId, Document attr) { | |
345 Document doc = XMLUtils.newDocument(); | |
346 | |
347 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
348 doc, | |
349 ArtifactNamespaceContext.NAMESPACE_URI, | |
350 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
351 | |
352 Element action = cr.create("action"); | |
353 Element type = cr.create("type"); | |
354 Element artifact = cr.create("artifact"); | |
355 Element attribute = cr.create("attribute"); | |
356 | |
357 cr.addAttr(artifact, "uuid", artId); | |
358 cr.addAttr(type, "name", "addartifact"); | |
359 | |
360 if (attr != null) { | |
361 attr.appendChild(attr); | |
362 } | |
363 | |
364 action.appendChild(type); | |
365 type.appendChild(artifact); | |
366 artifact.appendChild(attribute); | |
367 | |
368 doc.appendChild(action); | |
369 | |
370 return doc; | |
371 } | |
372 | |
373 | |
374 /** | |
375 * Create a new Document that is used to remove an artifact from a | |
376 * collection in the artifact server. | |
377 * | |
378 * @param artId The identifier of the artifact that should be added. | |
379 * | |
380 * @return the document to add an artifact into a collection. | |
381 */ | |
382 public static Document newRemoveArtifactDocument(String artId) { | |
383 Document doc = XMLUtils.newDocument(); | |
384 | |
385 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
386 doc, | |
387 ArtifactNamespaceContext.NAMESPACE_URI, | |
388 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
389 | |
390 Element action = cr.create("action"); | |
391 Element type = cr.create("type"); | |
392 Element artifact = cr.create("artifact"); | |
393 | |
394 cr.addAttr(artifact, "uuid", artId); | |
395 cr.addAttr(type, "name", "removeartifact"); | |
396 | |
397 action.appendChild(type); | |
398 type.appendChild(artifact); | |
399 | |
400 doc.appendChild(action); | |
401 | |
402 return doc; | |
403 } | |
404 | |
405 | |
406 /** | |
407 * This method creates a new Document that is used to trigger the DESCRIBE | |
408 * operation of a collection in the artifact server. | |
409 * | |
410 * @param uuid The identifier of the collection that should be described. | |
411 * | |
412 * @return the document to describe a collection. | |
413 */ | |
414 public static Document newDescribeCollectionDocument(String uuid) { | |
415 Document doc = XMLUtils.newDocument(); | |
416 | |
417 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
418 doc, | |
419 ArtifactNamespaceContext.NAMESPACE_URI, | |
420 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
421 | |
422 Element action = cr.create("action"); | |
423 Element type = cr.create("type"); | |
424 cr.addAttr(type, "name", "describe"); | |
425 | |
426 action.appendChild(type); | |
427 | |
428 doc.appendChild(action); | |
429 | |
430 return doc; | |
431 } | |
432 | |
433 | |
434 | |
435 /** | |
436 * This function builds a document that is used as request document of the | |
437 * out() operation of Collections. | |
438 * | |
439 * @param uuid The identifier of the collection. | |
440 * @param mode The name of the desired output mode. | |
441 * @param type The name of the desired output type. | |
442 * | |
443 * @return the request document. | |
444 */ | |
445 public static Document newOutCollectionDocument( | |
446 String uuid, | |
447 String mode, | |
448 String type) { | |
449 return newOutCollectionDocument(uuid, mode, type, null); | |
450 } | |
451 | |
452 | |
453 /** | |
454 * This function builds a document that is used as request document of the | |
455 * out() operation of Collections. The document <i>attr</i> might be used to | |
456 * adjust some settings specific to the output. | |
457 * | |
458 * @param uuid The identifier of the collection. | |
459 * @param mode The name of the desired output mode. | |
460 * @param type The name of the desired output type. | |
461 * @param attr A document that contains settings specific to the output. | |
462 * | |
463 * @return the request document. | |
464 */ | |
465 public static Document newOutCollectionDocument( | |
466 String uuid, | |
467 String mode, | |
468 String type, | |
469 Document attr) | |
470 { | |
471 Document doc = XMLUtils.newDocument(); | |
472 | |
473 XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( | |
474 doc, | |
475 ArtifactNamespaceContext.NAMESPACE_URI, | |
476 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
477 | |
478 Element action = cr.create("action"); | |
479 | |
480 cr.addAttr(action, "name", mode, true); | |
481 cr.addAttr(action, "type", type, true); | |
482 | |
483 doc.appendChild(action); | |
484 | |
485 if (attr != null) { | |
486 Node root = attr.getFirstChild(); | |
487 | |
488 if (root != null) { | |
489 action.appendChild(doc.importNode(root, true)); | |
490 } | |
491 } | |
492 | |
493 return doc; | |
494 } | |
495 | |
496 | |
497 /** | |
498 * This function creates a document that is used to set the attribute of a | |
499 * Collection. | |
500 * | |
501 * @param uuid The identifier of the Collection. | |
502 * @param attr The new attribute value for the Collection. | |
503 * | |
504 * @return the document that is used to set the attribute. | |
505 */ | |
506 public static Document newSetAttributeDocument( | |
507 String uuid, | |
508 Document attr) | |
509 { | |
510 Node root = attr != null ? attr.getFirstChild() : null; | |
511 | |
512 if (root == null) { | |
513 return null; | |
514 } | |
515 | |
516 Document doc = XMLUtils.newDocument(); | |
517 | |
518 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
519 doc, | |
520 ArtifactNamespaceContext.NAMESPACE_URI, | |
521 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
522 | |
523 Element action = ec.create("action"); | |
524 Element type = ec.create("type"); | |
525 Element collection = ec.create("collection"); | |
526 | |
527 ec.addAttr(type, "name", "setattribute", false); | |
528 ec.addAttr(collection, "uuid", uuid, false); | |
529 | |
530 doc.appendChild(action); | |
531 action.appendChild(type); | |
532 type.appendChild(collection); | |
533 | |
534 collection.appendChild(doc.importNode(root, true)); | |
535 | |
536 return doc; | |
537 } | |
538 | |
539 /** | |
540 * This function creates a document that is used to set the attribute of a | |
541 * CollectionItem. | |
542 * | |
543 * @param uuid The identifier of the CollectionItem. | |
544 * @param attr The new attribute value for the CollectionItem. | |
545 * | |
546 * @return the document that is used to set the attribute. | |
547 */ | |
548 public static Document newSetItemAttributeDocument( | |
549 String uuid, | |
550 Document attr) | |
551 { | |
552 Node root = attr.getFirstChild(); | |
553 | |
554 if (root == null) { | |
555 return null; | |
556 } | |
557 | |
558 Document doc = XMLUtils.newDocument(); | |
559 | |
560 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
561 doc, | |
562 ArtifactNamespaceContext.NAMESPACE_URI, | |
563 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
564 | |
565 Element action = ec.create("action"); | |
566 Element type = ec.create("type"); | |
567 Element artifact = ec.create("artifact"); | |
568 | |
569 ec.addAttr(type, "name", "setitemattribute"); | |
570 ec.addAttr(artifact, "uuid", uuid); | |
571 | |
572 doc.appendChild(action); | |
573 action.appendChild(type); | |
574 type.appendChild(artifact); | |
575 | |
576 artifact.appendChild(doc.importNode(root, true)); | |
577 | |
578 return doc; | |
579 } | |
580 | |
581 | |
582 /** | |
583 * This function creates a document that is used to set the time-to-live | |
584 * of a collection. | |
585 * | |
586 * @param ttl The ttl for the Collection. | |
587 * | |
588 * @return the document that is used to set the time-to-live. | |
589 */ | |
590 public static Document newSetCollectionTTLDocument(String ttl) { | |
591 Document doc = XMLUtils.newDocument(); | |
592 | |
593 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
594 doc, | |
595 ArtifactNamespaceContext.NAMESPACE_URI, | |
596 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
597 | |
598 Element action = ec.create("action"); | |
599 Element type = ec.create("type"); | |
600 Element ttlEl = ec.create("ttl"); | |
601 | |
602 ec.addAttr(type, "name", "settimetolive"); | |
603 ec.addAttr(ttlEl, "value", ttl); | |
604 | |
605 doc.appendChild(action); | |
606 action.appendChild(type); | |
607 type.appendChild(ttlEl); | |
608 | |
609 return doc; | |
610 } | |
611 | |
612 | |
613 /** | |
614 * This function creates a document that is used to set the name of a | |
615 * collection. | |
616 * | |
617 * @param name The name for the Collection. | |
618 * | |
619 * @return the document that is used to set the name of a collection. | |
620 */ | |
621 public static Document newSetCollectionNameDocument(String name) { | |
622 Document doc = XMLUtils.newDocument(); | |
623 | |
624 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
625 doc, | |
626 ArtifactNamespaceContext.NAMESPACE_URI, | |
627 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
628 | |
629 Element action = ec.create("action"); | |
630 Element type = ec.create("type"); | |
631 Element coll = ec.create("collection"); | |
632 | |
633 ec.addAttr(type, "name", "setname"); | |
634 ec.addAttr(coll, "name", name); | |
635 | |
636 doc.appendChild(action); | |
637 action.appendChild(type); | |
638 type.appendChild(coll); | |
639 | |
640 return doc; | |
641 } | |
642 | |
643 | |
644 /** | |
645 * This function creates a document that is used to delete an existing | |
646 * collection. | |
647 * | |
648 * @return the document that is used to delete an existing collection. | |
649 */ | |
650 public static Document newDeleteCollectionDocument() { | |
651 Document doc = XMLUtils.newDocument(); | |
652 | |
653 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
654 doc, | |
655 ArtifactNamespaceContext.NAMESPACE_URI, | |
656 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
657 | |
658 Element action = ec.create("action"); | |
659 Element type = ec.create("type"); | |
660 | |
661 ec.addAttr(type, "name", "delete"); | |
662 | |
663 doc.appendChild(action); | |
664 action.appendChild(type); | |
665 | |
666 return doc; | |
667 } | |
668 | |
669 | |
670 /** | |
671 * Returns string value found by {@link XPATH_LABEL} relative to | |
672 * <i>node</i>. | |
673 * | |
674 * @param node A node. | |
675 * | |
676 * @return the string value found by {@link XPATH_LABEL}. | |
677 */ | |
678 public static String getLabel(Node node) { | |
679 return (String) XMLUtils.xpath( | |
680 node, | |
681 XPATH_LABEL, | |
682 XPathConstants.STRING, | |
683 ArtifactNamespaceContext.INSTANCE); | |
684 } | |
685 | |
686 | |
687 /** | |
688 * Returns string value found by {@link XPATH_VALUE} relative to | |
689 * <i>node</i>. | |
690 * | |
691 * @param node A node. | |
692 * | |
693 * @return the string value found by {@link XPATH_VALUE}. | |
694 */ | |
695 public static String getValue(Node node) { | |
696 return (String) XMLUtils.xpath( | |
697 node, | |
698 XPATH_VALUE, | |
699 XPathConstants.STRING, | |
700 ArtifactNamespaceContext.INSTANCE); | |
701 } | |
702 | |
703 | |
704 /** | |
705 * This method returns the static UI part of the artifact's DESCRIBE | |
706 * document. | |
707 * | |
708 * @param description The document returned by the artifact server's | |
709 * DESCRIBE operation. | |
710 * | |
711 * @return the static UI node. | |
712 */ | |
713 public static Node getStaticUI(Document description) { | |
714 return (Node) XMLUtils.xpath( | |
715 description, | |
716 XPATH_STATIC, | |
717 XPathConstants.NODE, | |
718 ArtifactNamespaceContext.INSTANCE); | |
719 } | |
720 | |
721 | |
722 /** | |
723 * This method returns the dynamic UI part of the artifact's DESCRIBE | |
724 * document. | |
725 * | |
726 * @param description The document returned by the artifact server's | |
727 * DESCRIBE operation. | |
728 * | |
729 * @return the dynamic UI node. | |
730 */ | |
731 public static Node getDynamicUI(Document description) { | |
732 return (Node) XMLUtils.xpath( | |
733 description, | |
734 XPATH_DYNAMIC, | |
735 XPathConstants.NODE, | |
736 ArtifactNamespaceContext.INSTANCE); | |
737 } | |
738 | |
739 | |
740 /** | |
741 * This method returns the current state node contained in the DESCRIBE | |
742 * document. | |
743 * | |
744 * @param description The document returned by the artifact server's | |
745 * DESCRIBE operation. | |
746 * | |
747 * @return the node containing information about the current state. | |
748 */ | |
749 public static Node getCurrentState(Document description) { | |
750 return (Node) XMLUtils.xpath( | |
751 description, | |
752 XPATH_CURRENT_STATE, | |
753 XPathConstants.NODE, | |
754 ArtifactNamespaceContext.INSTANCE); | |
755 } | |
756 | |
757 | |
758 /** | |
759 * This method returns the node that contains information about the | |
760 * reachable states of the artifact in the artifact's DESCRIBE document. | |
761 * | |
762 * @param description The document returned by the artifact server's | |
763 * DESCRIBE operation. | |
764 * | |
765 * @return the node that contains the reachable states. | |
766 */ | |
767 public static Node getReachableStates(Document description) { | |
768 return (Node) XMLUtils.xpath( | |
769 description, | |
770 XPATH_STATES, | |
771 XPathConstants.NODE, | |
772 ArtifactNamespaceContext.INSTANCE); | |
773 } | |
774 | |
775 | |
776 /** | |
777 * This method returns the output mode nodes of the DESCRIBE document. | |
778 * | |
779 * @param description The document returned by the artifact server's | |
780 * DESCRIBE operation. | |
781 * | |
782 * @return the node that contains the output modes. | |
783 */ | |
784 public static NodeList getOutputModes(Document description) { | |
785 return (NodeList) XMLUtils.xpath( | |
786 description, | |
787 XPATH_OUTPUT_MODES, | |
788 XPathConstants.NODESET, | |
789 ArtifactNamespaceContext.INSTANCE); | |
790 } | |
791 | |
792 | |
793 /** | |
794 * Returns the node found by {@link XPATH_DATA_SELECT}. | |
795 * | |
796 * @param dynamicNode The dynamic UI node of the DESCRIBE document. | |
797 * | |
798 * @return the select node found in the dynamic UI node. | |
799 */ | |
800 public static NodeList getSelectNode(Node dynamicNode) { | |
801 return (NodeList) XMLUtils.xpath( | |
802 dynamicNode, | |
803 XPATH_DATA_SELECT, | |
804 XPathConstants.NODESET, | |
805 ArtifactNamespaceContext.INSTANCE); | |
806 } | |
807 | |
808 | |
809 /** | |
810 * Returns the items that could be found in the <i>node</i>. | |
811 * | |
812 * @param node A select node. | |
813 * | |
814 * @return the choices nodes as node list. | |
815 */ | |
816 public static NodeList getItemNodes(Node node) { | |
817 return (NodeList) XMLUtils.xpath( | |
818 node, | |
819 XPATH_DATA_ITEMS, | |
820 XPathConstants.NODESET, | |
821 ArtifactNamespaceContext.INSTANCE); | |
822 } | |
823 | |
824 | |
825 public static String getMinNode(Node parent) { | |
826 return (String) XMLUtils.xpath( | |
827 parent, | |
828 XPATH_MIN_NODE, | |
829 XPathConstants.STRING, | |
830 ArtifactNamespaceContext.INSTANCE); | |
831 } | |
832 | |
833 | |
834 public static String getMaxNode(Node parent) { | |
835 return (String) XMLUtils.xpath( | |
836 parent, | |
837 XPATH_MAX_NODE, | |
838 XPathConstants.STRING, | |
839 ArtifactNamespaceContext.INSTANCE); | |
840 } | |
841 | |
842 | |
843 public static String getDefMin(Node parent) { | |
844 return (String) XMLUtils.xpath( | |
845 parent, | |
846 XPATH_DEF_MIN, | |
847 XPathConstants.STRING, | |
848 ArtifactNamespaceContext.INSTANCE); | |
849 } | |
850 | |
851 | |
852 public static String getDefMax(Node parent) { | |
853 return (String) XMLUtils.xpath( | |
854 parent, | |
855 XPATH_DEF_MAX, | |
856 XPathConstants.STRING, | |
857 ArtifactNamespaceContext.INSTANCE); | |
858 } | |
859 } | |
860 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |