Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java @ 230:f68ffbe974a0
Implemented an exporter for odv and csv exports.
gnv-artifacts/trunk@298 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 06 Nov 2009 10:56:18 +0000 |
parents | ee2d4134d0b3 |
children | 3d6d89bcbf42 |
line wrap: on
line source
/** * */ package de.intevation.gnv.transition; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; import org.apache.log4j.Logger; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import de.intevation.artifactdatabase.Config; import de.intevation.artifacts.CallMeta; import de.intevation.gnv.artifacts.cache.CacheFactory; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.transition.exception.TransitionException; /** * @author Tim Englich <tim.englich@intevation.de> * */ public abstract class OutputTransitionBase extends TransitionBase implements OutputTransition { /** * The UID of this Class */ private static final long serialVersionUID = -1718732895737303823L; /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(OutputTransitionBase.class); /** * The different Outputmodes which are provided by an OutputTransition */ protected Collection<OutputMode> outputModes = null; /** * Constructor */ public OutputTransitionBase() { super(); } /** * @see de.intevation.gnv.transition.OutputTransition#getOutputModes() */ public Collection<OutputMode> getOutputModes() { log.debug("OutputTransitionBase.getOutputModes"); return this.outputModes; } /** * @see de.intevation.gnv.transition.TransitionBase#setup(org.w3c.dom.Node) */ @Override public void setup(Node configuration) { log.debug("OutputTransitionBase.setup"); super.setup(configuration); NodeList outputModeList = Config.getNodeSetXPath(configuration, "outputsModes/outputsMode"); if (outputModeList != null) { log.debug(outputModeList.getLength() + " were found."); this.outputModes = new ArrayList<OutputMode>(outputModeList .getLength()); for (int i = 0; i < outputModeList.getLength(); i++) { Element currentNode = (Element)outputModeList.item(i); String name = currentNode.getAttribute("name"); String description =currentNode.getAttribute("description"); String mimeType = currentNode.getAttribute("mime-type"); NodeList inputValuesList = Config.getNodeSetXPath(currentNode, "parameters/inputvalue"); Collection<InputValue> inputParameters = null; if (inputValuesList != null) { inputParameters = new ArrayList<InputValue>(inputValuesList .getLength()); for (int j = 0; j < inputValuesList.getLength(); j++) { Element currentInputValuesNode = (Element)inputValuesList.item(j); String inputValueName = currentInputValuesNode.getAttribute("name"); String inputValueType = currentInputValuesNode.getAttribute("type"); String defaultValue =currentInputValuesNode.getAttribute("value"); boolean isMultiselect = false; InputValue inputValue = new DefaultInputValue( inputValueName, inputValueType, defaultValue, isMultiselect); inputParameters.add(inputValue); } } OutputMode outputMode = new DefaultOutputMode(name, description, mimeType, inputParameters); log.debug(outputMode.toString()); this.outputModes.add(outputMode); } } } /** * @see de.intevation.gnv.transition.TransitionBase#advance() */ @Override public void advance(String uuid, CallMeta callMeta) throws TransitionException { log.debug("OutputTransitionBase.advance"); if (this.getChartResult(uuid) == null) { super.advance(uuid, callMeta); } } /** * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, * java.util.Collection, java.io.OutputStream) */ public void out(String outputMode, Collection<InputData> inputData, OutputStream outputStream) throws TransitionException { } /** * @return */ protected Collection<Result> getChartResult(String uuid) { log.debug("OutputTransitionBase.getChartResult"); if (CacheFactory.getInstance().isInitialized()) { String key = uuid + super.getID(); log.debug("Hash for Queryelements: " + key); net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); if (value != null) { return (Collection<Result>) (value.getObjectValue()); } } return null; } protected void removeChartResult(String uuid) { log.debug("OutputTransitionBase.getChartResult"); if (CacheFactory.getInstance().isInitialized()) { String key = uuid + super.getID(); log.debug("Hash for Queryelements: " + key); net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); if (value != null) { CacheFactory.getInstance().getCache().remove(key); } } } /** * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, * java.lang.String) */ @Override protected void purifyResult(Collection<Result> result, String uuid) { log.debug("OutputTransitionBase.purifyResult"); if (CacheFactory.getInstance().isInitialized()) { String key = uuid + super.getID(); log.debug("Hash for Queryelements: " + key); CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); } } /** * @see de.intevation.gnv.transition.TransitionBase#putInputData(java.util.Collection, java.lang.String) */ @Override public void putInputData(Collection<InputData> inputData, String uuid) throws TransitionException { log.debug("OutputTransitionBase.putInputData"); this.removeChartResult(uuid); super.putInputData(inputData, uuid); } public void out(String outputMode, Collection<InputData> inputData, OutputStream outputStream, String uuid, CallMeta callMeta) throws TransitionException { } }