Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/exports/ATExporter.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java@64139914e446 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.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 org.dive4elements.artifacts.Artifact; | |
12 import org.dive4elements.artifacts.CallContext; | |
13 | |
14 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
15 import org.dive4elements.artifactdatabase.state.Settings; | |
16 | |
17 import org.dive4elements.river.artifacts.FLYSArtifact; | |
18 | |
19 import org.dive4elements.river.artifacts.model.WQ; | |
20 import org.dive4elements.river.collections.FLYSArtifactCollection; | |
21 | |
22 import org.dive4elements.river.model.Gauge; | |
23 import org.dive4elements.river.model.River; | |
24 import org.dive4elements.river.model.TimeInterval; | |
25 import org.dive4elements.river.utils.FLYSUtils; | |
26 import org.dive4elements.river.artifacts.access.RangeAccess; | |
27 | |
28 public class ATExporter | |
29 implements OutGenerator | |
30 { | |
31 private static Logger logger = Logger.getLogger(ATExporter.class); | |
32 | |
33 public static final String DEFAULT_ENCODING = "UTF-8"; | |
34 | |
35 protected WQ data; | |
36 protected CallContext context; | |
37 protected OutputStream out; | |
38 protected FLYSArtifact master; | |
39 | |
40 protected FLYSArtifactCollection collection; | |
41 | |
42 | |
43 public ATExporter() { | |
44 } | |
45 | |
46 @Override | |
47 public void init(Document request, OutputStream out, CallContext context) { | |
48 this.context = context; | |
49 this.out = out; | |
50 } | |
51 | |
52 | |
53 @Override | |
54 public void setMasterArtifact(Artifact master) { | |
55 this.master = (FLYSArtifact) master; | |
56 } | |
57 | |
58 @Override | |
59 public void setCollection(FLYSArtifactCollection collection) { | |
60 this.collection = collection; | |
61 } | |
62 | |
63 @Override | |
64 public void doOut( | |
65 ArtifactAndFacet artifactf, | |
66 Document attr, | |
67 boolean visible | |
68 ) { | |
69 data = (WQ)artifactf.getData(context); | |
70 } | |
71 | |
72 @Override | |
73 public void generate() throws IOException { | |
74 | |
75 if (data == null) { | |
76 logger.debug("no W/Q data"); | |
77 return; | |
78 } | |
79 | |
80 ATWriter at; | |
81 try { | |
82 at = new ATWriter(data); | |
83 } | |
84 catch (IllegalArgumentException iae) { | |
85 logger.error("creating ATWriter failed", iae); | |
86 throw new IOException(iae); | |
87 } | |
88 | |
89 River river = FLYSUtils.getRiver(master); | |
90 RangeAccess rangeAccess = new RangeAccess(master, context); | |
91 double[] kms = rangeAccess.getLocations(); | |
92 | |
93 Gauge gauge = river.determineGaugeByPosition(kms[0]); | |
94 if (Math.abs(kms[0] - gauge.getStation().doubleValue()) < 1e-4) { | |
95 // at gauge. | |
96 TimeInterval interval = | |
97 gauge.fetchMasterDischargeTable().getTimeInterval(); | |
98 at.write( | |
99 new OutputStreamWriter(out, DEFAULT_ENCODING), | |
100 context.getMeta(), | |
101 river.getName(), | |
102 kms[0], | |
103 gauge.getName(), | |
104 gauge.getDatum(), | |
105 interval.getStartTime(), | |
106 100d); | |
107 } | |
108 else { | |
109 // at km | |
110 at.write( | |
111 new OutputStreamWriter(out), | |
112 context.getMeta(), | |
113 river.getName(), | |
114 kms[0], | |
115 null, | |
116 null, | |
117 null, | |
118 0d); | |
119 } | |
120 | |
121 } | |
122 | |
123 | |
124 /** | |
125 * Returns an instance of <i>EmptySettings</i> currently! | |
126 * | |
127 * @return an instance of <i>EmptySettings</i>. | |
128 */ | |
129 @Override | |
130 public Settings getSettings() { | |
131 return new EmptySettings(); | |
132 } | |
133 | |
134 | |
135 /** | |
136 * This method is not implemented! | |
137 * | |
138 * @param settings A settings object. | |
139 */ | |
140 @Override | |
141 public void setSettings(Settings settings) { | |
142 // do nothing here | |
143 } | |
144 } | |
145 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |