Mercurial > dive4elements > gnv-client
changeset 480:211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
well fitting TimeSeriesOutputState.
gnv-artifacts/trunk@552 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 17 Jan 2010 12:22:56 +0000 |
parents | d47b478e662b |
children | 20dde2b6f1b5 |
files | gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml gnv-artifacts/src/main/java/de/intevation/gnv/math/AttributedPoint2ds.java gnv-artifacts/src/main/java/de/intevation/gnv/math/AttributedXYColumns.java gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/FileUtils.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java |
diffstat | 10 files changed, 497 insertions(+), 285 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Fri Jan 15 20:39:30 2010 +0000 +++ b/gnv-artifacts/ChangeLog Sun Jan 17 12:22:56 2010 +0000 @@ -1,3 +1,39 @@ +2010-01-17 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * doc/conf/products/horizontalcrosssection/conf_mesh.xml: + Only offer WMS layers and download ZIPs in output state. + + * src/main/java/de/intevation/gnv/utils/FileUtils.java: + New. Helper class to recursively delete files and directories + and create ZIP archives from files and directories. + + * src/main/java/de/intevation/gnv/utils/WKTUtils.java: Simpilied + signature of worldEnvelopeCoordinatesToIndex(). + + * src/main/java/de/intevation/gnv/state/OutputState.java: Cleanup + imports. Made source more readable. + + * src/main/java/de/intevation/gnv/state/OutputStateBase.java: + Cleanup imports. Made source more readable. Moved some + XPath stuff from TimeSeriesOutputState up into this base class. + + * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java: + Move some XPath stuff into base class. Made source more readable. + + * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java: + Directly inherit from OutputStateBase now to break the implicit + constraints (chart styles, statisctics, etc.) of the + TimeSeriesOutputStates which not hold for this kind of state. + XXX: Added Workaround to circumvent gnv-intern/issue146 + + * src/main/java/de/intevation/gnv/math/AttributedXYColumns.java: Added + e-mail addresses for authors. Made querying for attributes more + robust. + + * src/main/java/de/intevation/gnv/math/AttributedPoint2ds.java: + New. Data carrier for the "Horizontalschnitte". Used for generation + of results and caching + 2010-01-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java,
--- a/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml Fri Jan 15 20:39:30 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml Sun Jan 17 12:22:56 2010 +0000 @@ -162,16 +162,8 @@ <value-name name="measurement" value="depthid"></value-name> </value-names> <outputsModes> - <outputsMode name="chart" description="Chartrepresentation of the Values" mime-type="image/png"> - <parameters> - <inputvalue name="width" type="Integer" value="600"/> - <inputvalue name="height" type="Integer" value="400"/> - </parameters> - </outputsMode> - <outputsMode name="pdf" description="PDF-Export der Daten" mime-type="application/pdf"/> - <outputsMode name="svg" description="PDF-Export der Daten" mime-type="image/svg+xml"/> - <outputsMode name="csv" description="CSV-Export der Daten" mime-type="text/plain"/> - <outputsMode name="odv" description="ODV-Export der Daten" mime-type="text/plain"/> + <outputsMode name="zip" description="Export als ZIP-Archiv" mime-type="application/zip"/> + <outputsMode name="wms" description="WMS-Layer bereitstellen" mime-type="text/url"/> </outputsModes> </state>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/AttributedPoint2ds.java Sun Jan 17 12:22:56 2010 +0000 @@ -0,0 +1,46 @@ +package de.intevation.gnv.math; + +import java.util.Map; +import java.util.HashMap; +import java.util.List; + +import java.io.Serializable; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public class AttributedPoint2ds +implements Serializable +{ + protected List<? extends Point2d> points; + protected Map attributes; + + public AttributedPoint2ds() { + } + + public AttributedPoint2ds(List<? extends Point2d> points) { + this.points = points; + } + + public Object getAttribute(Object key) { + return attributes != null + ? attributes.get(key) + : null; + } + + public void setAttribute(Object key, Object value) { + if (attributes == null) { + attributes = new HashMap(); + } + attributes.put(key, value); + } + + public List<? extends Point2d> getPoints() { + return points; + } + + public void setPoints(List<? extends Point2d> points) { + this.points = points; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/AttributedXYColumns.java Fri Jan 15 20:39:30 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/AttributedXYColumns.java Sun Jan 17 12:22:56 2010 +0000 @@ -9,8 +9,8 @@ import de.intevation.gnv.jfreechart.PolygonDataset; /** - * @author Ingo Weinzierl - * @author Sascha L. Teichmann + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class AttributedXYColumns implements Serializable @@ -33,14 +33,15 @@ } public Object getAttribute(Object key) { - return attributes.get(key); + return attributes != null + ? attributes.get(key) + : null; } public void setAttribute(Object key, Object value) { if (attributes == null) { attributes = new HashMap(); } - attributes.put(key, value); }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputState.java Fri Jan 15 20:39:30 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputState.java Sun Jan 17 12:22:56 2010 +0000 @@ -3,19 +3,23 @@ */ package de.intevation.gnv.state; +import de.intevation.artifacts.CallContext; + +import de.intevation.gnv.state.exception.StateException; + import java.io.OutputStream; + import java.util.Collection; import org.w3c.dom.Document; -import de.intevation.artifacts.CallContext; -import de.intevation.gnv.state.exception.StateException; - /** - * @author Tim Englich <tim.englich@intevation.de> + * @author Tim Englich (tim.englich@intevation.de) * */ -public interface OutputState extends State { +public interface OutputState +extends State +{ /** * Returns the Rendered Result of an State. @@ -26,11 +30,11 @@ * @throws StateException */ public void out( - Document format, + Document format, Collection<InputData> inputData, - OutputStream outputStream, - String uuid, - CallContext callContext + OutputStream outputStream, + String uuid, + CallContext callContext ) throws StateException; /**
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Fri Jan 15 20:39:30 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Sun Jan 17 12:22:56 2010 +0000 @@ -3,37 +3,50 @@ */ package de.intevation.gnv.state; +import de.intevation.artifactdatabase.Config; + +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; + +import de.intevation.gnv.artifacts.cache.CacheFactory; + +import de.intevation.gnv.artifacts.ressource.RessourceFactory; + +import de.intevation.gnv.geobackend.base.Result; + +import de.intevation.gnv.geobackend.base.query.QueryExecutor; +import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; + +import de.intevation.gnv.geobackend.base.query.exception.QueryException; + +import de.intevation.gnv.state.exception.StateException; + import java.io.OutputStream; + import java.util.ArrayList; import java.util.Collection; import java.util.Locale; +import org.apache.log4j.Logger; -import org.apache.log4j.Logger; import org.w3c.dom.Document; 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.artifacts.CallContext; - -import de.intevation.gnv.artifacts.cache.CacheFactory; -import de.intevation.gnv.artifacts.ressource.RessourceFactory; -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.geobackend.base.query.QueryExecutor; -import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; -import de.intevation.gnv.geobackend.base.query.exception.QueryException; -import de.intevation.gnv.state.exception.StateException; - /** * @author Tim Englich <tim.englich@intevation.de> * */ -public abstract class OutputStateBase extends StateBase implements - OutputState { +public abstract class OutputStateBase +extends StateBase +implements OutputState +{ + public static final String XPATH_OUTPUT_MODE = + "/art:action/art:out/@name"; + + public static final String XPATH_MIME_TYPE = + "/art:action/art:out/art:mime-type/@value"; /** * The UID of this Class @@ -129,9 +142,15 @@ throws StateException { } - public void out(Document format, Collection<InputData> inputData, - OutputStream outputStream, String uuid, CallMeta callMeta) - throws StateException { + public void out( + Document format, + Collection<InputData> inputData, + OutputStream outputStream, + String uuid, + CallMeta callMeta + ) + throws StateException + { } /**
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Fri Jan 15 20:39:30 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Sun Jan 17 12:22:56 2010 +0000 @@ -3,65 +3,59 @@ */ package de.intevation.gnv.state.profile.horizontalcrosssection; -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -import org.apache.log4j.Logger; - -import org.jfree.chart.ChartTheme; - -import org.w3c.dom.Node; - import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Polygon; -import au.com.bytecode.opencsv.CSVWriter; +import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.XMLUtils; + +import de.intevation.artifacts.ArtifactNamespaceContext; +import de.intevation.artifacts.CallContext; import de.intevation.gnv.artifacts.cache.CacheFactory; + import de.intevation.gnv.artifacts.context.GNVArtifactContext; -import de.intevation.gnv.chart.Chart; -import de.intevation.gnv.chart.ChartLabels; - import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.geobackend.base.ResultDescriptor; import de.intevation.gnv.geobackend.base.query.QueryExecutor; import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; + import de.intevation.gnv.geobackend.base.query.exception.QueryException; +import de.intevation.gnv.geobackend.sde.datasources.RasterObject; + +import de.intevation.gnv.math.AttributedPoint2ds; + import de.intevation.gnv.state.InputData; +import de.intevation.gnv.state.OutputStateBase; import de.intevation.gnv.state.exception.StateException; import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; -import de.intevation.gnv.statistics.Statistics; - import de.intevation.gnv.utils.StringUtils; import de.intevation.gnv.utils.WKTUtils; -import de.intevation.artifactdatabase.Config; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; -import de.intevation.artifacts.CallContext; +import java.util.Collection; -import de.intevation.gnv.geobackend.sde.datasources.RasterObject; +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; /** * @author Tim Englich (tim.englich@intevation.de) * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class HorizontalCrossSectionMeshOutputState -extends TimeSeriesOutputState +extends OutputStateBase { private static Logger log = Logger .getLogger(HorizontalCrossSectionMeshOutputState.class); @@ -77,188 +71,165 @@ * Constructor */ public HorizontalCrossSectionMeshOutputState() { - super(); - super.domainLable = "chart.horizontalcrosssection.title.xaxis"; } - @Override - protected Chart getChart( - ChartLabels chartLables, - ChartTheme theme, - Collection parameters, - Collection measurements, - Collection dates, - Object result, - Locale locale, - String uuid, - boolean linesVisible, - boolean shapesVisible, - CallContext callContext - ) { - Chart chart = null; + public void out( + Document format, + Collection<InputData> inputData, + OutputStream outputStream, + String uuid, + CallContext callContext + ) + throws StateException + { + String outputMode = XMLUtils.xpathString( + format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE); - if (CACHE_CHART) { - log.info("Try to get horizontalcrosssection chart from cache."); - chart = (Chart) getChartFromCache(uuid, callContext); + String mimeType = XMLUtils.xpathString( + format, XPATH_MIME_TYPE, ArtifactNamespaceContext.INSTANCE); + + if (outputMode == null || mimeType == null) { + throw new StateException("cannot find outputMode or mime"); } - if (chart != null) - return chart; - - log.info("Chart not in cache yet."); - - log.warn("This sort of chart is not implemented yet."); - - InputData meshPolygon = inputData.get("mesh_polygon"); - String meshPolygonWkt = null; - if (meshPolygon != null){ - meshPolygonWkt = meshPolygon.getValue(); - - } - log.debug("Used Polygon: "+meshPolygonWkt); - - return chart; - } - - /** - * @see de.intevation.gnv.state.OutputStateBase#getChartResult(java.lang.String, de.intevation.artifacts.CallContext) - */ - @Override - protected Object getChartResult(String uuid, CallContext callContext) { - log.debug("HorizontalProfileMeshCrossOutputState.getChartResult"); - Collection<Result> result = null; - 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) { - result = (Collection<Result>) (value.getObjectValue()); - }else{ - - InputData meshPolygon = inputData.get("mesh_polygon"); - InputData meshId = inputData.get("meshid"); - - if (meshPolygon == null) { - log.error("mesh_polygon is not defined"); - throw new IllegalStateException("missing mesh_linestring"); - } - - if (meshId == null) { - log.error("meshid is not defined"); - throw new IllegalStateException("missing meshid"); - } + outputMode = outputMode.toLowerCase(); - Polygon p = WKTUtils.toPolygon(meshPolygon.getValue()); - - if (p == null) { - log.error("no valid polygon"); - throw new IllegalStateException("no valid polygon"); - } - - try { - Envelope env = p.getEnvelopeInternal(); - - Coordinate [] coords = new Coordinate [] { - new Coordinate(env.getMinX(), env.getMinY()), - new Coordinate(env.getMinX(), env.getMaxY()), - new Coordinate(env.getMaxX(), env.getMaxY()), - new Coordinate(env.getMaxX(), env.getMinY()) }; - - String additionWhere = - WKTUtils.worldEnvelopeCoordinatesToIndex( - coords, - result, - meshId.getValue(), - ijkQueryID); + log.debug("---- asking for: " + outputMode); - String[] addedFilterValues = StringUtils.append( - generateFilterValuesFromInputData(), - additionWhere); - - QueryExecutor queryExecutor = QueryExecutorFactory - .getInstance() - .getQueryExecutor(); - - result = process( - Arrays.asList(coords), - numSamples(callContext), - queryExecutor.executeQuery( - queryID, - addedFilterValues), - p); - } - catch (QueryException e) { - log.error(e,e); - } - - if (CacheFactory.getInstance().isInitialized()) { - CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); - } + if ("zip".equals(outputMode)) { + } + else if ("wms".equals(outputMode)) { + } + else if ("statistics".equals(outputMode)) { + // TODO: REMOVE THIS! + try { + outputStream.write("<fake/>\n".getBytes()); + } + catch (IOException ioe) { } } + else { + throw new StateException("unsupported output mode"); + } + } + + protected Object getResult(String uuid, CallContext callContext) + throws StateException + { + CacheFactory cf = CacheFactory.getInstance(); + String key = uuid + super.getID(); + + if (cf.isInitialized()) { + net.sf.ehcache.Element value = cf.getCache().get(key); + if (value != null) { + return value.getObjectValue(); + } + } + + Object result = produceResult(callContext); + + if (result != null && cf.isInitialized()) { + cf.getCache().put(new net.sf.ehcache.Element(key, result)); + } + return result; } - public static Collection<Result> process( - List<Coordinate> path, - int numSamples, - Collection<Result> input, - Polygon polygon - ) { - // TODO: IMPLEMENT ME INTEGRATE POLYGONCLIPPING - return null; + protected Object produceResult(CallContext callContext) + throws StateException + { + InputData meshPolygon = inputData.get("mesh_polygon"); + InputData meshId = inputData.get("meshid"); + + if (meshPolygon == null) { + log.error("mesh_polygon is not defined"); + throw new StateException("missing mesh_linestring"); + } + + if (meshId == null) { + log.error("meshid is not defined"); + throw new StateException("missing meshid"); + } + + Polygon p = WKTUtils.toPolygon(meshPolygon.getValue()); + + if (p == null) { + log.error("no valid polygon"); + throw new StateException("no valid polygon"); + } + + try { + Envelope env = p.getEnvelopeInternal(); + + Coordinate [] coords = new Coordinate [] { + new Coordinate(env.getMinX(), env.getMinY()), + new Coordinate(env.getMinX(), env.getMaxY()), + new Coordinate(env.getMaxX(), env.getMaxY()), + new Coordinate(env.getMaxX(), env.getMinY()) }; + + String additionWhere = + WKTUtils.worldEnvelopeCoordinatesToIndex( + coords, + meshId.getValue(), + ijkQueryID); + + String[] addedFilterValues = StringUtils.append( + generateFilterValuesFromInputData(), + additionWhere); + + QueryExecutor queryExecutor = QueryExecutorFactory + .getInstance() + .getQueryExecutor(); + + return process( + env, + p, + numSamples(callContext), + preprocess( + queryExecutor.executeQuery( + queryID, + addedFilterValues))); + } + catch (QueryException e) { + log.error(e,e); + } + + throw new StateException("no result produced"); } - /** - * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() - */ - @Override - protected Statistics getStatisticsGenerator() { - return null; //Statistics are not supported for this kind of OutputState. + public AttributedPoint2ds preprocess(Collection<Result> results) { + + boolean debug = log.isDebugEnabled(); + + if (debug) { + log.debug("--- preprocess: " + results.size() + " results"); + } + + AttributedPoint2ds ap2ds = new AttributedPoint2ds(); + + boolean first = true; + + for (Result result: results) { + + if (debug && first) { + first = false; + ResultDescriptor rd = result.getResultDescriptor(); + log.debug(rd); + } + } + + return ap2ds; } - /** - * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, - * java.util.Collection) - */ - @Override - protected void createCSV( - OutputStream outputStream, - Collection<Result> chartResult - ) throws UnsupportedEncodingException, IOException, StateException - { - /* - if (chartResult != null) { - try { - CSVWriter writer = new CSVWriter(new OutputStreamWriter( - outputStream, "ISO-8859-1"), ','); - // USE THIS ENCODING BECAUSE OF - // PROBLEMS WITH EXCEL AND UTF-8 - Iterator<Result> it = chartResult.iterator(); - while (it.hasNext()) { - Result result = it.next(); - int i = 0; - String[] entries = new String[5]; - entries[i++] = result.getString("SHAPE"); - entries[i++] = result.getString("YORDINATE"); - entries[i++] = result.getString("IPOSITION"); - entries[i++] = result.getString("JPOSITION"); - entries[i++] = result.getString("KPOSITION"); - writer.writeNext(entries); - } - writer.close(); - } catch (Exception e) { - log.error(e,e); - throw new StateException( - "Exception occured while parsing an Point from WKT."); - } - } else { - log.error("No Data given for generating an CSV-File."); - throw new StateException( - "No Data given for generating an CSV-File."); - } - */ + public Object process( + Envelope env, + Polygon polygon, + int numSamples, + AttributedPoint2ds input + ) { + return input; } + /** * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#setup(org.w3c.dom.Node)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Fri Jan 15 20:39:30 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Sun Jan 17 12:22:56 2010 +0000 @@ -3,11 +3,64 @@ */ package de.intevation.gnv.state.timeseries; -import java.io.IOException; +import au.com.bytecode.opencsv.CSVWriter; + +import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.XMLUtils; + +import de.intevation.artifacts.ArtifactNamespaceContext; +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; +import de.intevation.artifacts.PreferredLocale; + +import de.intevation.gnv.artifacts.context.GNVArtifactContext; + +import de.intevation.gnv.artifacts.ressource.RessourceFactory; + +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.chart.TimeSeriesChart; +import de.intevation.gnv.chart.XMLChartTheme; + +import de.intevation.gnv.chart.exception.TechnicalChartException; + +import de.intevation.gnv.exports.ChartExportHelper; +import de.intevation.gnv.exports.DefaultDataCollector; +import de.intevation.gnv.exports.DefaultExport; +import de.intevation.gnv.exports.DefaultProfile; + +import de.intevation.gnv.exports.Export.Profile; + +import de.intevation.gnv.exports.SimpleOdvDataCollector; + +import de.intevation.gnv.geobackend.base.Result; + +import de.intevation.gnv.state.InputData; +import de.intevation.gnv.state.OutputStateBase; + +import de.intevation.gnv.state.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.NamedCollection; + +import de.intevation.gnv.state.exception.StateException; + +import de.intevation.gnv.statistics.Statistic; +import de.intevation.gnv.statistics.StatisticSet; +import de.intevation.gnv.statistics.Statistics; +import de.intevation.gnv.statistics.TimeseriesStatistics; + +import de.intevation.gnv.statistics.exception.StatisticsException; + +import de.intevation.gnv.timeseries.gap.DefaultTimeGap; +import de.intevation.gnv.timeseries.gap.TimeGap; + +import de.intevation.gnv.utils.ArtifactXMLUtilities; + import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.io.OutputStream; -import java.io.FileOutputStream; import java.io.UnsupportedEncodingException; + import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -20,52 +73,20 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; + import javax.xml.transform.dom.DOMSource; + import javax.xml.transform.stream.StreamResult; import org.apache.log4j.Logger; + +import org.jfree.chart.ChartTheme; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.jfree.chart.ChartTheme; - -import au.com.bytecode.opencsv.CSVWriter; -import de.intevation.artifactdatabase.Config; -import de.intevation.artifactdatabase.XMLUtils; -import de.intevation.artifacts.ArtifactNamespaceContext; -import de.intevation.artifacts.CallMeta; -import de.intevation.artifacts.CallContext; -import de.intevation.artifacts.PreferredLocale; -import de.intevation.gnv.artifacts.context.GNVArtifactContext; -import de.intevation.gnv.artifacts.ressource.RessourceFactory; -import de.intevation.gnv.chart.Chart; -import de.intevation.gnv.chart.ChartLabels; -import de.intevation.gnv.chart.TimeSeriesChart; -import de.intevation.gnv.chart.XMLChartTheme; -import de.intevation.gnv.chart.exception.TechnicalChartException; -import de.intevation.gnv.exports.ChartExportHelper; -import de.intevation.gnv.exports.DefaultExport; -import de.intevation.gnv.exports.DefaultDataCollector; -import de.intevation.gnv.exports.SimpleOdvDataCollector; -import de.intevation.gnv.exports.DefaultProfile; -import de.intevation.gnv.exports.Export.Profile; -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.state.InputData; -import de.intevation.gnv.state.OutputStateBase; -import de.intevation.gnv.state.describedata.KeyValueDescibeData; -import de.intevation.gnv.state.describedata.NamedCollection; -import de.intevation.gnv.state.exception.StateException; -import de.intevation.gnv.statistics.Statistic; -import de.intevation.gnv.statistics.StatisticSet; -import de.intevation.gnv.statistics.Statistics; -import de.intevation.gnv.statistics.TimeseriesStatistics; -import de.intevation.gnv.statistics.exception.StatisticsException; -import de.intevation.gnv.timeseries.gap.DefaultTimeGap; -import de.intevation.gnv.timeseries.gap.TimeGap; -import de.intevation.gnv.utils.ArtifactXMLUtilities; - /** * @author Tim Englich <tim.englich@intevation.de> @@ -73,12 +94,6 @@ */ public class TimeSeriesOutputState extends OutputStateBase { - public static final String XPATH_OUTPUT_MODE = - "/art:action/art:out/@name"; - - public static final String XPATH_MIME_TYPE = - "/art:action/art:out/art:mime-type/@value"; - protected static final boolean CACHE_CHART = Boolean.parseBoolean(System.getProperty("cache.chart", "false")); @@ -186,11 +201,11 @@ * de.intevation.artifacts.CallMeta) */ public void out( - Document format, + Document format, Collection<InputData> inputData, - OutputStream outputStream, - String uuid, - CallContext callContext + OutputStream outputStream, + String uuid, + CallContext callContext ) throws StateException { log.debug("TimeSeriesOutputTransition.out");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/FileUtils.java Sun Jan 17 12:22:56 2010 +0000 @@ -0,0 +1,129 @@ +package de.intevation.gnv.utils; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import java.util.Stack; + +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public final class FileUtils +{ + private FileUtils() { + } + + public final static boolean deleteRecursive(File file) { + + if (file == null) { + return false; + } + + if (file.isDirectory()) { + File [] files = file.listFiles(); + if (files != null) { + for (File sub: files) { + if (!deleteRecursive(sub)) { + return false; + } + } + } + } + + return file.delete(); + } + + public static void createZipArchive( + File file, + OutputStream outputStream + ) + throws IOException + { + ZipOutputStream out = new ZipOutputStream(outputStream); + + if (file.isFile()) { + copyFileToZip("", file, out); + } + else if (file.isDirectory()) { + + Stack<PrefixDir> stack = new Stack<PrefixDir>(); + stack.push(new PrefixDir(file.getName() + "/", file)); + + while (!stack.isEmpty()) { + PrefixDir pd = stack.pop(); + + ZipEntry dirEntry = new ZipEntry(pd.prefix); + out.putNextEntry(dirEntry); + out.closeEntry(); + + File [] files = pd.dir.listFiles(); + if (files != null) { + for (File sub: files) { + if (sub.isDirectory()) { + stack.push(new PrefixDir( + pd.prefix + sub.getName() + "/", + sub)); + } + else if (sub.isFile()) { + copyFileToZip(pd.prefix, sub, out); + } + } + } + } + } + + out.finish(); + } + + private static final class PrefixDir { + + String prefix; + File dir; + + public PrefixDir(String prefix, File dir) { + this.prefix = prefix; + this.dir = dir; + } + + } // class PrefixDir + + private static void copyFileToZip( + String prefix, + File file, + ZipOutputStream out + ) + throws IOException + { + String entryName = prefix + file.getName(); + ZipEntry entry = new ZipEntry(entryName); + out.putNextEntry(entry); + InputStream in = null; + try { + in = + new BufferedInputStream( + new FileInputStream(file), 20*1024); + + byte [] buf = new byte[2048]; + + int r; + while ((r = in.read(buf)) > 0) { + out.write(buf, 0, r); + } + } + finally { + if (in != null) { + try { in.close(); } + catch (IOException ioe) {} + } + } + out.closeEntry(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java Fri Jan 15 20:39:30 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java Sun Jan 17 12:22:56 2010 +0000 @@ -138,7 +138,6 @@ public static String worldEnvelopeCoordinatesToIndex( Coordinate [] coords, - Collection<Result> result, String meshid, String ijkQueryID )