Mercurial > dive4elements > framework
changeset 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 | 8ea4d0824d8f |
children | b75fca1ac215 |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultOutput.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/Output.java |
diffstat | 4 files changed, 176 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Mar 21 14:05:45 2011 +0000 +++ b/ChangeLog Tue Mar 22 16:06:35 2011 +0000 @@ -1,3 +1,14 @@ +2011-03-22 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultOutput.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/state/Output.java: + New. An interface and its default implementation to describe an output + mode of a state. Currently, the information 'name', 'description' and + 'mime-type' are provided. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java: + The abstract state reads the output modes available for the state now. + 2011-03-21 Ingo Weinzierl <ingo@intevation.de> * artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java:
--- 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; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultOutput.java Tue Mar 22 16:06:35 2011 +0000 @@ -0,0 +1,61 @@ +package de.intevation.artifactdatabase.state; + + +/** + * The default implementation of an Output. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultOutput implements Output { + + protected String name; + + protected String description; + + protected String mimeType; + + + /** + * The default constructor that instantiates a new DefaultOutput object. + * + * @param name The name of this output. + * @param description The description of this output. + * @param mimeType The mimetype of this output. + */ + public DefaultOutput(String name, String description, String mimeType) { + this.name = name; + this.description = description; + this.mimeType = mimeType; + } + + + /** + * Returns the name of this output. + * + * @return the name of this output. + */ + public String getName() { + return name; + } + + + /** + * Returns the description of this output. + * + * @return the description of this output. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the mimetype of this output. + * + * @return the mimetype of this output. + */ + public String getMimeType() { + return mimeType; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/Output.java Tue Mar 22 16:06:35 2011 +0000 @@ -0,0 +1,30 @@ +package de.intevation.artifactdatabase.state; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface Output { + + /** + * Retrieve the name of this output mode. + * + * @return the name of this output mode. + */ + public String getName(); + + /** + * Retrieve the description of an output. + * + * @return the description. + */ + public String getDescription(); + + /** + * Retrieve the mimetype used for the output. + * + * @return the mimetype. + */ + public String getMimeType(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :