Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java @ 1160:efe1b8545f5c
Cosmetics
flys-artifacts/trunk@2696 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 12 Sep 2011 09:00:08 +0000 |
parents | cded0924193d |
children | bdb05dc9b763 |
rev | line source |
---|---|
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.exports; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 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
|
4 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
|
5 import java.io.OutputStreamWriter; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Document; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.apache.log4j.Logger; |
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 au.com.bytecode.opencsv.CSVWriter; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifacts.Artifact; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.CallContext; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
695
45cd58a2a2bb
OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
445
diff
changeset
|
16 import de.intevation.artifactdatabase.state.Facet; |
45cd58a2a2bb
OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
445
diff
changeset
|
17 |
445
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
18 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
19 import de.intevation.artifacts.common.utils.XMLUtils; |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
20 |
416
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
412
diff
changeset
|
21 import de.intevation.flys.artifacts.resources.Resources; |
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
412
diff
changeset
|
22 |
701
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
23 import de.intevation.flys.artifacts.FLYSArtifact; |
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
24 |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 /** |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * An abstract exporter that implements some basic methods for exporting data of |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 * artifacts. |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 * |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 * @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
|
31 */ |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 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
|
33 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 /** The logger used in this exporter.*/ |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 private static Logger logger = Logger.getLogger(AbstractExporter.class); |
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 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
38 /** 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
|
39 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
|
40 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
41 /** 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
|
42 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
|
43 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
44 /** The default separator 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
|
45 public static final char DEFAULT_CSV_SEPARATOR = ','; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
47 /** 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
|
48 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
|
49 |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
51 /** 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
|
52 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
|
53 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
54 /** 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
|
55 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
|
56 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
57 /** 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
|
58 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
|
59 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
60 /** 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
|
61 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
|
62 |
1160
efe1b8545f5c
Cosmetics
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
710
diff
changeset
|
63 /** 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
|
64 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
|
65 |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 /** |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 * 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
|
69 * 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
|
70 * |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 * @param writer The CSVWriter. |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 */ |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 protected abstract void writeCSVData(CSVWriter writer); |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 /** |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 * 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
|
78 * data. |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 * |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 * @param artifacts The artifact that stores the data that has to be |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 * exported. |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 */ |
701
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
83 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
|
84 |
710
cded0924193d
Added generator and facet for error reports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
701
diff
changeset
|
85 @Override |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 public void init(Document request, OutputStream out, CallContext context) { |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 logger.debug("AbstractExporter.init"); |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 this.request = request; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 this.out = out; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 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
|
92 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 |
710
cded0924193d
Added generator and facet for error reports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
701
diff
changeset
|
95 @Override |
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
|
96 public void setMasterArtifact(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
|
97 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
|
98 } |
046bd86ae41d
Improved the OutGenerator interface to set a master artifact for the out generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
391
diff
changeset
|
99 |
046bd86ae41d
Improved the OutGenerator interface to set a master artifact for the out generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
391
diff
changeset
|
100 |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 /** |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 * 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
|
103 * 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
|
104 * 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
|
105 * 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
|
106 * |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 * @param artifact The artifact. |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 * @param facet The facet to add - NOTE: the facet needs to fit to the first |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 * facet inserted into this exporter. Otherwise this artifact/facet is |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 * skipped. |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 * @param attr The attr document. |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 */ |
710
cded0924193d
Added generator and facet for error reports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
701
diff
changeset
|
113 @Override |
695
45cd58a2a2bb
OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
445
diff
changeset
|
114 public void doOut(Artifact artifact, Facet facet, Document attr) { |
45cd58a2a2bb
OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
445
diff
changeset
|
115 String name = facet.getName(); |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 |
695
45cd58a2a2bb
OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
445
diff
changeset
|
117 logger.debug("AbstractExporter.doOut: " + name); |
45cd58a2a2bb
OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
445
diff
changeset
|
118 |
45cd58a2a2bb
OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
445
diff
changeset
|
119 if (!isFacetValid(name)) { |
45cd58a2a2bb
OutGenerators doOut() takes a facet object now instead of just its name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
445
diff
changeset
|
120 logger.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
|
121 return; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 |
701
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
124 FLYSArtifact flys = (FLYSArtifact)artifact; |
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
125 |
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
126 Facet nativeFacet = flys.getNativeFacet(facet); |
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
127 |
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
128 if (nativeFacet != null) { |
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
129 addData(nativeFacet.getData(flys, context)); |
dad1a2c88f9f
Base WST/CSV exports on facets. TODO: generate the facets.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
695
diff
changeset
|
130 } |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
131 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 /** |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 * 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
|
136 */ |
710
cded0924193d
Added generator and facet for error reports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
701
diff
changeset
|
137 @Override |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 public void generate() |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 throws IOException |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 { |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 logger.debug("AbstractExporter.generate"); |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 if (facet != null && facet.equals(FACET_CSV)) { |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
144 generateCSV(); |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
145 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 else { |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
147 throw new IOException("invalid facet for exporter."); |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 /** |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 * 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
|
154 * 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
|
155 * |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 * @param facet The desired facet. |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
157 * |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
158 * @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
|
159 */ |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
160 protected boolean isFacetValid(String facet) { |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 logger.debug("AbstractExporter.isFacetValid"); |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
162 |
445
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
163 String thisFacet = getFacet(); |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
164 |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
165 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
|
166 return false; |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
167 } |
445
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
168 else if (facet == null || facet.length() == 0) { |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
169 return false; |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 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
|
172 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
|
173 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
174 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
176 |
445
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
177 /** |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
178 * 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
|
179 * |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
180 * @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
|
181 */ |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
182 protected String getFacet() { |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
183 if (facet == null) { |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
184 facet = getFacetFromRequest(); |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
185 } |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
186 |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
187 return facet; |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
188 } |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
189 |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
190 |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
191 /** |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
192 * 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
|
193 * |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
194 * @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
|
195 */ |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
196 protected String getFacetFromRequest() { |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
197 return XMLUtils.xpathString( |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
198 request, XPATH_FACET, ArtifactNamespaceContext.INSTANCE); |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
199 } |
a7947972fdeb
Added a new class that supports formatters for different types of data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
418
diff
changeset
|
200 |
416
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
412
diff
changeset
|
201 |
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
412
diff
changeset
|
202 protected String msg(String key, String def) { |
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
412
diff
changeset
|
203 return Resources.getMsg(context.getMeta(), key, def); |
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
412
diff
changeset
|
204 } |
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
412
diff
changeset
|
205 |
340dc41a7ea3
The CSV exports will now have headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
412
diff
changeset
|
206 |
391
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
207 /** |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
208 * 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
|
209 * 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
|
210 */ |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 protected void generateCSV() |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
212 throws IOException |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
213 { |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
214 logger.info("AbstractExporter.generateCSV"); |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
215 |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
216 CSVWriter writer = new CSVWriter( |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
217 new OutputStreamWriter( |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
218 out, |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
219 DEFAULT_CSV_CHARSET), |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
220 DEFAULT_CSV_SEPARATOR); |
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 writeCSVData(writer); |
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 writer.close(); |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
225 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
226 } |
5d6988836f01
Added an exporter to export the computed data of a duration curve.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
227 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |