comparison flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.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 AttributeParser {
32
33 /** Constant XPath that points to the outputmodes of an artifact.*/
34 public static final String XPATH_ARTIFACT_OUTPUTMODES =
35 "/art:output";
36
37
38 private static Logger logger = Logger.getLogger(AttributeParser.class);
39
40
41 protected Map<String, Output> outs;
42
43
44 public AttributeParser() {
45 this.outs = new HashMap<String, Output>();
46 }
47
48
49 public void parse(Document doc) {
50 logger.debug("AttributeParser.parse");
51
52 NodeList outs = (NodeList) XMLUtils.xpath(
53 doc,
54 XPATH_ARTIFACT_OUTPUTMODES,
55 XPathConstants.NODESET,
56 ArtifactNamespaceContext.INSTANCE);
57
58 int num = outs != null ? outs.getLength() : 0;
59
60 logger.debug("Attribute has " + num + " outputs.");
61
62 for (int i = 0; i < num; i++) {
63 Node out = outs.item(i);
64
65 parseOutput(out);
66 }
67 }
68
69
70 public Map<String, Output> getOuts() {
71 return outs;
72 }
73
74
75 protected void addItem(String out, ManagedFacet item) {
76 Output o = outs.get(out);
77
78 if (o != null) {
79 o.addFacet(item);
80 }
81 }
82
83
84 protected void parseOutput(Node out) {
85 String name = XMLUtils.xpathString(
86 out, "@name", ArtifactNamespaceContext.INSTANCE);
87
88 if (outs.get(name) == null) {
89 logger.debug("Create new output: " + name);
90
91 Output o = new DefaultOutput(name, null, null);
92 outs.put(name, o);
93 }
94
95 parseItems(out, name);
96 }
97
98
99 protected void parseItems(Node out, String outname) {
100 NodeList themes = (NodeList) XMLUtils.xpath(
101 out, "art:theme",
102 XPathConstants.NODESET,
103 ArtifactNamespaceContext.INSTANCE);
104
105 int num = themes != null ? themes.getLength() : 0;
106
107 logger.debug("Output has " + num + " themes.");
108
109 for (int i = 0; i < num; i++) {
110 Node theme = themes.item(i);
111
112 String name = XMLUtils.xpathString(
113 theme, "@facet", ArtifactNamespaceContext.INSTANCE);
114
115 String uuid = XMLUtils.xpathString(
116 theme, "@artifact", ArtifactNamespaceContext.INSTANCE);
117
118 String pos = XMLUtils.xpathString(
119 theme, "@pos", ArtifactNamespaceContext.INSTANCE);
120
121 String active = XMLUtils.xpathString(
122 theme, "@active", ArtifactNamespaceContext.INSTANCE);
123
124 ManagedFacet item = new ManagedFacet(
125 name, "", uuid,
126 Integer.parseInt(pos),
127 Integer.parseInt(active));
128
129 addItem(outname, item);
130 }
131 }
132 }
133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org