view artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractExportContext.java @ 9195:a4121ec450d6

'ca.'-issue ExportContextCSV+PDF separated uinfo.inundationduration url export
author gernotbelger
date Fri, 29 Jun 2018 14:52:54 +0200
parents
children 3dae6b78e1da
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.artifacts.common;

import java.text.NumberFormat;

import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.resources.Resources;
import org.dive4elements.river.utils.Formatter;

/**
 * @author Domenico Nardi Tironi
 */
public abstract class AbstractExportContext implements IExportContext {

    private NumberFormat qFormat = null;

    private NumberFormat flowDepthFormat = null;

    private NumberFormat kmFormat = null;

    /** The CallContext object. */
    private final CallContext context;

    private final AbstractCalculationResults<?> results;

    public AbstractExportContext(final CallContext context, final AbstractCalculationResults<?> results) {
        this.context = context;
        this.results = results;
    }

    protected final CallContext getContext() {
        return this.context;
    }

    @Override
    public final <RESULTS extends AbstractCalculationResults<?>> RESULTS getResults() {
        @SuppressWarnings("unchecked")
        final RESULTS resultsCast = (RESULTS) this.results;
        return resultsCast;
    }

    // copy from AbstractExporter TODO merge with ExportContextPDF
    protected NumberFormat getKmFormatter() {

        if (this.kmFormat == null)
            this.kmFormat = Formatter.getWaterlevelKM(getContext());

        return this.kmFormat;
    }

    public NumberFormat getQFormatter() {
        if (this.qFormat == null)
            this.qFormat = Formatter.getWaterlevelQ(this.context);

        return this.qFormat;
    }

    public final NumberFormat getFlowDepthFormatter() {
        if (this.flowDepthFormat == null)
            this.flowDepthFormat = Formatter.getFlowDepth(this.context);

        return this.flowDepthFormat;
    }

    protected String msg(final String key) {
        return Resources.getMsg(this.context.getMeta(), key, key);
    }

    protected final String msg(final String key, final Object... args) {
        return Resources.getMsg(this.context.getMeta(), key, key, args);
    }

    @Override
    public final String formatRowValue(final ResultRow row, final IResultType type) {
        return row.exportValue(this.context, type);
    }
}

http://dive4elements.wald.intevation.org