view flys-client/src/main/java/de/intevation/flys/client/server/MapHelper.java @ 3822:1083bf2041aa

Tagged 'flys-client' as 2.9.1 flys-client/trunk@5496 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 17 Sep 2012 13:47:43 +0000
parents e3bd1f412421
children
line wrap: on
line source
package de.intevation.flys.client.server;

import org.w3c.dom.Document;

import org.apache.log4j.Logger;

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

import de.intevation.flys.client.shared.model.MapConfig;


public class MapHelper {

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


    public static final String XPATH_SRID =
        "/art:floodmap/art:srid/text()";

    public static final String XPATH_MAX_EXTENT =
        "/art:floodmap/art:maxExtent/text()";

    public static final String XPATH_INITIAL_EXTENT =
        "/art:floodmap/art:initialExtent/text()";


    private MapHelper() {
    }


    public static MapConfig parseConfig(Document raw) {
        logger.debug("MapHelper.parseConfig");

        if (logger.isDebugEnabled()) {
            logger.debug(XMLUtils.toString(raw));
        }

        MapConfig config = new MapConfig();

        setSrid(config, raw);
        setMaxExtent(config, raw);
        setInitialExtent(config, raw);

        return config;
    }


    protected static void setSrid(MapConfig config, Document raw) {
        String srid = (String) XMLUtils.xpathString(
            raw,
            XPATH_SRID,
            ArtifactNamespaceContext.INSTANCE);

        logger.debug("Found srid: '" + srid + "'");

        if (srid != null && srid.length() > 0) {
            logger.debug("Set srid: '" + srid + "'");
            config.setSrid(srid);
        }
    }


    protected static void setMaxExtent(MapConfig config, Document raw) {
        String maxExtent = (String) XMLUtils.xpathString(
            raw,
            XPATH_MAX_EXTENT,
            ArtifactNamespaceContext.INSTANCE);

        logger.debug("Found max extent: '" + maxExtent + "'");

        if (maxExtent != null && maxExtent.length() > 0) {
            logger.debug("Set max extent: '" + maxExtent + "'");
            config.setMaxExtent(maxExtent);
        }
    }


    protected static void setInitialExtent(MapConfig config, Document raw) {
        String initialExtent = (String) XMLUtils.xpathString(
            raw,
            XPATH_INITIAL_EXTENT,
            ArtifactNamespaceContext.INSTANCE);

        if (initialExtent != null && initialExtent.length() > 0) {
            logger.debug("Set initial extent: '" + initialExtent + "'");
            config.setInitialExtent(initialExtent);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org