comparison 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
comparison
equal deleted inserted replaced
334:e37930705daa 335:e964a3d8f7bc
1 /**
2 *
3 */
4 package de.intevation.gnv.state.profile.horizontalcrosssection;
5
6 import java.io.IOException;
7 import java.io.OutputStream;
8 import java.io.OutputStreamWriter;
9 import java.io.UnsupportedEncodingException;
10 import java.util.Collection;
11 import java.util.Iterator;
12 import java.util.Locale;
13
14 import org.apache.log4j.Logger;
15
16 import au.com.bytecode.opencsv.CSVWriter;
17 import de.intevation.gnv.chart.Chart;
18 import de.intevation.gnv.chart.ChartLabels;
19 import de.intevation.gnv.geobackend.base.Result;
20 import de.intevation.gnv.state.exception.StateException;
21 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState;
22 import de.intevation.gnv.statistics.Statistics;
23
24 /**
25 * @author Tim Englich <tim.englich@intevation.de>
26 *
27 */
28 public class HorizontalCrossSectionMeshOutputState
29 extends TimeSeriesOutputState {
30
31 private static Logger log = Logger
32 .getLogger(HorizontalCrossSectionMeshOutputState.class);
33
34 /**
35 * The UID of this Class
36 */
37 private static final long serialVersionUID = 3233620652465061860L;
38
39 /**
40 * Constructor
41 */
42 public HorizontalCrossSectionMeshOutputState() {
43 super();
44 super.domainLable = "Latitude [m]";
45 }
46
47 @Override
48 protected Chart getChart(
49 ChartLabels chartLables,
50 Collection parameters,
51 Collection measurements,
52 Collection dates,
53 Collection result,
54 Locale locale,
55 String uuid,
56 boolean linesVisible,
57 boolean shapesVisible
58 ) {
59 Chart chart = null;
60
61 if (CACHE_CHART) {
62 log.info("Try to get horizontalcrosssection chart from cache.");
63 chart = (Chart) getChartFromCache(uuid);
64 }
65
66 if (chart != null)
67 return chart;
68
69 log.info("Chart not in cache yet.");
70
71 log.warn("This sort of chart is not implemented yet.");
72 /* TODO Implement a special chart for this sort of charts.
73 chart = new HorizontalProfileChart(
74 chartLables,
75 chartTheme,
76 parameters,
77 measurements,
78 result,
79 dates,
80 locale
81 );
82 chart.generateChart();
83
84 if (CACHE_CHART) {
85 log.info("Put chart into cache.");
86 purifyChart(chart, uuid);
87 }
88 */
89
90 return chart;
91 }
92
93
94 /**
95 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator()
96 */
97 @Override
98 protected Statistics getStatisticsGenerator() {
99 return null; //Statistiken werden nicht für diesen Out-Typ unterstützt.
100 }
101
102 /**
103 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream,
104 * java.util.Collection)
105 */
106 @Override
107 protected void createCSV(OutputStream outputStream,
108 Collection<Result> chartResult)
109 throws UnsupportedEncodingException,
110 IOException,
111 StateException {
112 if (chartResult != null) {
113 try {
114 CSVWriter writer = new CSVWriter(new OutputStreamWriter(
115 outputStream, "ISO-8859-1"), ',');
116 // USE THIS ENCODING BECAUSE OF
117 // PROBLEMS WITH EXCEL AND UTF-8
118 Iterator<Result> it = chartResult.iterator();
119 while (it.hasNext()) {
120 Result result = it.next();
121 int i = 0;
122 String[] entries = new String[5];
123 entries[i++] = result.getString("SHAPE");
124 entries[i++] = result.getString("YORDINATE");
125 entries[i++] = result.getString("IPOSITION");
126 entries[i++] = result.getString("JPOSITION");
127 entries[i++] = result.getString("KPOSITION");
128 writer.writeNext(entries);
129 }
130 writer.close();
131 } catch (Exception e) {
132 log.error(e,e);
133 throw new StateException(
134 "Exception occured while parsing an Point from WKT.");
135 }
136 } else {
137 log.error("No Data given for generating an CSV-File.");
138 throw new StateException(
139 "No Data given for generating an CSV-File.");
140 }
141 }
142
143 }

http://dive4elements.wald.intevation.org