view flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixATExport.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents cbe2febe30cc
children acfd48384835
line wrap: on
line source
package de.intevation.flys.exports.fixings;

import au.com.bytecode.opencsv.CSVWriter;

import de.intevation.artifactdatabase.state.ArtifactAndFacet;

import de.intevation.flys.artifacts.FLYSArtifact;

import de.intevation.flys.artifacts.access.FixAccess;

import de.intevation.flys.artifacts.math.fitting.Function;
import de.intevation.flys.artifacts.math.fitting.FunctionFactory;

import de.intevation.flys.artifacts.model.CalculationResult;
import de.intevation.flys.artifacts.model.Parameters;

import de.intevation.flys.artifacts.model.fixings.FixAnalysisResult;

import de.intevation.flys.exports.AbstractExporter;

import de.intevation.flys.utils.FLYSUtils;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

/** Export result of fixation analysis. */
public class FixATExport extends AbstractExporter {

    /** Private logger. */
    private static Logger logger =
        Logger.getLogger(FixATExport.class);

    protected Function function;
    protected Parameters parameters;


    @Override
    public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) {
        logger.debug("AT Export doOut().");
        Object data = bundle.getData(context);
        if (data instanceof CalculationResult) {
            CalculationResult cr = (CalculationResult)data;
            Object resData = cr.getData();
            if (resData instanceof FixAnalysisResult) {
                this.parameters = ((FixAnalysisResult)resData).getParameters();
            }
        }
        else {
            logger.debug("No CalculationResult found for AT export.");
            return;
        }
        FixAccess access = new FixAccess((FLYSArtifact)this.master);
        String f = access.getFunction();
        if (f == null || f.length() == 0) {
            logger.debug("No function found for AT export.");
            return;
        }
        this.function = FunctionFactory.getInstance().getFunction(f);
    }

    @Override
    public void generate() throws IOException {
        if (this.function == null || this.parameters == null) {
            logger.debug("No function or paramters for AT export.");
            return;
        }

        Writer writer = new OutputStreamWriter(out, DEFAULT_CSV_CHARSET);

        FixATWriter atWriter = new FixATWriter(this.function, this.parameters);
        NodeList nodes = request.getElementsByTagName("km");
        String km = nodes.item(0).getTextContent();
        double dkm = Double.parseDouble(km);
        String river = FLYSUtils.getRivername((FLYSArtifact)master);
        atWriter.write(writer, context.getMeta(), river, dkm);
        writer.close();
    }

    @Override
    protected void writeCSVData(CSVWriter writer) throws IOException {
        // The concrete writer is used to write csv data.
    }

    @Override
    protected void writePDF(OutputStream out) {
        // Implement me!
    }

    @Override
    protected void addData(Object data) {
        // Nothing to do here.
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org