annotate artifacts/src/main/java/org/dive4elements/river/collections/CollectionDescriptionHelper.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
9 package org.dive4elements.river.collections;
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import java.util.ArrayList;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import java.util.Date;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import java.util.List;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import javax.xml.xpath.XPathConstants;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
17 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
18 import org.apache.logging.log4j.LogManager;
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import org.w3c.dom.Document;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import org.w3c.dom.Element;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import org.w3c.dom.Node;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import org.w3c.dom.NodeList;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
24 import org.dive4elements.artifacts.ArtifactDatabase;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
25 import org.dive4elements.artifacts.ArtifactDatabaseException;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
26 import org.dive4elements.artifacts.ArtifactNamespaceContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
27 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
28 import org.dive4elements.artifacts.common.utils.XMLUtils;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
29 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 public class CollectionDescriptionHelper {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
34 private static final Logger log =
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
35 LogManager.getLogger(CollectionDescriptionHelper.class);
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 public static final String XPATH_ARTIFACT_STATE_DATA =
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 "/art:result/art:ui/art:static/art:state/art:data";
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 /** Constant XPath that points to the outputmodes of an artifact. */
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 public static final String XPATH_ARTIFACT_OUTPUTMODES =
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 "/art:result/art:outputmodes";
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 protected ElementCreator ec;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 protected CallContext context;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 protected ArtifactDatabase database;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 protected String name;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 protected String uuid;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 protected Date creation;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 protected long ttl;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1972
diff changeset
56 protected List<String> artifacts;
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1972
diff changeset
57 protected CollectionAttribute attribute;
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 /**
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 * @param name The name of the collection.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 * @param uuid The uuid of the collection.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 * @param creation The creation time of the collection.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 * @param ttl The time to live of the collection.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 */
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 public CollectionDescriptionHelper(
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 String name,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 String uuid,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 Date creation,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 long ttl,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 CallContext callContext
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 ) {
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
73 this.name = name;
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
74 this.uuid = uuid;
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
75 this.creation = creation;
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
76 this.ttl = ttl;
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
77 this.context = callContext;
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
78 this.database = callContext.getDatabase();
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
79 this.artifacts = new ArrayList<String>();
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 public void addArtifact(String uuid) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 if (uuid != null && uuid.length() > 0) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 artifacts.add(uuid);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1972
diff changeset
90 public void setAttribute(CollectionAttribute attribute) {
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 if (attribute != null) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 this.attribute = attribute;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 public Document toXML() {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 Document doc = XMLUtils.newDocument();
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 ec = new ElementCreator(
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 doc,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 ArtifactNamespaceContext.NAMESPACE_URI,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 ArtifactNamespaceContext.NAMESPACE_PREFIX);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 Element root = ec.create("artifact-collection");
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 doc.appendChild(root);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 String creationTime = creation != null
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 ? Long.toString(creation.getTime())
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 : "";
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 ec.addAttr(root, "name", name, true);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 ec.addAttr(root, "uuid", uuid, true);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 ec.addAttr(root, "creation", creationTime, true);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 ec.addAttr(root, "ttl", String.valueOf(ttl), true);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 appendArtifacts(root);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 appendAttribute(root);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 return doc;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 /**
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 * Appends parts of the DESCRIBE document of each Artifact to <i>root</i>.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 *
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 * @param root The root node.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 */
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 protected void appendArtifacts(Element root) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 Element artifactsEl = ec.create("artifacts");
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 for (String uuid: artifacts) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 try {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 Element e = buildArtifactNode(uuid);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 if (e != null) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 artifactsEl.appendChild(e);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 catch (ArtifactDatabaseException dbe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
141 log.warn(dbe, dbe);
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 root.appendChild(artifactsEl);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 /**
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 * Create the Artifacts Node that contains outputmode and statedata.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 *
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 * @param uuid uuid of the artifact.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 */
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 protected Element buildArtifactNode(String uuid)
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 throws ArtifactDatabaseException
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
157 log.debug("Append artifact '" + uuid + "' to collection description");
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 // TODO
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 String hash = "MYHASH";
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 Element ci = ec.create("artifact");
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163 ec.addAttr(ci, "uuid", uuid, true);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 ec.addAttr(ci, "hash", hash, true);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166 // XXX I am not sure if it works well every time with an empty document
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 // in the describe operation of an artifact.
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 Document description = database.describe(uuid, null, context.getMeta());
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 // Add outputmode element(s).
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 Node outputModes = (Node) XMLUtils.xpath(
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 description,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 XPATH_ARTIFACT_OUTPUTMODES,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 XPathConstants.NODE,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 ArtifactNamespaceContext.INSTANCE);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 if (outputModes != null) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 Document doc = ci.getOwnerDocument();
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 ci.appendChild(doc.importNode(outputModes, true));
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 // Add state-data element(s).
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 Node dataNode = ci.appendChild(
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 ci.getOwnerDocument().createElement("art:data-items"));
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 NodeList dataNodes = (NodeList) XMLUtils.xpath(
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 description,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 XPATH_ARTIFACT_STATE_DATA,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 XPathConstants.NODESET,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 ArtifactNamespaceContext.INSTANCE);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 if (dataNodes != null) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 Document doc = ci.getOwnerDocument();
3087
4a76da133144 Removed repeated x.size() calls from for loops.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3083
diff changeset
194 for (int i = 0, D = dataNodes.getLength(); i < D; i++) {
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 dataNode.appendChild(doc.importNode(dataNodes.item(i), true));
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 return ci;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 protected void appendAttribute(Element root) {
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
204 if (attribute != null) {
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
205 Document owner = root.getOwnerDocument();
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
206 Document attr = attribute.toXML();
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
208 root.appendChild(owner.importNode(attr.getFirstChild(), true));
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3087
diff changeset
209 }
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 }
3083
4bd3d8bbb60c Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1976
diff changeset
212 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org