Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultExport.java @ 1052:b30361464775
The pdf format depends on the chart's aspect ratio (issue290).
gnv-artifacts/trunk@1126 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 26 May 2010 06:45:03 +0000 |
parents | 22c18083225e |
children | f953c9a559d8 |
line wrap: on
line source
package de.intevation.gnv.exports; import au.com.bytecode.opencsv.CSVWriter; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.state.exception.StateException; 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 org.apache.log4j.Logger; /** * This class is the default implementation of {@link Export}. * * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class DefaultExport implements Export { /** * Logger used for logging via log4j. */ private static Logger log = Logger.getLogger(DefaultExport.class); /** * DataCollector used to extract data from <code>Result</code> objects. */ protected Export.DataCollector collector; /** * Constructor * * @param collector See {@link #collector} */ public DefaultExport(Export.DataCollector collector) { this.collector = collector; } /** * This method writes data stored in <code>result</code> into a CSV document * using <code>writer</code>. * * @param profile <code>Profile</code> used to specify the format and columns. * @param result Collection storing the required data. * @param writer CSVWriter to write the csv document. * * @throws StateException */ 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)); } } /** * This method takes a data Collection and writes it to * <code>outputStream</code> using the the format specified by * <code>profile</code>. * * @param profile used to specify the format and columns. * @param outputStream OutputStream which is used for writing the export * document to. * @param result Collection storing the data. * * @throws IOException if writing to OutputStream failed. * @throws UnsupportedEncodingException if the encoding was not accepted. * @throws StateException if result is null. */ 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(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :