Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionDescriptionHelper.java @ 2742:faf73245ec73
Improved startup performance.
flys-artifacts/trunk@4476 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 23 May 2012 11:02:50 +0000 |
parents | 0b466bd4ab24 |
children | 4bd3d8bbb60c |
rev | line source |
---|---|
1972
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.collections; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.Date; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 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
|
8 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 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
|
10 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
|
11 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
|
12 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
|
13 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import org.apache.log4j.Logger; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifacts.ArtifactDatabase; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.artifacts.ArtifactDatabaseException; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.artifacts.ArtifactNamespaceContext; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifacts.CallContext; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.artifacts.common.utils.XMLUtils; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 public class CollectionDescriptionHelper { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 private static final Logger logger = |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 Logger.getLogger(CollectionDescriptionHelper.class); |
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 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
|
32 "/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
|
33 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 /** 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
|
35 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
|
36 "/art:result/art:outputmodes"; |
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 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 protected ElementCreator ec; |
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 protected CallContext context; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 protected ArtifactDatabase database; |
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 protected String name; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 protected String uuid; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 protected Date creation; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 protected long ttl; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 |
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
|
49 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
|
50 protected CollectionAttribute attribute; |
1972
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 /** |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 * @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
|
55 * @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
|
56 * @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
|
57 * @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
|
58 */ |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 public CollectionDescriptionHelper( |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 String name, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 String uuid, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 Date creation, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 long ttl, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 CallContext callContext |
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 this.name = name; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 this.uuid = uuid; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 this.creation = creation; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 this.ttl = ttl; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 this.context = callContext; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 this.database = callContext.getDatabase(); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 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
|
76 if (artifacts == null) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 artifacts = new ArrayList<String>(); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 } |
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 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
|
81 artifacts.add(uuid); |
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 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
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
|
86 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
|
87 if (attribute != null) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 this.attribute = attribute; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 |
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 public Document toXML() { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 Document doc = XMLUtils.newDocument(); |
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 ec = new ElementCreator( |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 doc, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 ArtifactNamespaceContext.NAMESPACE_URI, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 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
|
102 doc.appendChild(root); |
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 String creationTime = creation != null |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 ? Long.toString(creation.getTime()) |
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 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
112 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 appendArtifacts(root); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 appendAttribute(root); |
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 return doc; |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 } |
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 |
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 * 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
|
122 * |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 * @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
|
124 */ |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 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
|
126 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
|
127 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 for (String uuid: artifacts) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 try { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 Element e = buildArtifactNode(uuid); |
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 if (e != null) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 artifactsEl.appendChild(e); |
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 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 catch (ArtifactDatabaseException dbe) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 logger.warn(dbe, dbe); |
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 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 root.appendChild(artifactsEl); |
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 /** |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 * 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
|
147 * |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 * @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
|
149 */ |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 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
|
151 throws ArtifactDatabaseException |
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 logger.debug("Append artifact '" + uuid + "' to collection description"); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
154 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
155 // TODO |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 String hash = "MYHASH"; |
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 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
|
159 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
|
160 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
|
161 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
162 // 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
|
163 // 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
|
164 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
|
165 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
166 // Add outputmode element(s). |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
167 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
|
168 description, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
169 XPATH_ARTIFACT_OUTPUTMODES, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 XPathConstants.NODE, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 ArtifactNamespaceContext.INSTANCE); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
172 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 if (outputModes != null) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
174 Document doc = ci.getOwnerDocument(); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 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
|
176 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
177 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
178 // 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
|
179 Node dataNode = ci.appendChild( |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
180 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
|
181 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
182 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
|
183 description, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
184 XPATH_ARTIFACT_STATE_DATA, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 XPathConstants.NODESET, |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 ArtifactNamespaceContext.INSTANCE); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
188 if (dataNodes != null) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
189 Document doc = ci.getOwnerDocument(); |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
190 for (int i = 0; i < dataNodes.getLength(); i++) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
191 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
|
192 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
193 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
195 return ci; |
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 protected void appendAttribute(Element root) { |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
200 Document owner = root.getOwnerDocument(); |
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
|
201 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
|
202 |
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
|
203 root.appendChild(owner.importNode(attr.getFirstChild(), true)); |
1972
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
204 } |
3c3e81fca092
Added a CollectionDescriptionHelper that helps generating DESCRIBE documents for Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
205 } |