Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java @ 107:39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
artifacts/trunk@1295 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 04 Feb 2011 16:52:39 +0000 |
parents | |
children | ab646e0f5569 |
rev | line source |
---|---|
107
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 /* |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 * Copyright (c) 2011 by Intevation GmbH |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 * |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 */ |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 package de.intevation.artifactdatabase; |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import org.w3c.dom.Element; |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import org.w3c.dom.Node; |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifacts.common.utils.XMLUtils; |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 /** |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 * This class provides methods that help creating the artifact protocol |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 * documents describe, feed, advance and out. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 * |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 */ |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 public class ProtocolUtils { |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 /** |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * It should not be necessary to create instances of this class. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 */ |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 private ProtocolUtils() {} |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 /** |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 * This method creates a node that might be used for the artifact protocol. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 * |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 * @param creator The ElementCreator that is used to create the node. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 * @param nodeName The node name. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 * @param attrName The names of optional attributes. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 * @param value The values for the optional attributes. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 * |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 * @return the created node. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 */ |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 public static Element createArtNode( |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 XMLUtils.ElementCreator creator, |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 String nodeName, String[] attrName, String[] value) |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 { |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 Element typeNode = creator.create(nodeName); |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 if (attrName != null && value != null) { |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 for (int i = 0; i < attrName.length; i++) { |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 if (i < value.length) { |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 creator.addAttr(typeNode, attrName[i], value[i], true); |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 } |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 else { |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 break; |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 } |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 } |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 } |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 return typeNode; |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 } |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 /** |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 * This method creates the root node for all artifact protocol documents. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 * |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 * @param creator The ElementCreator used to create new elements. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 * |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 * @return the root node for the artifact protocol document. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 */ |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 public static Element createRootNode(XMLUtils.ElementCreator creator) { |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 return createArtNode(creator, "result", null, null); |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 /** |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 * This method appends the three necessary nodes <i>type</i>, <i>uuid</i> |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 * and <i>hash</i> of the describe document to <i>root</i> node. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 * |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 * @param creator The ElementCreator that is used to create new nodes. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 * @param root The root node of the describe document. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 * @param uuid The UUID of the artifact. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 * @param hash The hash if the artifact. |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 */ |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 public static void appendDescribeHeader( |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 XMLUtils.ElementCreator creator, Element root, String uuid, String hash) |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 { |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 root.appendChild(createArtNode( |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 creator, |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 "type", |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 new String[] {"name"}, |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 new String[] {"describe"})); |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 root.appendChild(createArtNode( |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 creator, |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 "uuid", |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 new String[] {"value"}, |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 new String[] {uuid})); |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 root.appendChild(createArtNode( |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 creator, |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 "hash", |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 new String[] {"value"}, |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 new String[] {hash})); |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 } |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 } |
39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |