Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultExport.java @ 592:3c939c95c477
Removed accidental checkin of Test-Shapefiles
gnv-artifacts/trunk@647 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 29 Jan 2010 13:28:28 +0000 |
parents | e964a3d8f7bc |
children | f28a7eac542a |
line wrap: on
line source
package de.intevation.gnv.exports; import org.apache.log4j.Logger; import au.com.bytecode.opencsv.CSVWriter; import java.util.Iterator; import java.util.Collection; import java.io.UnsupportedEncodingException; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.OutputStream; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.state.exception.StateException; /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) */ public class DefaultExport implements Export { private static Logger log = Logger.getLogger(DefaultExport.class); private Export.DataCollector collector; public DefaultExport(Export.DataCollector collector) { this.collector = collector; } protected void writeData( Profile profile, Collection result, CSVWriter writer ) throws StateException { log.debug("create content for export."); Iterator<Result> it = result.iterator(); String[] header = profile.getHeader(); if (header != null) writer.writeNext(header); while (it.hasNext()) { Result res = it.next(); writer.writeNext(collector.getData(res)); } } public void create( Profile profile, OutputStream outputStream, Collection result ) throws IOException, UnsupportedEncodingException, StateException { if (result == null) { String msg = "No data given for generation of " + profile.getType() + " file."; log.error(msg); throw new StateException(msg); } CSVWriter writer = new CSVWriter( new OutputStreamWriter( outputStream, profile.getEncoding()), profile.getSeparator(), profile.getQuoteCharacter(), profile.getEscapeCharacter()); writeData(profile, result, writer); writer.close(); } }