Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java @ 1976:0b466bd4ab24
Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
flys-artifacts/trunk@3400 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 13 Dec 2011 11:55:47 +0000 |
parents | 2fe270661b20 |
children | 3e703d134bbe |
comparison
equal
deleted
inserted
replaced
1975:b30e1710df1d | 1976:0b466bd4ab24 |
---|---|
1 package de.intevation.flys.collections; | 1 package de.intevation.flys.collections; |
2 | 2 |
3 import java.util.ArrayList; | |
4 import java.util.HashMap; | |
5 import java.util.List; | 3 import java.util.List; |
6 import java.util.Map; | 4 import java.util.Map; |
7 | 5 |
8 import javax.xml.xpath.XPathConstants; | 6 import javax.xml.xpath.XPathConstants; |
9 | 7 |
20 import de.intevation.artifactdatabase.state.Facet; | 18 import de.intevation.artifactdatabase.state.Facet; |
21 import de.intevation.artifactdatabase.state.Output; | 19 import de.intevation.artifactdatabase.state.Output; |
22 | 20 |
23 import de.intevation.artifacts.common.utils.XMLUtils; | 21 import de.intevation.artifacts.common.utils.XMLUtils; |
24 | 22 |
25 import de.intevation.flys.artifacts.model.ManagedFacet; | |
26 import de.intevation.flys.artifacts.model.ManagedDomFacet; | 23 import de.intevation.flys.artifacts.model.ManagedDomFacet; |
27 | 24 |
28 /** | 25 /** |
29 * Access parts of the Attribute parts of a FLYSCollections description | 26 * Access parts of the Attribute parts of a FLYSCollections description |
30 * document. | 27 * document. |
33 | 30 |
34 /** Constant XPath that points to the outputmodes of an artifact. */ | 31 /** Constant XPath that points to the outputmodes of an artifact. */ |
35 public static final String XPATH_ARTIFACT_OUTPUTMODES = | 32 public static final String XPATH_ARTIFACT_OUTPUTMODES = |
36 "/art:attribute/art:outputs/art:output"; | 33 "/art:attribute/art:outputs/art:output"; |
37 | 34 |
35 | |
38 private static Logger logger = Logger.getLogger(AttributeParser.class); | 36 private static Logger logger = Logger.getLogger(AttributeParser.class); |
39 | 37 |
40 protected Map<String, Output> outs; | |
41 | 38 |
42 /** List of facets. */ | 39 protected Document attributeDocument; |
43 protected List<Facet> facets; | 40 |
41 protected CollectionAttribute attribute; | |
44 | 42 |
45 | 43 |
46 public AttributeParser() { | 44 public AttributeParser(Document attributeDocument) { |
47 this.outs = new HashMap<String, Output>(); | 45 this.attributeDocument = attributeDocument; |
48 this.facets = new ArrayList<Facet>(); | |
49 } | 46 } |
50 | 47 |
51 | 48 |
52 public void parse(Document doc) { | 49 public void parse() { |
53 logger.debug("AttributeParser.parse"); | 50 logger.debug("AttributeParser.parse"); |
54 | 51 |
52 attribute = new CollectionAttribute(); | |
53 | |
55 NodeList outs = (NodeList) XMLUtils.xpath( | 54 NodeList outs = (NodeList) XMLUtils.xpath( |
56 doc, | 55 attributeDocument, |
57 XPATH_ARTIFACT_OUTPUTMODES, | 56 XPATH_ARTIFACT_OUTPUTMODES, |
58 XPathConstants.NODESET, | 57 XPathConstants.NODESET, |
59 ArtifactNamespaceContext.INSTANCE); | 58 ArtifactNamespaceContext.INSTANCE); |
60 | 59 |
61 int num = outs != null ? outs.getLength() : 0; | 60 int num = outs != null ? outs.getLength() : 0; |
68 parseOutput(out); | 67 parseOutput(out); |
69 } | 68 } |
70 } | 69 } |
71 | 70 |
72 | 71 |
73 public Map<String, Output> getOuts() { | 72 public CollectionAttribute getCollectionAttribute() { |
74 return outs; | 73 if (attribute == null) { |
74 parse(); | |
75 } | |
76 | |
77 return attribute; | |
75 } | 78 } |
76 | 79 |
77 | 80 |
78 /** | 81 public Document getAttributeDocument() { |
79 * Adds item (a ManagedFacet) to an out. | 82 return attributeDocument; |
80 */ | |
81 protected void addItem(String out, ManagedFacet item) { | |
82 this.facets.add(item); | |
83 Output o = outs.get(out); | |
84 | |
85 if (o != null) { | |
86 o.addFacet(item); | |
87 } | |
88 } | 83 } |
89 | 84 |
90 | 85 |
91 protected void parseOutput(Node out) { | 86 public Map<String, Output> getOuts() { |
92 String name = XMLUtils.xpathString( | 87 return attribute.getOutputs(); |
93 out, "@name", ArtifactNamespaceContext.INSTANCE); | |
94 | |
95 if (outs.get(name) == null) { | |
96 logger.debug("Create new output: " + name); | |
97 | |
98 Output o = new DefaultOutput(name, null, null); | |
99 outs.put(name, o); | |
100 } | |
101 | |
102 parseItems(out, name); | |
103 } | 88 } |
104 | 89 |
105 | 90 |
106 /** | 91 /** |
107 * Access all facets. | 92 * Access all facets. |
108 * @return list of all facets. | 93 * @return list of all facets. |
109 */ | 94 */ |
110 public List<Facet> getFacets() { | 95 public List<Facet> getFacets() { |
111 return this.facets; | 96 return attribute.getFacets(); |
97 } | |
98 | |
99 | |
100 protected void parseOutput(Node out) { | |
101 String name = XMLUtils.xpathString( | |
102 out, "@name", ArtifactNamespaceContext.INSTANCE); | |
103 | |
104 if (name == null || name.length() == 0) { | |
105 logger.warn("No Output name specified. Cancel parsing!"); | |
106 return; | |
107 } | |
108 | |
109 Output o = attribute.getOutput(name); | |
110 | |
111 if (o == null) { | |
112 logger.debug("Create new output: " + name); | |
113 | |
114 o = new DefaultOutput(name, null, null); | |
115 attribute.addOutput(name, o); | |
116 } | |
117 | |
118 parseItems(out, name); | |
112 } | 119 } |
113 | 120 |
114 | 121 |
115 protected void parseItems(Node out, String outname) { | 122 protected void parseItems(Node out, String outname) { |
116 NodeList themes = (NodeList) XMLUtils.xpath( | 123 NodeList themes = (NodeList) XMLUtils.xpath( |
125 String uri = ArtifactNamespaceContext.NAMESPACE_URI; | 132 String uri = ArtifactNamespaceContext.NAMESPACE_URI; |
126 | 133 |
127 for (int i = 0; i < num; i++) { | 134 for (int i = 0; i < num; i++) { |
128 Element theme = (Element) themes.item(i); | 135 Element theme = (Element) themes.item(i); |
129 | 136 |
130 addItem(outname, new ManagedDomFacet(theme)); | 137 attribute.addFacet(outname, new ManagedDomFacet(theme)); |
131 } | 138 } |
132 } | 139 } |
133 } | 140 } |
134 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 141 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |