teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5863: * Software engineering by Intevation GmbH
teichmann@5863: *
teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5994: * documentation coming with Dive4Elements River for details.
teichmann@5863: */
teichmann@5863:
teichmann@5831: package org.dive4elements.river.exports;
sascha@730:
sascha@730: import java.io.OutputStream;
sascha@730: import java.io.OutputStreamWriter;
sascha@730: import java.io.IOException;
sascha@730:
sascha@730: import org.w3c.dom.Document;
sascha@730:
tom@9726: import org.apache.logging.log4j.Logger;
tom@9726: import org.apache.logging.log4j.LogManager;
sascha@730:
teichmann@5831: import org.dive4elements.artifacts.Artifact;
teichmann@5831: import org.dive4elements.artifacts.CallContext;
sascha@730:
teichmann@5831: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
teichmann@5831: import org.dive4elements.artifactdatabase.state.Settings;
sascha@730:
teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact;
teichmann@5831:
teichmann@5831: import org.dive4elements.river.artifacts.model.WQ;
teichmann@5867: import org.dive4elements.river.collections.D4EArtifactCollection;
teichmann@5831:
teichmann@5831: import org.dive4elements.river.model.Gauge;
teichmann@5831: import org.dive4elements.river.model.River;
teichmann@5831: import org.dive4elements.river.model.TimeInterval;
teichmann@6905: import org.dive4elements.river.themes.ThemeDocument;
tom@8380: import org.dive4elements.river.artifacts.access.RiverAccess;
teichmann@5831: import org.dive4elements.river.artifacts.access.RangeAccess;
ingo@1658:
sascha@730: public class ATExporter
sascha@730: implements OutGenerator
sascha@730: {
tom@9726: private static Logger log = LogManager.getLogger(ATExporter.class);
sascha@730:
sascha@730: public static final String DEFAULT_ENCODING = "UTF-8";
sascha@730:
sascha@730: protected WQ data;
sascha@730: protected CallContext context;
sascha@730: protected OutputStream out;
teichmann@7077: protected D4EArtifact master;
teichmann@7077: protected String outName;
sascha@730:
teichmann@5867: protected D4EArtifactCollection collection;
ingo@3422:
ingo@3422:
sascha@730: public ATExporter() {
sascha@730: }
sascha@730:
sascha@730: @Override
teichmann@7087: public void setup(Object config) {
teichmann@8202: log.debug("ATExporter.setup");
teichmann@7037: }
teichmann@7037:
teichmann@7037: @Override
tom@8856: public void init(
tom@8856: String outName,
tom@8856: Document request,
tom@8856: OutputStream out,
tom@8856: CallContext context
tom@8856: ) {
teichmann@7077: this.outName = outName;
sascha@730: this.context = context;
sascha@730: this.out = out;
sascha@730: }
sascha@730:
ingo@3422:
sascha@730: @Override
sascha@730: public void setMasterArtifact(Artifact master) {
teichmann@5867: this.master = (D4EArtifact) master;
sascha@730: }
sascha@730:
sascha@730: @Override
teichmann@5867: public void setCollection(D4EArtifactCollection collection) {
ingo@3422: this.collection = collection;
ingo@3422: }
ingo@3422:
ingo@3422: @Override
ingo@1684: public void doOut(
felix@1944: ArtifactAndFacet artifactf,
teichmann@6905: ThemeDocument attr,
teichmann@6905: boolean visible
ingo@1684: ) {
felix@1944: data = (WQ)artifactf.getData(context);
sascha@730: }
sascha@730:
sascha@730: @Override
sascha@730: public void generate() throws IOException {
sascha@730:
sascha@730: if (data == null) {
teichmann@8202: log.debug("no W/Q data");
sascha@730: return;
sascha@730: }
sascha@730:
tom@8380: River river = new RiverAccess(master).getRiver();
tom@8380: double[] kms = new RangeAccess(master).getLocations();
ingo@1658:
tom@8724: Gauge gauge = river.determineGaugeAtStation(kms[0]);
tom@8724: if (gauge != null) {
rrenkert@4941: // at gauge.
rrenkert@4941: TimeInterval interval =
rrenkert@4941: gauge.fetchMasterDischargeTable().getTimeInterval();
aheinecke@6304: ATWriter.write(
aheinecke@6304: data,
rrenkert@4941: new OutputStreamWriter(out, DEFAULT_ENCODING),
rrenkert@4941: context.getMeta(),
rrenkert@4941: river.getName(),
rrenkert@4941: kms[0],
rrenkert@4941: gauge.getName(),
rrenkert@4941: gauge.getDatum(),
rrenkert@4941: interval.getStartTime(),
aheinecke@6304: river.getWstUnit().getName());
rrenkert@4941: }
rrenkert@4941: else {
rrenkert@4941: // at km
aheinecke@6304: ATWriter.write(
aheinecke@6304: data,
rrenkert@4941: new OutputStreamWriter(out),
rrenkert@4941: context.getMeta(),
rrenkert@4941: river.getName(),
rrenkert@4941: kms[0],
rrenkert@4941: null,
rrenkert@4941: null,
rrenkert@4941: null,
aheinecke@6304: river.getWstUnit().getName());
rrenkert@4941: }
rrenkert@4941:
sascha@730: }
ingo@1979:
ingo@1979:
ingo@1979: /**
ingo@1979: * Returns an instance of EmptySettings currently!
ingo@1979: *
ingo@1979: * @return an instance of EmptySettings.
ingo@1979: */
ingo@2047: @Override
ingo@1979: public Settings getSettings() {
ingo@1979: return new EmptySettings();
ingo@1979: }
ingo@2047:
ingo@2047:
ingo@2047: /**
ingo@2047: * This method is not implemented!
ingo@2047: *
ingo@2047: * @param settings A settings object.
ingo@2047: */
ingo@2047: @Override
ingo@2047: public void setSettings(Settings settings) {
ingo@2047: // do nothing here
ingo@2047: }
sascha@730: }
sascha@730: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :