Mercurial > dive4elements > gnv-client
changeset 234:a7fa7b404897
HorizontalProfile CSV-export uses an Exporter instead of writing csv on its own.
gnv-artifacts/trunk@302 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 09 Nov 2009 09:52:18 +0000 |
parents | 2ceb4bf51cba |
children | c8ecc0c0bcb4 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/exports/HorizontalProfileDataCollector.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java |
diffstat | 3 files changed, 97 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Nov 09 09:43:52 2009 +0000 +++ b/gnv-artifacts/ChangeLog Mon Nov 09 09:52:18 2009 +0000 @@ -1,3 +1,12 @@ +2009-11-09 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/exports/HorizontalProfileDataCollector.java: + Special DataCollector for fetching data used for horizontal profile + exports. + + * src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java: + Uses the an exporter for csv export. + 2009-11-09 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/java/de/intevation/gnv/exports/Export.java,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/HorizontalProfileDataCollector.java Mon Nov 09 09:52:18 2009 +0000 @@ -0,0 +1,60 @@ +package de.intevation.gnv.exports; + +import java.util.List; +import java.util.ArrayList; + +import org.apache.log4j.Logger; + +import com.vividsolutions.jts.io.WKTReader; +import com.vividsolutions.jts.io.ParseException; +import com.vividsolutions.jts.geom.Point; + +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.transition.exception.TransitionException; + + +/** + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + */ +public class HorizontalProfileDataCollector +extends DefaultDataCollector +{ + private Logger log = Logger.getLogger(HorizontalProfileDataCollector.class); + + protected WKTReader wktReader = new WKTReader(); + + public HorizontalProfileDataCollector(String[] names) { + super(names); + } + + public String[] getData(Result result) + throws TransitionException { + + if (rd == null) + init(result); + + try { + String [] entries = new String[names.length+1]; + int j = 0; + for (int i = 0; i < names.length; i++) { + + if (names[i].equals("SHAPE")) { + Point p = (Point)wktReader.read(result.getString("SHAPE")); + + entries[j++] = ""+p.getX(); + entries[j++] = ""+p.getY(); + } + else { + entries[j++] = result.getString(names[i]); + } + } + + return entries; + } + catch (ParseException pe) { + log.error(pe, pe); + throw new TransitionException( + "Error occured while parsing a Point from WKT."); + } + } +}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java Mon Nov 09 09:43:52 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java Mon Nov 09 09:52:18 2009 +0000 @@ -29,6 +29,11 @@ import de.intevation.gnv.transition.exception.TransitionException; import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; +import de.intevation.gnv.exports.DefaultExport; +import de.intevation.gnv.exports.HorizontalProfileDataCollector; +import de.intevation.gnv.exports.DefaultProfile; +import de.intevation.gnv.exports.Export.Profile; + /** * @author Tim Englich <tim.englich@intevation.de> * @@ -42,6 +47,23 @@ private static Logger log = Logger .getLogger(HorizontalProfileOutputTransition.class); + + public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { + "SHAPE", + "YORDINATE", + "GROUP1", + "GROUP2", + "GROUP3" + }; + + public static final Profile TIMESERIES_CSV_PROFILE = + new DefaultProfile( + ',', + '"', + '"', + "CSV", + "ISO-8859-1"); + /** * Constructor */ @@ -84,38 +106,12 @@ IOException, TransitionException { - 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(); - WKTReader wktReader = new WKTReader(); - while (it.hasNext()) { - Result result = it.next(); - int i = 0; - String[] entries = new String[6]; - Point p = (Point)wktReader.read(result.getString("SHAPE")); - entries[i++] = ""+p.getX(); - entries[i++] = ""+p.getY(); - entries[i++] = result.getString("YORDINATE"); - entries[i++] = result.getString("GROUP1"); - entries[i++] = result.getString("GROUP2"); - entries[i++] = result.getString("GROUP3"); - writer.writeNext(entries); - } - writer.close(); - } catch (ParseException e) { - log.error(e,e); - throw new TransitionException( - "Exception occured while parsing an Point from WKT."); - } - } else { - log.error("No Data given for generation an CSV-File."); - throw new TransitionException( - "No Data given for generation an CSV-File."); - } + log.debug("createCSV for HorizontalProfileOutputTransition."); + DefaultExport export = new DefaultExport( + new HorizontalProfileDataCollector(TIMESERIES_CSV_PROFILE_NAMES)); + + export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); + }