Mercurial > dive4elements > river
changeset 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 | 078934923acb |
children | 5ddb1b568f38 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java |
diffstat | 2 files changed, 83 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Jun 23 15:50:44 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Jun 23 16:45:48 2011 +0000 @@ -1,3 +1,8 @@ +2011-06-23 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/exports/ATExporter.java: New. + Exporter for AT facets. Needs testing. + 2011-06-23 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/exports/ATWriter.java: New.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java Thu Jun 23 16:45:48 2011 +0000 @@ -0,0 +1,78 @@ +package de.intevation.flys.exports; + +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.IOException; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.flys.artifacts.FLYSArtifact; + +import de.intevation.artifactdatabase.state.Facet; + +import de.intevation.flys.artifacts.model.WQ; + +public class ATExporter +implements OutGenerator +{ + private static Logger logger = Logger.getLogger(ATExporter.class); + + public static final String DEFAULT_ENCODING = "UTF-8"; + + protected WQ data; + protected CallContext context; + protected OutputStream out; + + public ATExporter() { + } + + @Override + public void init(Document request, OutputStream out, CallContext context) { + this.context = context; + this.out = out; + } + + @Override + public void setMasterArtifact(Artifact master) { + // not needed + } + + @Override + public void doOut(Artifact artifact, Facet facet, Document attr) { + + FLYSArtifact flys = (FLYSArtifact)artifact; + + if ((facet = flys.getNativeFacet(facet)) == null) { + logger.debug("native facet not found."); + return; + } + + data = (WQ)facet.getData(flys, context); + } + + @Override + public void generate() throws IOException { + + if (data == null) { + logger.debug("no W/Q data"); + return; + } + + ATWriter at; + try { + at = new ATWriter(data); + } + catch (IllegalArgumentException iae) { + logger.error("creating ATWriter failed", iae); + throw new IOException(iae); + } + + at.write(new OutputStreamWriter(out, DEFAULT_ENCODING)); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :