Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/exports/ShapeExporter.java @ 6970:7be97faf5848
flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 05 Sep 2013 17:15:04 +0200 |
parents | 1b35b2ddfc28 |
children | 5c6fd2c010dd |
line wrap: on
line source
package org.dive4elements.river.exports; import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.io.OutputStream; import org.apache.log4j.Logger; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifactdatabase.state.Settings; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; import org.dive4elements.artifacts.common.ArtifactNamespaceContext; import org.dive4elements.artifacts.common.utils.FileTools; import org.dive4elements.artifacts.common.utils.XMLUtils; import org.dive4elements.river.collections.D4EArtifactCollection; import org.dive4elements.river.themes.ThemeDocument; import org.w3c.dom.Document; public class ShapeExporter implements OutGenerator { private static final String XPATH_FACET = "/art:action/@art:type"; private static Logger logger = Logger.getLogger(ShapeExporter.class); private Artifact master; private Document request; private OutputStream out; private CallContext context; private D4EArtifactCollection collection; private String facet; private File dir; @Override public void init(Document request, OutputStream out, CallContext context) { this.request = request; this.out = out; this.context = context; } @Override public void setMasterArtifact(Artifact master) { this.master = master; } @Override public void setCollection(D4EArtifactCollection collection) { this.collection = collection; } @Override public void doOut(ArtifactAndFacet bundle, ThemeDocument attr, boolean visible) { String name = bundle.getFacetName(); if (!isFacetValid(name)) { logger.debug("Facet '" + name + "' is not valid for this exporter!"); return; } addData(bundle.getData(context)); } private void addData(Object data) { if (data instanceof File) { this.dir = (File)data; } } private boolean isFacetValid(String name) { String thisFacet = getFacet(); if (thisFacet == null || thisFacet.length() == 0) { return false; } else if (facet == null || facet.length() == 0) { return false; } else { return thisFacet.equals(facet); } } /** * Returns the name of the desired facet. * * @return the name of the desired facet. */ protected String getFacet() { if (facet == null) { facet = getFacetFromRequest(); } return facet; } @Override public void generate() throws IOException { FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.getName().startsWith("wsplgen") && !pathname.getName().endsWith(".par")) { return true; } else { return false; } } }; FileTools.createZipArchive(this.dir, out, filter); out.close(); } @Override public void setSettings(Settings settings) { //Do nothing. } @Override public Settings getSettings() { // This exporter has no settings. return null; } /** * Extracts the name of the requested facet from request document. * * @return the name of the requested facet. */ protected String getFacetFromRequest() { return XMLUtils.xpathString( request, XPATH_FACET, ArtifactNamespaceContext.INSTANCE); } }