comparison artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCommonExporter.java @ 9151:bb929b444ea5

vergessen
author gernotbelger
date Thu, 14 Jun 2018 16:57:14 +0200
parents
children a4121ec450d6
comparison
equal deleted inserted replaced
9150:23945061daec 9151:bb929b444ea5
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10 package org.dive4elements.river.artifacts.common;
11
12 import java.io.OutputStream;
13
14 import org.apache.log4j.Logger;
15 import org.dive4elements.artifacts.CallContext;
16 import org.dive4elements.river.artifacts.model.CalculationResult;
17 import org.dive4elements.river.exports.AbstractExporter;
18 import org.w3c.dom.Document;
19
20 import au.com.bytecode.opencsv.CSVWriter;
21
22 /**
23 * @author Gernot Belger
24 */
25 public abstract class AbstractCommonExporter<RESULTS extends AbstractCalculationResults> extends AbstractExporter {
26
27 /** The log used in this exporter. */
28 private final Logger log = Logger.getLogger(getClass());
29
30 /** The log used in this exporter. */
31 protected final Logger getLog() {
32 return this.log;
33 }
34
35 private RESULTS results = null;
36
37 private ExportContextPDF helper;
38
39 @Override
40 public void init(final String outName, final Document request, final OutputStream out, final CallContext context) {
41 super.init(outName, request, out, context);
42
43 this.helper = new ExportContextPDF(context); // bleibt so asynchron zu ExportContextCSV - ist so beabsichtigt
44 }
45
46 protected final ExportContextPDF getHelper() {
47 return this.helper;
48 }
49
50 @Override
51 protected final void addData(final Object d) {
52 /* reset */
53 this.results = null;
54
55 if (d instanceof CalculationResult) {
56
57 final Object dat = ((CalculationResult) d).getData();
58 if (dat != null) {
59 @SuppressWarnings("unchecked")
60 final RESULTS result = (RESULTS) dat;
61 this.results = result;
62 }
63 }
64 }
65
66 protected final RESULTS getResults() {
67 return this.results;
68 }
69
70 protected final AbstractCalculationResults getResults2() {
71 return this.results;
72 }
73
74 @Override
75 protected final void writeCSVData(final CSVWriter writer) {
76 doWriteCSVData(writer, this.results);
77 }
78
79 protected abstract void doWriteCSVData(CSVWriter writer, RESULTS results);
80
81 /**
82 * Formats header with unit and label: msg [unit] (label)
83 */
84 // TODO: REMOVE, because it has moved to ExportContextCSV
85 protected final String msgUnitLabel(final String key, final String unit, final String label) {
86 final String msg = msg(key);
87 return String.format("%s [%s] (%s)", msg, unit, label);
88 }
89
90 @Override
91 protected final void writePDF(final OutputStream out) {
92 doWritePdf(out, this.results);
93 }
94
95 protected abstract void doWritePdf(OutputStream out, RESULTS results);
96 }

http://dive4elements.wald.intevation.org