annotate artifacts/src/main/java/org/dive4elements/river/collections/CollectionDescriptionHelper.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents af13ceeba52a
children 0a5239a1e46e
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
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
17 import org.apache.log4j.Logger;
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 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
19 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
20 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
21 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
22
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
23 import org.dive4elements.artifacts.ArtifactDatabase;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
24 import org.dive4elements.artifacts.ArtifactDatabaseException;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
25 import org.dive4elements.artifacts.ArtifactNamespaceContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
26 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
27 import org.dive4elements.artifacts.common.utils.XMLUtils;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3785
diff changeset
28 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
29
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 public class CollectionDescriptionHelper {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
33 private static final Logger log =
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 Logger.getLogger(CollectionDescriptionHelper.class);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35
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 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
38 "/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
39
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 /** 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
41 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
42 "/art:result/art:outputmodes";
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43
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 protected ElementCreator ec;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 protected CallContext context;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 protected ArtifactDatabase database;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 protected String name;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 protected String uuid;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 protected Date creation;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 protected long ttl;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54
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
55 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
56 protected CollectionAttribute attribute;
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57
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 * @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
61 * @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
62 * @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
63 * @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
64 */
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 public CollectionDescriptionHelper(
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 String name,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 String uuid,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 Date creation,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 long ttl,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 CallContext callContext
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 ) {
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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 }
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 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
83 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
84 artifacts.add(uuid);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 }
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
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
89 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
90 if (attribute != null) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 this.attribute = attribute;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 }
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 public Document toXML() {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 Document doc = XMLUtils.newDocument();
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 ec = new ElementCreator(
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 doc,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 ArtifactNamespaceContext.NAMESPACE_URI,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 ArtifactNamespaceContext.NAMESPACE_PREFIX);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 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
105 doc.appendChild(root);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 String creationTime = creation != null
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 ? Long.toString(creation.getTime())
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 : "";
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 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
112 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
113 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
114 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
115
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 appendArtifacts(root);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 appendAttribute(root);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 return doc;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 }
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 * 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
125 *
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 * @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
127 */
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 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
129 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
130
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 for (String uuid: artifacts) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 try {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 Element e = buildArtifactNode(uuid);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 if (e != null) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 artifactsEl.appendChild(e);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 }
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 catch (ArtifactDatabaseException dbe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
140 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
141 }
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 root.appendChild(artifactsEl);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 }
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 * 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
150 *
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 * @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
152 */
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 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
154 throws ArtifactDatabaseException
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
156 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
157
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 // TODO
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 String hash = "MYHASH";
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 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
162 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
163 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
164
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 // 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
166 // 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
167 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
168
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 // Add outputmode element(s).
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 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
171 description,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 XPATH_ARTIFACT_OUTPUTMODES,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 XPathConstants.NODE,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 ArtifactNamespaceContext.INSTANCE);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 if (outputModes != null) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 Document doc = ci.getOwnerDocument();
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 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
179 }
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 // 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
182 Node dataNode = ci.appendChild(
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 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
184
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 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
186 description,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 XPATH_ARTIFACT_STATE_DATA,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 XPathConstants.NODESET,
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 ArtifactNamespaceContext.INSTANCE);
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 if (dataNodes != null) {
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 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
193 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
194 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
195 }
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 return ci;
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 }
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 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
203 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
204 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
205 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
206
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
207 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
208 }
1972
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 }
3c3e81fca092 Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210 }
3083
4bd3d8bbb60c Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1976
diff changeset
211 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org