Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java @ 3017:296b067e17e6
i18n and format for line labels.
flys-artifacts/trunk@4582 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 05 Jun 2012 12:35:49 +0000 |
parents | a2b265b9b2f7 |
children | ce796f1db30e |
line wrap: on
line source
package de.intevation.flys.exports; import au.com.bytecode.opencsv.CSVWriter; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.CallMeta; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.fixings.DeltaWT; import de.intevation.flys.artifacts.model.fixings.DeltaWTsKM; import de.intevation.flys.artifacts.model.fixings.FixResult; import de.intevation.flys.artifacts.resources.Resources; import de.intevation.flys.utils.Formatter; import java.io.IOException; import java.io.OutputStream; import java.text.DateFormat; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; import org.apache.log4j.Logger; import org.w3c.dom.Document; public class DeltaWtExporter extends AbstractExporter { private static Logger log = Logger.getLogger(DeltaWtExporter.class); public static final String CSV_KM_HEADER = "export.fixings.deltawt.csv.header.km"; public static final String CSV_DELTA_W_HEADER = "export.fixings.deltawt.csv.header.deltaw"; public static final String CSV_T_HEADER = "export.fixings.deltawt.csv.header.t"; public static final String CSV_T_DESC_HEADER = "export.fixings.deltawt.csv.header.description"; public static final String DEFAULT_CSV_KM_HEADER = "km"; public static final String DEFAULT_CSV_DELTA_W_HEADER = "\u0394 W [cm]"; public static final String DEFAULT_CSV_T_HEADER = "Datum"; public static final String DEFAULT_CSV_T_DESC_HEADER = "Beschreibung"; protected List<DeltaWTsKM> deltaWTsKMs; @Override public void init(Document request, OutputStream out, CallContext context) { log.debug("DeltaWtExporter.init"); super.init(request, out, context); deltaWTsKMs = new ArrayList<DeltaWTsKM>(); } @Override public void generate() throws IOException { log.debug("DeltaWtExporter.generate"); if (facet == null) { throw new IOException("invalid (null) facet for exporter"); } else if (facet.equals(FACET_CSV)) { generateCSV(); } else if (facet.equals(FACET_PDF)) { generatePDF(); } else { throw new IOException("invalid facet (" + facet + ") for exporter"); } } @Override protected void addData(Object d) { log.debug("DeltaWtExporter.addData"); if (!(d instanceof CalculationResult)) { log.warn("Invalid data type"); return; } Object data = ((CalculationResult)d).getData(); if (!(data instanceof FixResult)) { log.warn("Invalid data stored in result."); } FixResult result = (FixResult)data; deltaWTsKMs.add(result.getDeltaWTsKM()); } @Override protected void writeCSVData(CSVWriter writer) throws IOException { boolean debug = log.isDebugEnabled(); writeCSVHeader(writer); NumberFormat kmF = getKMFormatter(); NumberFormat dwF = getDeltaWFormatter(); CallMeta meta = context.getMeta(); Locale locale = Resources.getLocale(meta); DateFormat dF = DateFormat.getDateInstance(DateFormat.SHORT, locale); if (debug) { log.debug("DeltaWTsKMs: " + deltaWTsKMs.size()); } for (DeltaWTsKM deltaWTsKM: deltaWTsKMs) { List<DeltaWTsKM.KM> dkms = deltaWTsKM.getKms(); if (debug) { log.debug("DeltaWTsKM.KM: " + dkms.size()); } for (DeltaWTsKM.KM dkm: dkms) { double km = dkm.getKm(); String kmS = kmF.format(km); List<DeltaWT> deltaWTs = dkm.getDeltaWTs(); if (debug) { log.debug("deltaWTs: " + deltaWTs.size()); } for (DeltaWT dwt: deltaWTs) { double deltaW = dwt.getDeltaW(); Date date = dwt.getDate(); String desc = dwt.getDescription(); String deltaWS = dwF.format(deltaW); String dateS = dF.format(date); writer.writeNext(new String[] { kmS, deltaWS, dateS, desc != null ? desc : "" }); } } } writer.flush(); } protected NumberFormat getKMFormatter() { return Formatter.getFixDeltaWKM(context); } protected NumberFormat getDeltaWFormatter() { return Formatter.getFixDeltaWDeltaW(context); } protected void writeCSVHeader(CSVWriter writer) { log.debug("DeltaWtExporter.writeCSVHeader"); writer.writeNext(new String[] { msg(CSV_KM_HEADER, DEFAULT_CSV_KM_HEADER), msg(CSV_DELTA_W_HEADER, DEFAULT_CSV_DELTA_W_HEADER), msg(CSV_T_HEADER, DEFAULT_CSV_T_HEADER), msg(CSV_T_DESC_HEADER, DEFAULT_CSV_T_DESC_HEADER) }); } @Override protected void writePDF(OutputStream out) { // TODO: Implement me! } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :