view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java @ 1849:5d5dd44d613e

Refactored, move doMainValueAnnotations to XYChartGenerator. flys-artifacts/trunk@3193 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 09 Nov 2011 13:06:08 +0000
parents 7f5426c69ee0
children fde3db5e68e8
line wrap: on
line source
package de.intevation.flys.artifacts.states;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.xpath.XPathConstants;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import de.intevation.artifacts.CallMeta;

import de.intevation.artifacts.common.utils.Config;
import de.intevation.artifacts.common.utils.XMLUtils;

import de.intevation.artifactdatabase.state.Facet;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.model.WMSLayerFacet;
import de.intevation.flys.artifacts.resources.Resources;
import de.intevation.flys.artifacts.states.DefaultState.ComputeType;


public class WMSBackgroundState extends OutputState {

    public static final String I18N_DESCRIPTION = "floodmap.wmsbackground";

    public static final String XPATH_SRID =
        "/artifact-database/floodmap/river[@name=$name]/srid/@value";

    public static final String XPATH_WMS_URL =
        "/artifact-database/floodmap/river[@name=$name]/background-wms/@url";

    public static final String XPATH_WMS_LAYER =
        "/artifact-database/floodmap/river[@name=$name]/background-wms/@layers";


    protected String url;
    protected String layer;
    protected String srid;


    private static final Logger logger = Logger.getLogger(WMSBackgroundState.class);


    @Override
    public void setup(Node config) {
        super.setup(config);

        logger.debug("WMSBackgroundState.setup()");
    }


    @Override
    public Object computeInit(
        FLYSArtifact artifact,
        String       hash,
        Object       context,
        CallMeta     meta,
        List<Facet>  facets
    ) {
        logger.debug("WMSBackgroundState.computeInit()");

        if (url == null || layer == null) {
            Document cfg = Config.getConfig();

            String river = artifact.getDataAsString("river");

            Map<String, String> variables = new HashMap<String, String>();
            variables.put("name", river);

            srid = (String) XMLUtils.xpath(
                cfg,
                XPATH_SRID,
                XPathConstants.STRING,
                null,
                variables);

            url = (String) XMLUtils.xpath(
                cfg,
                XPATH_WMS_URL,
                XPathConstants.STRING,
                null,
                variables);

            layer = (String) XMLUtils.xpath(
                cfg,
                XPATH_WMS_LAYER,
                XPathConstants.STRING,
                null,
                variables);
        }

        if (url == null || layer == null) {
            logger.warn("No background layers currently configured:");
            logger.warn("... add config for WMS url: " + XPATH_WMS_URL);
            logger.warn("... add config for WMS layer: " + XPATH_WMS_LAYER);
            return null;
        }

        WMSLayerFacet facet = new WMSLayerFacet(
            0,
            FLOODMAP_WMSBACKGROUND,
            Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION),
            ComputeType.INIT,
            getID(), hash,
            url);

        facet.addLayer(layer);
        facet.setSrid(srid);

        facets.add(facet);

        return null;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org