comparison flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java @ 430:7ab81ff32111 2.3

merged flys-artifacts/2.3
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:10 +0200
parents 6167ae622ce0
children 9c565eb46f06
comparison
equal deleted inserted replaced
290:a6f56ed9238b 430:7ab81ff32111
1 package de.intevation.flys.collections;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.xml.xpath.XPathConstants;
7
8 import org.apache.log4j.Logger;
9
10 import org.w3c.dom.Document;
11 import org.w3c.dom.Node;
12 import org.w3c.dom.NodeList;
13
14 import de.intevation.artifacts.ArtifactNamespaceContext;
15
16 import de.intevation.artifactdatabase.state.DefaultOutput;
17 import de.intevation.artifactdatabase.state.Output;
18
19 import de.intevation.artifacts.common.utils.XMLUtils;
20
21 import de.intevation.flys.artifacts.model.ManagedFacet;
22
23
24 public class AttributeParser {
25
26 /** Constant XPath that points to the outputmodes of an artifact.*/
27 public static final String XPATH_ARTIFACT_OUTPUTMODES =
28 "/art:output";
29
30
31 private static Logger logger = Logger.getLogger(AttributeParser.class);
32
33
34 protected Map<String, Output> outs;
35
36
37 public AttributeParser() {
38 this.outs = new HashMap<String, Output>();
39 }
40
41
42 public void parse(Document doc) {
43 logger.debug("AttributeParser.parse");
44
45 NodeList outs = (NodeList) XMLUtils.xpath(
46 doc,
47 XPATH_ARTIFACT_OUTPUTMODES,
48 XPathConstants.NODESET,
49 ArtifactNamespaceContext.INSTANCE);
50
51 int num = outs != null ? outs.getLength() : 0;
52
53 logger.debug("Attribute has " + num + " outputs.");
54
55 for (int i = 0; i < num; i++) {
56 Node out = outs.item(i);
57
58 parseOutput(out);
59 }
60 }
61
62
63 public Map<String, Output> getOuts() {
64 return outs;
65 }
66
67
68 protected void addItem(String out, ManagedFacet item) {
69 Output o = outs.get(out);
70
71 if (o != null) {
72 o.addFacet(item);
73 }
74 }
75
76
77 protected void parseOutput(Node out) {
78 String name = XMLUtils.xpathString(
79 out, "@name", ArtifactNamespaceContext.INSTANCE);
80
81 if (outs.get(name) == null) {
82 logger.debug("Create new output: " + name);
83
84 Output o = new DefaultOutput(name, null, null);
85 outs.put(name, o);
86 }
87
88 parseItems(out, name);
89 }
90
91
92 protected void parseItems(Node out, String outname) {
93 NodeList themes = (NodeList) XMLUtils.xpath(
94 out, "art:theme",
95 XPathConstants.NODESET,
96 ArtifactNamespaceContext.INSTANCE);
97
98 int num = themes != null ? themes.getLength() : 0;
99
100 logger.debug("Output has " + num + " themes.");
101
102 for (int i = 0; i < num; i++) {
103 Node theme = themes.item(i);
104
105 String name = XMLUtils.xpathString(
106 theme, "@facet", ArtifactNamespaceContext.INSTANCE);
107
108 String uuid = XMLUtils.xpathString(
109 theme, "@artifact", ArtifactNamespaceContext.INSTANCE);
110
111 String pos = XMLUtils.xpathString(
112 theme, "@pos", ArtifactNamespaceContext.INSTANCE);
113
114 String active = XMLUtils.xpathString(
115 theme, "@active", ArtifactNamespaceContext.INSTANCE);
116
117 ManagedFacet item = new ManagedFacet(
118 name, "", uuid,
119 Integer.parseInt(pos),
120 Integer.parseInt(active));
121
122 addItem(outname, item);
123 }
124 }
125 }
126 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org