view gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java @ 778:9a828e5a2390

Removed trailing whitespace gnv-artifacts/trunk@851 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 07:58:51 +0000
parents b3f922908a31
children b1f5f2a8840f
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.state.profile.vertical;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;

import org.apache.log4j.Logger;
import org.jfree.chart.ChartTheme;

import de.intevation.artifacts.CallContext;
import de.intevation.gnv.chart.Chart;
import de.intevation.gnv.chart.ChartLabels;
import de.intevation.gnv.chart.VerticalProfileChart;
import de.intevation.gnv.exports.DefaultDataCollector;
import de.intevation.gnv.exports.DefaultExport;
import de.intevation.gnv.exports.DefaultProfile;
import de.intevation.gnv.exports.Export.Profile;
import de.intevation.gnv.geobackend.base.Result;
import de.intevation.gnv.state.exception.StateException;
import de.intevation.gnv.state.timeseries.TimeSeriesOutputState;
import de.intevation.gnv.statistics.Statistics;
import de.intevation.gnv.statistics.VerticalProfileStatistics;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 *
 */
public class VerticalProfileOutputState extends TimeSeriesOutputState {

    public static final String [] VERTICAL_PROFILE_COLUMNS = {
        "XORDINATE", // not quite sure if this is depth
        "YORDINATE",
        "GROUP1",
        "FEATUREID",
        "TIMESERIESID"
    };

    public static final String [] VERTICAL_PROFILE_MESH_COLUMNS = {
        "XORDINATE", // not quite sure if this is depth
        "YORDINATE",
        "GROUP1",
        "FEATUREID",
        "MESHID"
    };

    public static final String [] VERTICAL_PROFILE_MEASUREMENT_COLUMNS = {
        "XORDINATE", // not quite sure if this is depth
        "YORDINATE",
        "GROUP1",
        "FEATUREID",
        "SERIESID"
    };


    public static final String [] VERTICAL_MESH_CSV_COLUMN_LABEL = {
        "CentralDepth",
        "Value",
        "ParameterID",
        "FeatureID",
        "MeshID"
    };


    public static final String [] VERTICAL_TIMESERIES_CSV_COLUMN_LABEL = {
        "Depth",
        "Value",
        "ParameterID",
        "FeatureID",
        "TimeseriesID"
    };


    public static final String [] VERTICAL_MEASUREMENT_CSV_COLUMN_LABEL = {
        "Depth",
        "Value",
        "ParameterID",
        "FeatureID",
        "SeriesID"
    };


    /**
     * The UID of this class
     */
    private static final long serialVersionUID = 4401516087492028840L;

    private static Logger log = Logger
            .getLogger(TimeSeriesOutputState.class);

    /**
     * Constructor
     */
    public VerticalProfileOutputState() {
        super();
        super.domainLable = "chart.verticalprofile.title.xaxis";
    }


    @Override
    protected Chart getChart(
        ChartLabels chartLables,
        ChartTheme  theme,
        Collection  parameters,
        Collection  measurements,
        Collection  dates,
        Object      result,
        Locale      locale,
        String      uuid,
        boolean     linesVisible,
        boolean     shapesVisible,
        CallContext callContext
    ) {
        Chart chart = null;

        if (CACHE_CHART) {
            log.info("Try to get verticalprofile chart from cache.");
            chart = (Chart) getChartFromCache(uuid, callContext);
        }

        if (chart != null)
            return chart;

        log.info("Chart not in cache yet.");
        chart = new VerticalProfileChart(
            chartLables,
            theme,
            parameters,
            measurements,
            dates,
            (Collection)result,
            null,
            locale,
            linesVisible,
            shapesVisible
        );
        chart.generateChart();

        if (CACHE_CHART) {
            log.info("Put chart into cache.");
            purifyChart(chart, uuid);
        }

        return chart;
    }


    @Override
    protected void createCSV(OutputStream out, Collection<Result> results)
    throws UnsupportedEncodingException, IOException, StateException
    {
        Iterator<Result> iter = results.iterator();
        Result   res  = iter.hasNext() ? iter.next() : null;

        if (res == null)
            return;

        Profile profile = null;
        int     dataid  = res.getInteger("DATAID").intValue();
        DefaultExport export = null;
        // on meshes
        if (dataid == 2) {
            profile =  new DefaultProfile(
                VERTICAL_MESH_CSV_COLUMN_LABEL,
                ',',
                '"',
                '"',
                "CSV",
                "ISO-8859-1");
            export = new DefaultExport(
                    new DefaultDataCollector(VERTICAL_PROFILE_MESH_COLUMNS));
        }

        // on timeseries
        else if (dataid == 1) {
            profile =  new DefaultProfile(
                VERTICAL_TIMESERIES_CSV_COLUMN_LABEL,
                ',',
                '"',
                '"',
                "CSV",
                "ISO-8859-1");
            export = new DefaultExport(
                    new DefaultDataCollector(VERTICAL_PROFILE_COLUMNS));
        }

        // on measurements
        else {
            profile =  new DefaultProfile(
                VERTICAL_MEASUREMENT_CSV_COLUMN_LABEL,
                ',',
                '"',
                '"',
                "CSV",
                "ISO-8859-1");
            export = new DefaultExport(
                    new DefaultDataCollector(VERTICAL_PROFILE_MEASUREMENT_COLUMNS));
        }
        export.create(profile, out, results);
    }


    protected String createChartSubtitle(Locale locale, String uuid) {
        return getSelectedFeatureName(uuid);
    }



    /**
     * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator()
     */
    @Override
    protected Statistics getStatisticsGenerator() {
        return new VerticalProfileStatistics();
    }

}

http://dive4elements.wald.intevation.org