view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java @ 1077:3067e700fc13

Minor cosmetics and docs. flys-artifacts/trunk@2574 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 25 Aug 2011 10:34:20 +0000
parents e7c1ebfc2701
children adb52a2005e7
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 com.vividsolutions.jts.geom.Geometry;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;

import de.intevation.artifacts.CallContext;
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.model.RiverAxis;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.context.FLYSContext;
import de.intevation.flys.artifacts.model.WMSLayerFacet;
import de.intevation.flys.artifacts.resources.Resources;
import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
import de.intevation.flys.utils.GeometryUtils;


public class RiverAxisState extends OutputState {

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

    public static final String WMS_LAYER_NAME = "riveraxis";

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


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


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

        FLYSContext flysContext = null;

        if (context instanceof FLYSContext) {
            flysContext = (FLYSContext) context;
        }
        else {
            flysContext = (FLYSContext) ((CallContext) context).globalContext();
        }

        Map<String, String> wms = (Map<String, String>)
            flysContext.get(FLYSContext.RIVER_WMS);

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

        if(river == null || river.length() == 0) {
            logger.warn("No river found in the current parameterization.");
            return null;
        }

        String url = wms.get(river);

        // TODO Add config for background layer
        WMSLayerFacet facet = new WMSLayerFacet(
            0,
            FLOODMAP_RIVERAXIS,
            Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION),
            ComputeType.INIT,
            getID(), hash,
            url);

        facet.addLayer(WMS_LAYER_NAME);

        RiverAxis axis = RiverAxis.getRiverAxis(river);
        if (axis != null) {
            // TODO Take the correct EPSG into account. Maybe, we need to
            // reproject the geometry.
            Geometry geom   = axis.getGeom().getBoundary();
            String   bounds = GeometryUtils.jtsBoundsToOLBounds(geom);

            logger.debug("River '" + river + "' bounds: " + bounds);

            facet.setExtent(bounds);
        }

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

        Document cfg = Config.getConfig();

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

        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