# HG changeset patch # User Felix Wolfsteller # Date 1319792928 0 # Node ID 2fe270661b207a9a2ebaedf530c38ec533c40165 # Parent 5a1d59926a7291ec7ce2a9414fd4a54645406e33 Let Output and Attribute Parsers collect Facets during processing. flys-artifacts/trunk@3101 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 5a1d59926a72 -r 2fe270661b20 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Oct 28 09:02:48 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Oct 28 09:08:48 2011 +0000 @@ -1,3 +1,12 @@ +2011-10-28 Felix Wolfsteller + + Let OutputParser and AttributeParser collect all facets on the way. + + * src/main/java/de/intevation/flys/collections/OutputParser.java, + src/main/java/de/intevation/flys/collections/AttributeParser.java: + Collect all facets while iterating over Outputs and Attributes, + documentation added. + 2011-10-28 Felix Wolfsteller Extracted getFlysContext from FLYSArtifacts into FLYSUtils. diff -r 5a1d59926a72 -r 2fe270661b20 flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java --- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java Fri Oct 28 09:02:48 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java Fri Oct 28 09:08:48 2011 +0000 @@ -1,6 +1,8 @@ package de.intevation.flys.collections; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.xml.xpath.XPathConstants; @@ -15,6 +17,7 @@ import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifactdatabase.state.DefaultOutput; +import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifactdatabase.state.Output; import de.intevation.artifacts.common.utils.XMLUtils; @@ -22,22 +25,27 @@ import de.intevation.flys.artifacts.model.ManagedFacet; import de.intevation.flys.artifacts.model.ManagedDomFacet; - +/** + * Access parts of the Attribute parts of a FLYSCollections description + * document. + */ public class AttributeParser { /** Constant XPath that points to the outputmodes of an artifact. */ public static final String XPATH_ARTIFACT_OUTPUTMODES = "/art:attribute/art:outputs/art:output"; - private static Logger logger = Logger.getLogger(AttributeParser.class); - protected Map outs; + /** List of facets. */ + protected List facets; + public AttributeParser() { - this.outs = new HashMap(); + this.outs = new HashMap(); + this.facets = new ArrayList(); } @@ -67,7 +75,11 @@ } + /** + * 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) { @@ -91,6 +103,15 @@ } + /** + * Access all facets. + * @return list of all facets. + */ + public List getFacets() { + return this.facets; + } + + protected void parseItems(Node out, String outname) { NodeList themes = (NodeList) XMLUtils.xpath( out, "art:facet", diff -r 5a1d59926a72 -r 2fe270661b20 flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java --- a/flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java Fri Oct 28 09:02:48 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java Fri Oct 28 09:08:48 2011 +0000 @@ -32,8 +32,12 @@ protected CallMeta meta; protected CallContext context; + /** Map outputs name to Output. */ protected Map outs; + /** Map facets name to list of Facets. */ + protected List facets; + /** * @param db Database used to fetch artifacts, outputs and facets. @@ -43,11 +47,12 @@ this.meta = context.getMeta(); this.context = context; this.outs = new HashMap(); + this.facets = new ArrayList(); } /** - * Gets raw facet with given id and sorts outputs in mapping. + * Gets raw artifact with given id and sorts outputs in mapping. * Converts Facets to ManagedFacets on the way. * @param uuid uuid of artifact to load from database. */ @@ -80,8 +85,9 @@ pos = o.getFacets().size() + 1; } - List facets = facet2ManagedFacet(uuid, out.getFacets(), pos); - o.addFacets(facets); + List mfacets = facet2ManagedFacet(uuid, out.getFacets(), pos); + o.addFacets(mfacets); + this.facets.addAll(mfacets); } } @@ -94,6 +100,19 @@ } + /** + * Access all facets. + */ + public List getFacets() { + return this.facets; + } + + + /** + * Creates a list of ManagedFacets from list of Facets. + * @param pos Position of first facet (for each other the positions + * will be increased). + */ protected List facet2ManagedFacet( String uuid, List old,