comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java @ 730:97d774d58e24

Added exporter for AT facets. flys-artifacts/trunk@2220 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 23 Jun 2011 16:45:48 +0000
parents
children 7d11ad5a52d5
comparison
equal deleted inserted replaced
729:078934923acb 730:97d774d58e24
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.flys.artifacts.FLYSArtifact;
15
16 import de.intevation.artifactdatabase.state.Facet;
17
18 import de.intevation.flys.artifacts.model.WQ;
19
20 public class ATExporter
21 implements OutGenerator
22 {
23 private static Logger logger = Logger.getLogger(ATExporter.class);
24
25 public static final String DEFAULT_ENCODING = "UTF-8";
26
27 protected WQ data;
28 protected CallContext context;
29 protected OutputStream out;
30
31 public ATExporter() {
32 }
33
34 @Override
35 public void init(Document request, OutputStream out, CallContext context) {
36 this.context = context;
37 this.out = out;
38 }
39
40 @Override
41 public void setMasterArtifact(Artifact master) {
42 // not needed
43 }
44
45 @Override
46 public void doOut(Artifact artifact, Facet facet, Document attr) {
47
48 FLYSArtifact flys = (FLYSArtifact)artifact;
49
50 if ((facet = flys.getNativeFacet(facet)) == null) {
51 logger.debug("native facet not found.");
52 return;
53 }
54
55 data = (WQ)facet.getData(flys, context);
56 }
57
58 @Override
59 public void generate() throws IOException {
60
61 if (data == null) {
62 logger.debug("no W/Q data");
63 return;
64 }
65
66 ATWriter at;
67 try {
68 at = new ATWriter(data);
69 }
70 catch (IllegalArgumentException iae) {
71 logger.error("creating ATWriter failed", iae);
72 throw new IOException(iae);
73 }
74
75 at.write(new OutputStreamWriter(out, DEFAULT_ENCODING));
76 }
77 }
78 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org