Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 335:e964a3d8f7bc
Some Refactoring work done.
Moved Transition to State
gnv-artifacts/trunk@401 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 08 Dec 2009 08:39:03 +0000 |
parents | |
children | 2e43542e6a11 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,143 @@ +/** + * + */ +package de.intevation.gnv.state.profile.horizontalcrosssection; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.Iterator; +import java.util.Locale; + +import org.apache.log4j.Logger; + +import au.com.bytecode.opencsv.CSVWriter; +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.exception.StateException; +import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; +import de.intevation.gnv.statistics.Statistics; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class HorizontalCrossSectionMeshOutputState + extends TimeSeriesOutputState { + + private static Logger log = Logger + .getLogger(HorizontalCrossSectionMeshOutputState.class); + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 3233620652465061860L; + + /** + * Constructor + */ + public HorizontalCrossSectionMeshOutputState() { + super(); + super.domainLable = "Latitude [m]"; + } + + @Override + protected Chart getChart( + ChartLabels chartLables, + Collection parameters, + Collection measurements, + Collection dates, + Collection result, + Locale locale, + String uuid, + boolean linesVisible, + boolean shapesVisible + ) { + Chart chart = null; + + if (CACHE_CHART) { + log.info("Try to get horizontalcrosssection chart from cache."); + chart = (Chart) getChartFromCache(uuid); + } + + if (chart != null) + return chart; + + log.info("Chart not in cache yet."); + + log.warn("This sort of chart is not implemented yet."); + /* TODO Implement a special chart for this sort of charts. + chart = new HorizontalProfileChart( + chartLables, + chartTheme, + parameters, + measurements, + result, + dates, + locale + ); + chart.generateChart(); + + if (CACHE_CHART) { + log.info("Put chart into cache."); + purifyChart(chart, uuid); + } + */ + + return chart; + } + + + /** + * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() + */ + @Override + protected Statistics getStatisticsGenerator() { + return null; //Statistiken werden nicht für diesen Out-Typ unterstützt. + } + + /** + * @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."); + } + } + +}