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@710: sascha@710: import java.io.IOException; sascha@710: import java.io.OutputStream; sascha@710: sascha@710: import org.apache.log4j.Logger; sascha@710: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; sascha@710: teichmann@5831: import org.dive4elements.artifacts.common.utils.XMLUtils; sascha@710: teichmann@5831: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5831: import org.dive4elements.artifactdatabase.state.Settings; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.model.Calculation; teichmann@5867: import org.dive4elements.river.collections.D4EArtifactCollection; teichmann@6905: import org.dive4elements.river.themes.ThemeDocument; sascha@710: sascha@710: import org.w3c.dom.Document; teichmann@7037: import org.w3c.dom.Element; sascha@710: sascha@710: public class ReportGenerator sascha@742: implements OutGenerator sascha@710: { sascha@710: private static Logger logger = Logger.getLogger(ReportGenerator.class); sascha@710: sascha@710: protected Document result; sascha@710: protected OutputStream out; sascha@710: protected CallContext context; sascha@710: sascha@710: public ReportGenerator() { sascha@710: } sascha@710: sascha@710: @Override teichmann@7037: public void setup(Element config) { teichmann@7037: logger.debug("ReportGenerator.setup"); teichmann@7037: } teichmann@7037: teichmann@7037: @Override sascha@710: public void init(Document request, OutputStream out, CallContext context) { sascha@710: logger.debug("init"); sascha@710: this.out = out; sascha@710: this.context = context; sascha@2303: result = null; sascha@710: } sascha@710: sascha@710: @Override sascha@710: public void setMasterArtifact(Artifact master) { sascha@710: // not needed sascha@710: } sascha@710: sascha@710: @Override teichmann@5867: public void setCollection(D4EArtifactCollection collection) { ingo@3422: // not needed ingo@3422: } ingo@3422: ingo@3422: @Override ingo@1684: public void doOut( felix@1944: ArtifactAndFacet artifactFacet, teichmann@6905: ThemeDocument attr, felix@1944: boolean visible ingo@1684: ) { sascha@710: logger.debug("doOut"); felix@1944: Facet facet = artifactFacet.getFacet(); sascha@710: if (facet != null) { felix@1944: Calculation report = (Calculation) artifactFacet.getData(context); sascha@2303: if (result == null) { sascha@2303: result = XMLUtils.newDocument(); sascha@2303: report.toXML(result, context.getMeta()); sascha@2303: } sascha@710: } sascha@710: } sascha@710: sascha@710: @Override sascha@710: public void generate() throws IOException { sascha@710: logger.debug("generate"); sascha@2303: XMLUtils.toStream(result != null sascha@2303: ? result sascha@2303: : XMLUtils.newDocument(), out); sascha@710: } 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@1979: public Settings getSettings() { ingo@1979: return new EmptySettings(); ingo@1979: } ingo@2047: ingo@2047: ingo@2047: /** ingo@2047: * This method is not implemented. Override it in subclasses if those need a ingo@2047: * Settings object. ingo@2047: */ ingo@2047: public void setSettings(Settings settings) { ingo@2047: // do nothing ingo@2047: } sascha@710: } sascha@710: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :