diff 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
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java	Tue Dec 13 09:10:48 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java	Tue Dec 13 11:55:47 2011 +0000
@@ -1,7 +1,5 @@
 package de.intevation.flys.collections;
 
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -22,7 +20,6 @@
 
 import de.intevation.artifacts.common.utils.XMLUtils;
 
-import de.intevation.flys.artifacts.model.ManagedFacet;
 import de.intevation.flys.artifacts.model.ManagedDomFacet;
 
 /**
@@ -35,25 +32,27 @@
     public static final String XPATH_ARTIFACT_OUTPUTMODES =
         "/art:attribute/art:outputs/art:output";
 
+
     private static Logger logger = Logger.getLogger(AttributeParser.class);
 
-    protected Map<String, Output> outs;
 
-    /** List of facets. */
-    protected List<Facet> facets;
+    protected Document attributeDocument;
+
+    protected CollectionAttribute attribute;
 
 
-    public AttributeParser() {
-        this.outs   = new HashMap<String, Output>();
-        this.facets = new ArrayList<Facet>();
+    public AttributeParser(Document attributeDocument) {
+        this.attributeDocument = attributeDocument;
     }
 
 
-    public void parse(Document doc) {
+    public void parse() {
         logger.debug("AttributeParser.parse");
 
+        attribute = new CollectionAttribute();
+
         NodeList outs = (NodeList) XMLUtils.xpath(
-            doc,
+            attributeDocument,
             XPATH_ARTIFACT_OUTPUTMODES,
             XPathConstants.NODESET,
             ArtifactNamespaceContext.INSTANCE);
@@ -70,36 +69,22 @@
     }
 
 
-    public Map<String, Output> getOuts() {
-        return outs;
+    public CollectionAttribute getCollectionAttribute() {
+        if (attribute == null) {
+            parse();
+        }
+
+        return attribute;
     }
 
 
-    /**
-     * Adds item (a ManagedFacet) to an out.
-     */
-    protected void addItem(String out, ManagedFacet item) {
-        this.facets.add(item);
-        Output o = outs.get(out);
-
-        if (o != null) {
-            o.addFacet(item);
-        }
+    public Document getAttributeDocument() {
+        return attributeDocument;
     }
 
 
-    protected void parseOutput(Node out) {
-        String name = XMLUtils.xpathString(
-            out, "@name", ArtifactNamespaceContext.INSTANCE);
-
-        if (outs.get(name) == null) {
-            logger.debug("Create new output: " + name);
-
-            Output o = new DefaultOutput(name, null, null);
-            outs.put(name, o);
-        }
-
-        parseItems(out, name);
+    public Map<String, Output> getOuts() {
+        return attribute.getOutputs();
     }
 
 
@@ -108,7 +93,29 @@
      * @return list of all facets.
      */
     public List<Facet> getFacets() {
-        return this.facets;
+        return attribute.getFacets();
+    }
+
+
+    protected void parseOutput(Node out) {
+        String name = XMLUtils.xpathString(
+            out, "@name", ArtifactNamespaceContext.INSTANCE);
+
+        if (name == null || name.length() == 0) {
+            logger.warn("No Output name specified. Cancel parsing!");
+            return;
+        }
+
+        Output o = attribute.getOutput(name);
+
+        if (o == null) {
+            logger.debug("Create new output: " + name);
+
+            o = new DefaultOutput(name, null, null);
+            attribute.addOutput(name, o);
+        }
+
+        parseItems(out, name);
     }
 
 
@@ -127,7 +134,7 @@
         for (int i = 0; i < num; i++) {
             Element theme = (Element) themes.item(i);
 
-            addItem(outname, new ManagedDomFacet(theme));
+            attribute.addFacet(outname, new ManagedDomFacet(theme));
         }
     }
 }

http://dive4elements.wald.intevation.org