comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java @ 3786:4adc35aa655c

merged flys-artifacts/2.9.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:47 +0200
parents 118fe1cc8cc8
children f86c8d75fd85
comparison
equal deleted inserted replaced
3719:e82acd5c86f7 3786:4adc35aa655c
1 package de.intevation.flys.exports;
2
3 import java.io.OutputStream;
4 import java.io.OutputStreamWriter;
5 import java.io.IOException;
6
7 import org.w3c.dom.Document;
8
9 import org.apache.log4j.Logger;
10
11 import de.intevation.artifacts.Artifact;
12 import de.intevation.artifacts.CallContext;
13
14 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
15 import de.intevation.artifactdatabase.state.Settings;
16
17 import de.intevation.flys.artifacts.FLYSArtifact;
18
19 import de.intevation.flys.artifacts.model.WQ;
20 import de.intevation.flys.collections.FLYSArtifactCollection;
21
22 import de.intevation.flys.utils.FLYSUtils;
23
24
25 public class ATExporter
26 implements OutGenerator
27 {
28 private static Logger logger = Logger.getLogger(ATExporter.class);
29
30 public static final String DEFAULT_ENCODING = "UTF-8";
31
32 protected WQ data;
33 protected CallContext context;
34 protected OutputStream out;
35 protected FLYSArtifact master;
36
37 protected FLYSArtifactCollection collection;
38
39
40 public ATExporter() {
41 }
42
43 @Override
44 public void init(Document request, OutputStream out, CallContext context) {
45 this.context = context;
46 this.out = out;
47 }
48
49
50 @Override
51 public void setMasterArtifact(Artifact master) {
52 this.master = (FLYSArtifact) master;
53 }
54
55 @Override
56 public void setCollection(FLYSArtifactCollection collection) {
57 this.collection = collection;
58 }
59
60 @Override
61 public void doOut(
62 ArtifactAndFacet artifactf,
63 Document attr,
64 boolean visible
65 ) {
66 data = (WQ)artifactf.getData(context);
67 }
68
69 @Override
70 public void generate() throws IOException {
71
72 if (data == null) {
73 logger.debug("no W/Q data");
74 return;
75 }
76
77 ATWriter at;
78 try {
79 at = new ATWriter(data);
80 }
81 catch (IllegalArgumentException iae) {
82 logger.error("creating ATWriter failed", iae);
83 throw new IOException(iae);
84 }
85
86 String river = FLYSUtils.getRiver(master).getName();
87 double[] kms = FLYSUtils.getLocations(master);
88
89 at.write(
90 new OutputStreamWriter(out, DEFAULT_ENCODING),
91 context.getMeta(),
92 river,
93 kms[0]);
94 }
95
96
97 /**
98 * Returns an instance of <i>EmptySettings</i> currently!
99 *
100 * @return an instance of <i>EmptySettings</i>.
101 */
102 @Override
103 public Settings getSettings() {
104 return new EmptySettings();
105 }
106
107
108 /**
109 * This method is not implemented!
110 *
111 * @param settings A settings object.
112 */
113 @Override
114 public void setSettings(Settings settings) {
115 // do nothing here
116 }
117 }
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org