Mercurial > dive4elements > framework
diff artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java @ 209:1a3fb29b8b2e
Enhanced the abstract state: the output modes are read now.
artifacts/trunk@1539 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 22 Mar 2011 16:06:35 +0000 |
parents | 2a9591f76270 |
children | 41404961c804 |
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java Mon Mar 21 14:05:45 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java Tue Mar 22 16:06:35 2011 +0000 @@ -7,7 +7,9 @@ */ package de.intevation.artifactdatabase.state; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.xml.xpath.XPathConstants; @@ -15,7 +17,9 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.common.utils.XMLUtils; @@ -39,6 +43,9 @@ * the configuration. */ public static final String XPATH_DESCRIPTION = "@description"; + /** The XPath to the output nodes of the state configuration.*/ + public static final String XPATH_OUTPUT_MODES = "outputmodes/outputmode"; + /** The ID of the state. */ protected String id; @@ -49,8 +56,12 @@ /** The data provided by this state. */ protected Map<String, StateData> data; + /** A list of output modes which are available for this state.*/ + protected List<Output> outputs; + public AbstractState() { + outputs = new ArrayList<Output>(); } @@ -61,8 +72,11 @@ * @param description The description of the state. */ public AbstractState(String id, String description) { + super(); + this.id = id; this.description = description; + } @@ -133,6 +147,17 @@ /** + * Returns the list of possible outputs of this state. The list is empty + * if no output is available for this state. + * + * @return a list of possible outputs of this state. + */ + public List<Output> getOutputs() { + return outputs; + } + + + /** * Initialize the state based on the state node in the configuration. * * @param config The state configuration node. @@ -142,6 +167,55 @@ description = (String) XMLUtils.xpath( config, XPATH_DESCRIPTION, XPathConstants.STRING); + + setupOutputs(config); + } + + + /** + * This method tries reading the available output nodes configured in the + * state configuration and adds possible Outputs to the outputs list. + * + * @param config The state configuration node. + */ + protected void setupOutputs(Node config) { + NodeList outs = (NodeList) XMLUtils.xpath( + config, + XPATH_OUTPUT_MODES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (outs == null || outs.getLength() == 0) { + return; + } + + int size = outs.getLength(); + + for (int i = 0; i < size; i++) { + outputs.add(buildOutput(outs.item(i))); + } + } + + + /** + * A helper method that creates an Output object based on the <i>out</i> + * node. + * + * @param out The output node configuration. + * + * @return an Output object. + */ + protected Output buildOutput(Node out) { + String name = XMLUtils.xpathString( + out, "@name", ArtifactNamespaceContext.INSTANCE); + + String desc = XMLUtils.xpathString( + out, "@description", ArtifactNamespaceContext.INSTANCE); + + String mimetype = XMLUtils.xpathString( + out, "@mime-type", ArtifactNamespaceContext.INSTANCE); + + return name != null ? new DefaultOutput(name, desc, mimetype) : null; }