Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java @ 346:16161de47662
The Attributes of a collection are written into its DESCRIBE now.
flys-artifacts/trunk@1748 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 26 Apr 2011 13:29:18 +0000 |
parents | |
children | 6167ae622ce0 |
comparison
equal
deleted
inserted
replaced
345:88a669785863 | 346:16161de47662 |
---|---|
1 package de.intevation.flys.collections; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.HashMap; | |
5 import java.util.List; | |
6 import java.util.Map; | |
7 | |
8 import javax.xml.xpath.XPathConstants; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 | |
12 import org.w3c.dom.Document; | |
13 import org.w3c.dom.Element; | |
14 import org.w3c.dom.Node; | |
15 import org.w3c.dom.NodeList; | |
16 | |
17 import de.intevation.artifacts.ArtifactDatabase; | |
18 import de.intevation.artifacts.ArtifactDatabaseException; | |
19 import de.intevation.artifacts.ArtifactNamespaceContext; | |
20 import de.intevation.artifacts.CallMeta; | |
21 | |
22 import de.intevation.artifactdatabase.state.DefaultOutput; | |
23 import de.intevation.artifactdatabase.state.Facet; | |
24 import de.intevation.artifactdatabase.state.Output; | |
25 | |
26 import de.intevation.artifacts.common.utils.XMLUtils; | |
27 | |
28 import de.intevation.flys.artifacts.model.ManagedFacet; | |
29 | |
30 | |
31 public class OutputParser { | |
32 | |
33 /** Constant XPath that points to the outputmodes of an artifact.*/ | |
34 public static final String XPATH_ARTIFACT_OUTPUTMODES = | |
35 "/art:result/art:outputmodes/art:output"; | |
36 | |
37 | |
38 private static Logger logger = Logger.getLogger(OutputParser.class); | |
39 | |
40 protected ArtifactDatabase db; | |
41 protected CallMeta meta; | |
42 | |
43 protected Map<String, Output> outs; | |
44 | |
45 | |
46 public OutputParser(ArtifactDatabase db, CallMeta meta) { | |
47 this.db = db; | |
48 this.meta = meta; | |
49 this.outs = new HashMap<String, Output>(); | |
50 } | |
51 | |
52 | |
53 public void parse(String uuid) | |
54 throws ArtifactDatabaseException | |
55 { | |
56 logger.debug("OutputParser.parse: " + uuid); | |
57 | |
58 // XXX I am not sure if it works well every time with an empty | |
59 // document in the describe operation of an artifact. | |
60 Document description = db.describe(uuid, null, meta); | |
61 | |
62 NodeList outs = (NodeList) XMLUtils.xpath( | |
63 description, | |
64 XPATH_ARTIFACT_OUTPUTMODES, | |
65 XPathConstants.NODESET, | |
66 ArtifactNamespaceContext.INSTANCE); | |
67 | |
68 int num = outs != null ? outs.getLength() : 0; | |
69 | |
70 logger.debug("Artifact has " + num + " outputs."); | |
71 | |
72 for (int i = 0; i < num; i++) { | |
73 Node out = outs.item(i); | |
74 | |
75 parseOutput(uuid, out); | |
76 } | |
77 } | |
78 | |
79 | |
80 public Map<String, Output> getOuts() { | |
81 return outs; | |
82 } | |
83 | |
84 | |
85 protected void addItem(String out, ManagedFacet item) { | |
86 Output o = outs.get(out); | |
87 | |
88 if (o != null) { | |
89 int num = o.getFacets().size(); | |
90 item.setPosition(num+1); | |
91 | |
92 o.addFacet(item); | |
93 } | |
94 } | |
95 | |
96 | |
97 protected void parseOutput(String uuid, Node out) { | |
98 String name = XMLUtils.xpathString( | |
99 out, "@art:name", ArtifactNamespaceContext.INSTANCE); | |
100 | |
101 if (outs.get(name) == null) { | |
102 logger.debug("Create new output: " + name); | |
103 newOutput(out, name); | |
104 } | |
105 | |
106 parseItems(uuid, out, name); | |
107 } | |
108 | |
109 | |
110 protected void newOutput(Node out, String name) { | |
111 String desc = XMLUtils.xpathString( | |
112 out, "@art:description", ArtifactNamespaceContext.INSTANCE); | |
113 | |
114 String mimetype = XMLUtils.xpathString( | |
115 out, "@art:mime-type", ArtifactNamespaceContext.INSTANCE); | |
116 | |
117 Output o = new DefaultOutput(name, desc, mimetype); | |
118 | |
119 outs.put(name, o); | |
120 } | |
121 | |
122 | |
123 protected void parseItems(String uuid, Node out, String outname) { | |
124 NodeList facets = (NodeList) XMLUtils.xpath( | |
125 out, "art:facets/art:facet", | |
126 XPathConstants.NODESET, | |
127 ArtifactNamespaceContext.INSTANCE); | |
128 | |
129 int num = facets != null ? facets.getLength() : 0; | |
130 | |
131 logger.debug("Output has " + num + " facets."); | |
132 | |
133 for (int i = 0; i < num; i++) { | |
134 Node facet = facets.item(i); | |
135 | |
136 String name = XMLUtils.xpathString( | |
137 facet, "@art:name", ArtifactNamespaceContext.INSTANCE); | |
138 | |
139 ManagedFacet item = new ManagedFacet(name, null, uuid, 1, 1); | |
140 | |
141 addItem(outname, item); | |
142 } | |
143 } | |
144 } | |
145 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |