annotate artifacts/src/main/java/org/dive4elements/river/exports/AbstractExporter.java @ 9150:23945061daec

gigantic refactoring: exporter, result, results to support multiple jaspers -> collisions
author gernotbelger
date Thu, 14 Jun 2018 16:56:31 +0200
parents 93ea282c33e8
children 13a0c4be17ea
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5133
diff changeset
9 package org.dive4elements.river.exports;
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import java.io.IOException;
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import java.io.OutputStream;
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import java.io.OutputStreamWriter;
2284
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
14 import java.text.NumberFormat;
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
15
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
18 import org.dive4elements.artifactdatabase.state.Settings;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5133
diff changeset
19 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5133
diff changeset
20 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5133
diff changeset
21 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5133
diff changeset
22 import org.dive4elements.artifacts.common.utils.XMLUtils;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5133
diff changeset
23 import org.dive4elements.river.artifacts.resources.Resources;
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
24 import org.dive4elements.river.collections.D4EArtifactCollection;
6905
1b35b2ddfc28 Artifacts: Introduce ThemeDocument & make stuff compileable again. THIS BREAKS THE SYSTEM! TODO: Move ThemeUtils into ThemeDocument.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
25 import org.dive4elements.river.themes.ThemeDocument;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5133
diff changeset
26 import org.dive4elements.river.utils.Formatter;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
27 import org.w3c.dom.Document;
2284
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
28
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
29 import au.com.bytecode.opencsv.CSVWriter;
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 /**
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
32 * Abstract exporter that implements some basic methods for exporting data of
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 * artifacts.
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 *
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 */
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 public abstract class AbstractExporter implements OutGenerator {
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
39 /** The log used in this exporter. */
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
40 private static Logger log = Logger.getLogger(AbstractExporter.class);
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
3223
282c9da923ab FixA: flys/issue689: Export CSV for facet 'fix_parameters'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
42 /* XXX: Why does AbstractExporter do not implement FacetTypes? */
282c9da923ab FixA: flys/issue689: Export CSV for facet 'fix_parameters'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
43 public static String FIX_PARAMETERS = "fix_parameters";
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
45 /** The name of the CSV facet which triggers the CSV creation. */
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 public static final String FACET_CSV = "csv";
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
2176
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
48 /** The name of the PDF facet which triggers the PDF creation. */
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
49 public static final String FACET_PDF = "pdf";
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
50
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
51 /** The default charset for the CSV export. */
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 public static final String DEFAULT_CSV_CHARSET = "UTF-8";
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
54 /** The default separator for the CSV export. */
7035
e61bb712ee41 issue971: Change CSV column separator to ";" for Exports, client-side change follows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6905
diff changeset
55 public static final char DEFAULT_CSV_SEPARATOR = ';';
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
7937
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
57 public static final String START_META_CHAR = "#";
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
58
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
59 /** XPath that points to the desired export facet. */
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
60 public static final String XPATH_FACET = "/art:action/@art:type";
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
61
7077
0a337f0005c2 Extended init() of OutGenerator to take name of the out to serve.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7037
diff changeset
62 /** The out name to serve. */
0a337f0005c2 Extended init() of OutGenerator to take name of the out to serve.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7037
diff changeset
63 protected String outName;
0a337f0005c2 Extended init() of OutGenerator to take name of the out to serve.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7037
diff changeset
64
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
65 /** The document of the incoming out() request. */
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 protected Document request;
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
68 /** The output stream where the data should be written to. */
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 protected OutputStream out;
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
71 /** The CallContext object. */
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 protected CallContext context;
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
74 /** The selected facet. */
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 protected String facet;
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
77 /** The collection. */
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
78 protected D4EArtifactCollection collection;
3422
118fe1cc8cc8 OutGenerators got a setCollection() method; analogous to setMasterArtifact(). Registered the SQOverviewGenerator as OutGenerator for 'sq_overview' Output.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3270
diff changeset
79
1160
efe1b8545f5c Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 710
diff changeset
80 /** The master artifact. */
412
046bd86ae41d Improved the OutGenerator interface to set a master artifact for the out generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 391
diff changeset
81 protected Artifact master;
046bd86ae41d Improved the OutGenerator interface to set a master artifact for the out generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 391
diff changeset
82
5111
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
83 private NumberFormat kmFormat;
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
84
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
85 private NumberFormat wFormat;
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
86
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
87 private NumberFormat qFormat;
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
88
8862
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
89 private NumberFormat meanBedHeightFormat;
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
90
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
91 private NumberFormat tkhFormat;
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
92
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
93 private NumberFormat flowDepthFormat;
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
94
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
95 private NumberFormat w2Format;
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 /**
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 * Concrete subclasses need to use this method to write their special data
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 * objects into the CSV document.
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 *
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
101 * @param writer
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
102 * The CSVWriter.
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 */
2792
fe987587ebc9 Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2284
diff changeset
104 protected abstract void writeCSVData(CSVWriter writer) throws IOException;
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 /**
7937
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
107 * Write lines of informative content to CSV file.
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
108 * Usually this will be done above the column headers from within
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
109 * the implementation of writeCSVData in concret subclasses.
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
110 *
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
111 * @param writer
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
112 * The CSVWriter
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
113 * @param infolines
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
114 * Array of Strings with informative content.
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
115 * Each will be written to a separate line prefixed with START_META_CHAR.
7937
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
116 */
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
117 protected void writeCSVInfo(final CSVWriter writer, final String[] infolines) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
118 final String[] metaline = new String[1];
7937
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
119
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
120 for (final String infoline : infolines) {
7937
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
121 metaline[0] = START_META_CHAR + " " + infoline;
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
122 writer.writeNext(metaline);
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
123 }
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
124
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
125 }
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
126
a310b1f85ce0 issue1633: Add info lines in SQ-relation CSV export.
Tom Gottfried <tom@intevation.de>
parents: 7936
diff changeset
127 /**
2176
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
128 * Concrete subclasses need to use this method to write their special data
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
129 * objects into the PDF document.
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
130 */
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
131 protected abstract void writePDF(OutputStream out);
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
132
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
133 /**
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 * This method enables concrete subclasses to collected its own special
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 * data.
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 *
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
137 * @param data
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
138 * The artifact that stores the data that has to be
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
139 * exported.
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 */
701
dad1a2c88f9f Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 695
diff changeset
141 protected abstract void addData(Object data);
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
143 @Override
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
144 public void setup(final Object config) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
145 log.debug("AbstractExporter.setup");
7037
5c6fd2c010dd Add setup(Element config) method to Generator interface to be initialized from configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6905
diff changeset
146 }
5c6fd2c010dd Add setup(Element config) method to Generator interface to be initialized from configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6905
diff changeset
147
710
cded0924193d Added generator and facet for error reports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 701
diff changeset
148 @Override
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
149 public void init(final String outName, final Document request, final OutputStream out, final CallContext context) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
150 log.debug("AbstractExporter.init");
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151
7077
0a337f0005c2 Extended init() of OutGenerator to take name of the out to serve.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7037
diff changeset
152 this.outName = outName;
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 this.request = request;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
154 this.out = out;
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 this.context = context;
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 }
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157
710
cded0924193d Added generator and facet for error reports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 701
diff changeset
158 @Override
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
159 public void setMasterArtifact(final Artifact master) {
412
046bd86ae41d Improved the OutGenerator interface to set a master artifact for the out generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 391
diff changeset
160 this.master = master;
046bd86ae41d Improved the OutGenerator interface to set a master artifact for the out generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 391
diff changeset
161 }
046bd86ae41d Improved the OutGenerator interface to set a master artifact for the out generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 391
diff changeset
162
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
163 /**
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
164 * Get the callcontext that this exporter has been initialized
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
165 * with.
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
166 */
5102
baf51f820838 AbstractExporter: Added getter for CallContext.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4910
diff changeset
167 public CallContext getCallContext() {
baf51f820838 AbstractExporter: Added getter for CallContext.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4910
diff changeset
168 return this.context;
baf51f820838 AbstractExporter: Added getter for CallContext.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4910
diff changeset
169 }
baf51f820838 AbstractExporter: Added getter for CallContext.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4910
diff changeset
170
3422
118fe1cc8cc8 OutGenerators got a setCollection() method; analogous to setMasterArtifact(). Registered the SQOverviewGenerator as OutGenerator for 'sq_overview' Output.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3270
diff changeset
171 @Override
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
172 public void setCollection(final D4EArtifactCollection collection) {
3422
118fe1cc8cc8 OutGenerators got a setCollection() method; analogous to setMasterArtifact(). Registered the SQOverviewGenerator as OutGenerator for 'sq_overview' Output.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3270
diff changeset
173 this.collection = collection;
118fe1cc8cc8 OutGenerators got a setCollection() method; analogous to setMasterArtifact(). Registered the SQOverviewGenerator as OutGenerator for 'sq_overview' Output.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3270
diff changeset
174 }
118fe1cc8cc8 OutGenerators got a setCollection() method; analogous to setMasterArtifact(). Registered the SQOverviewGenerator as OutGenerator for 'sq_overview' Output.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3270
diff changeset
175
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 /**
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 * This doOut() just collects the data of multiple artifacts. Therefore, it
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 * makes use of the addData() method which enables concrete subclasses to
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 * store its data on its own. The real output creation takes place in the
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 * concrete generate() methods.
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 *
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
182 * @param artifactFacet
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
183 * The artifact and facet.
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
184 * The facet to add - NOTE: the facet needs to fit to the first
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
185 * facet inserted into this exporter. Otherwise this artifact/facet is
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
186 * skipped.
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
187 * @param attr
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
188 * The attr document.
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 */
710
cded0924193d Added generator and facet for error reports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 701
diff changeset
190 @Override
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
191 public void doOut(final ArtifactAndFacet artifactFacet, final ThemeDocument attr, final boolean visible) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
192 final String name = artifactFacet.getFacetName();
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
194 log.debug("AbstractExporter.doOut: " + name);
695
45cd58a2a2bb OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 445
diff changeset
195
45cd58a2a2bb OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 445
diff changeset
196 if (!isFacetValid(name)) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
197 log.warn("Facet '" + name + "' not valid. No output created!");
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 return;
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 }
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
201 addData(artifactFacet.getData(this.context));
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 }
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 /**
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 * Generates an export based on a specified facet.
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 */
710
cded0924193d Added generator and facet for error reports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 701
diff changeset
207 @Override
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
208 public void generate() throws IOException {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
209 log.debug("AbstractExporter.generate");
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
211 if (this.facet == null) {
3217
79dd823733e2 FixA: Added parameter exporter.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2792
diff changeset
212 throw new IOException("invalid (null) facet for exporter");
79dd823733e2 FixA: Added parameter exporter.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2792
diff changeset
213 }
79dd823733e2 FixA: Added parameter exporter.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2792
diff changeset
214
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
215 if (this.facet.equals(FACET_CSV)) {
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 generateCSV();
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
217 } else if (this.facet.equals(FACET_PDF)) {
2176
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
218 generatePDF();
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
219 } else {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
220 throw new IOException("invalid facet for exporter: '" + this.facet + "'");
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 }
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 }
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 /**
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225 * Determines if the desired facet is valid for this exporter. If no facet
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 * is currently set, <i>facet</i> is set.
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 *
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
228 * @param facet
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
229 * The desired facet.
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 *
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
231 * @return true, if <i>facet</i> is valid, otherwise false.
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 */
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
233 protected boolean isFacetValid(final String facet) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
234 log.debug("AbstractExporter.isFacetValid : " + facet + " (" + getFacet() + ")");
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
236 final String thisFacet = getFacet();
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
237
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
238 if (thisFacet == null || thisFacet.length() == 0) {
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
239 return false;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
240 } else if (facet == null || facet.length() == 0) {
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
241 return false;
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
242 } else {
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
243 return thisFacet.equals(facet);
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
244 }
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
245 }
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
246
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
247 /**
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
248 * Returns the name of the desired facet.
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
249 *
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
250 * @return the name of the desired facet.
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
251 */
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
252 protected String getFacet() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
253 if (this.facet == null) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
254 this.facet = getFacetFromRequest();
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
255 }
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
256
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
257 return this.facet;
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
258 }
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
259
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
260 /**
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
261 * Extracts the name of the requested facet from request document.
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
262 *
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
263 * @return the name of the requested facet.
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
264 */
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
265 protected String getFacetFromRequest() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
266 return XMLUtils.xpathString(this.request, XPATH_FACET, ArtifactNamespaceContext.INSTANCE);
445
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
267 }
a7947972fdeb Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 418
diff changeset
268
8862
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
269 protected String msg(final String key) {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
270 return Resources.getMsg(this.context.getMeta(), key, key);
7936
5ef60ed15c25 So you do not need to type every string twice.
Tom Gottfried <tom@intevation.de>
parents: 7116
diff changeset
271 }
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 412
diff changeset
272
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
273 protected String msg(final String key, final String def) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
274 return Resources.getMsg(this.context.getMeta(), key, def);
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 412
diff changeset
275 }
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 412
diff changeset
276
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
277 protected String msg(final String key, final Object[] args) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
278 return Resources.getMsg(this.context.getMeta(), key, key, args);
8179
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 7937
diff changeset
279 }
705f8b92fd66 Complete CSV-export and correct headers.
Tom Gottfried <tom@intevation.de>
parents: 7937
diff changeset
280
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
281 protected String msg(final String key, final String def, final Object[] args) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
282 return Resources.getMsg(this.context.getMeta(), key, def, args);
5133
8e52b4829cd1 Fix flys/issue1228: Units in tabular calculation output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5111
diff changeset
283 }
8936
93ea282c33e8 Fixed: introducing the varargs method did brerak some old behaviour, distinguish with method name
gernotbelger
parents: 8928
diff changeset
284
93ea282c33e8 Fixed: introducing the varargs method did brerak some old behaviour, distinguish with method name
gernotbelger
parents: 8928
diff changeset
285 protected String msgVarg(final String key, final Object... args) {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
286 return Resources.getMsg(this.context.getMeta(), key, key, args);
8936
93ea282c33e8 Fixed: introducing the varargs method did brerak some old behaviour, distinguish with method name
gernotbelger
parents: 8928
diff changeset
287 }
93ea282c33e8 Fixed: introducing the varargs method did brerak some old behaviour, distinguish with method name
gernotbelger
parents: 8928
diff changeset
288
8928
791714b92b5c Basically implemented SINFO-Tkh Exports
gernotbelger
parents: 8862
diff changeset
289 /**
791714b92b5c Basically implemented SINFO-Tkh Exports
gernotbelger
parents: 8862
diff changeset
290 * Formats header with unit: msg [unit]
791714b92b5c Basically implemented SINFO-Tkh Exports
gernotbelger
parents: 8862
diff changeset
291 */
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
292 // TODO: REMOVE, because it has moved to ExportContextCSV
8928
791714b92b5c Basically implemented SINFO-Tkh Exports
gernotbelger
parents: 8862
diff changeset
293 protected final String msgUnit(final String key, final String unit) {
791714b92b5c Basically implemented SINFO-Tkh Exports
gernotbelger
parents: 8862
diff changeset
294 final String msg = msg(key);
791714b92b5c Basically implemented SINFO-Tkh Exports
gernotbelger
parents: 8862
diff changeset
295 return String.format("%s [%s]", msg, unit);
791714b92b5c Basically implemented SINFO-Tkh Exports
gernotbelger
parents: 8862
diff changeset
296 }
416
340dc41a7ea3 The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 412
diff changeset
297
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
298 /**
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
299 * This method starts CSV creation. It makes use of writeCSVData() which has
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
300 * to be implemented by concrete subclasses.
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
301 */
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
302 protected void generateCSV() throws IOException {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
303 log.info("AbstractExporter.generateCSV");
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
304
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
305 final char quote = '"';
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
306 final char escape = '\\';
4910
a707ef048188 Insert CR and LF at the end of each line in CSV exports.
Raimund Renkert <rrenkert@intevation.de>
parents: 3422
diff changeset
307
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
308 final CSVWriter writer = new CSVWriter(new OutputStreamWriter(this.out, DEFAULT_CSV_CHARSET), DEFAULT_CSV_SEPARATOR, quote, escape, "\r\n");
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
309
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
310 writeCSVData(writer);
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
311
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
312 writer.close();
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
313 }
1979
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
314
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
315 /**
2176
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
316 * This method starts PDF creation.
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
317 */
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
318 protected void generatePDF() throws IOException {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8179
diff changeset
319 log.info("AbstractExporter.generatePDF");
2176
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
320 writePDF(this.out);
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
321 }
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
322
65dac9cf6ff5 Issue 138.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2047
diff changeset
323 /**
1979
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
324 * Returns an instance of <i>EmptySettings</i> currently!
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
325 *
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
326 * @return an instance of <i>EmptySettings</i>.
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
327 */
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
328 @Override
1979
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
329 public Settings getSettings() {
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
330 return new EmptySettings();
a7c437c9547e Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1948
diff changeset
331 }
2047
0318fa6f0844 Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2038
diff changeset
332
0318fa6f0844 Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2038
diff changeset
333 /**
0318fa6f0844 Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2038
diff changeset
334 * This method is not implemented. Override it in subclasses if those need a
0318fa6f0844 Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2038
diff changeset
335 * <i>Settings</i> object.
0318fa6f0844 Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2038
diff changeset
336 */
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
337 @Override
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
338 public void setSettings(final Settings settings) {
2047
0318fa6f0844 Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2038
diff changeset
339 // do nothing
0318fa6f0844 Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2038
diff changeset
340 }
2284
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
341
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
342 /**
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
343 * Returns the number formatter for kilometer values.
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
344 *
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
345 * @return the number formatter for kilometer values.
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
346 */
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
347 protected NumberFormat getKmFormatter() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
348 if (this.kmFormat == null) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
349 this.kmFormat = Formatter.getWaterlevelKM(this.context);
5111
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
350 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
351 return this.kmFormat;
2284
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
352 }
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
353
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
354 /**
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
355 * Returns the number formatter for W values.
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
356 *
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
357 * @return the number formatter for W values.
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
358 */
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
359 protected NumberFormat getWFormatter() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
360 if (this.wFormat == null) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
361 this.wFormat = Formatter.getWaterlevelW(this.context);
5111
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
362 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
363 return this.wFormat;
2284
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
364 }
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
365
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
366 /**
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
367 * Returns the number formatter for Q values.
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
368 *
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
369 * @return the number formatter for Q values.
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
370 */
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
371 protected NumberFormat getQFormatter() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
372 if (this.qFormat == null) {
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
373 this.qFormat = Formatter.getWaterlevelQ(this.context);
5111
4898376c680b AbstractExporter: keep km-, w- and q-formatter instances.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5102
diff changeset
374 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
375 return this.qFormat;
2284
5d1ba04d2f68 Refactored Formatter access to ease reuse.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2176
diff changeset
376 }
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
377
8862
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
378 protected final NumberFormat getMeanBedHeighFormatter() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
379 if (this.meanBedHeightFormat == null)
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
380 this.meanBedHeightFormat = Formatter.getMeanBedHeight(this.context);
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
381 return this.meanBedHeightFormat;
8862
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
382 }
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
383
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
384 protected final NumberFormat getTkhFormatter() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
385 if (this.tkhFormat == null)
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
386 this.tkhFormat = Formatter.getTkh(this.context);
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
387 return this.tkhFormat;
8862
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
388 }
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
389
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
390 protected final NumberFormat getFlowDepthFormatter() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
391 if (this.flowDepthFormat == null)
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
392 this.flowDepthFormat = Formatter.getFlowDepth(this.context);
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
393 return this.flowDepthFormat;
8862
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
394 }
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
395
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
396 protected final NumberFormat getW2Formatter() {
9150
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
397 if (this.w2Format == null)
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
398 this.w2Format = Formatter.getFlowDepth(this.context);
23945061daec gigantic refactoring: exporter, result, results
gernotbelger
parents: 8936
diff changeset
399 return this.w2Format;
8862
5b5bdce5a216 Introduced new number formats for some new data types
gernotbelger
parents: 8856
diff changeset
400 }
391
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
401 }
5d6988836f01 Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
402 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org