Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATExport.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATExport.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.exports.fixings; | |
2 | |
3 import au.com.bytecode.opencsv.CSVWriter; | |
4 | |
5 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
6 | |
7 import org.dive4elements.river.artifacts.FLYSArtifact; | |
8 | |
9 import org.dive4elements.river.artifacts.access.FixAccess; | |
10 | |
11 import org.dive4elements.river.artifacts.math.fitting.Function; | |
12 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory; | |
13 | |
14 import org.dive4elements.river.artifacts.model.CalculationResult; | |
15 import org.dive4elements.river.artifacts.model.Parameters; | |
16 | |
17 import org.dive4elements.river.artifacts.model.fixings.FixResult; | |
18 | |
19 import org.dive4elements.river.exports.AbstractExporter; | |
20 | |
21 import java.io.IOException; | |
22 import java.io.OutputStream; | |
23 import java.io.OutputStreamWriter; | |
24 import java.io.Writer; | |
25 | |
26 import org.apache.log4j.Logger; | |
27 | |
28 import org.w3c.dom.Document; | |
29 import org.w3c.dom.NodeList; | |
30 | |
31 /** Export result of fixation analysis. */ | |
32 public class FixATExport extends AbstractExporter { | |
33 | |
34 /** Private logger. */ | |
35 private static Logger logger = | |
36 Logger.getLogger(FixATExport.class); | |
37 | |
38 protected Function function; | |
39 protected Parameters parameters; | |
40 | |
41 | |
42 @Override | |
43 public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) { | |
44 logger.debug("AT Export doOut()."); | |
45 Object data = bundle.getData(context); | |
46 if (data instanceof CalculationResult) { | |
47 CalculationResult cr = (CalculationResult)data; | |
48 Object resData = cr.getData(); | |
49 if (resData instanceof FixResult) { | |
50 this.parameters = ((FixResult)resData).getParameters(); | |
51 } | |
52 } | |
53 else { | |
54 logger.debug("No CalculationResult found for AT export."); | |
55 return; | |
56 } | |
57 FixAccess access = new FixAccess((FLYSArtifact)this.master, context); | |
58 String f = access.getFunction(); | |
59 if (f == null || f.length() == 0) { | |
60 logger.debug("No function found for AT export."); | |
61 return; | |
62 } | |
63 this.function = FunctionFactory.getInstance().getFunction(f); | |
64 } | |
65 | |
66 @Override | |
67 public void generate() throws IOException { | |
68 if (this.function == null || this.parameters == null) { | |
69 logger.debug("No function or paramters for AT export."); | |
70 return; | |
71 } | |
72 | |
73 Writer writer = new OutputStreamWriter(out, DEFAULT_CSV_CHARSET); | |
74 | |
75 FixAccess access = new FixAccess((FLYSArtifact)this.master, context); | |
76 FixATWriter atWriter = new FixATWriter(this.function, this.parameters); | |
77 NodeList nodes = request.getElementsByTagName("km"); | |
78 String km = nodes.item(0).getTextContent(); | |
79 double dkm = Double.parseDouble(km); | |
80 String river = access.getRiver(); | |
81 atWriter.write(writer, context.getMeta(), river, dkm); | |
82 writer.close(); | |
83 } | |
84 | |
85 @Override | |
86 protected void writeCSVData(CSVWriter writer) throws IOException { | |
87 // The concrete writer is used to write csv data. | |
88 } | |
89 | |
90 @Override | |
91 protected void writePDF(OutputStream out) { | |
92 // Implement me! | |
93 } | |
94 | |
95 @Override | |
96 protected void addData(Object data) { | |
97 // Nothing to do here. | |
98 } | |
99 } | |
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |