ingo@1376: package de.intevation.flys.client.server;
ingo@1376: 
ingo@1376: import org.w3c.dom.Document;
ingo@1376: 
ingo@1376: import org.apache.log4j.Logger;
ingo@1376: 
ingo@1376: import de.intevation.artifacts.common.ArtifactNamespaceContext;
ingo@1376: import de.intevation.artifacts.common.utils.XMLUtils;
ingo@1376: 
ingo@1376: import de.intevation.flys.client.shared.model.MapConfig;
ingo@1376: 
ingo@1376: 
ingo@1376: public class MapHelper {
ingo@1376: 
ingo@1376:     private static final Logger logger = Logger.getLogger(MapHelper.class);
ingo@1376: 
ingo@1376: 
ingo@1376:     public static final String XPATH_SRID =
ingo@1376:         "/art:floodmap/art:srid/text()";
ingo@1376: 
ingo@1376:     public static final String XPATH_MAX_EXTENT =
ingo@1376:         "/art:floodmap/art:maxExtent/text()";
ingo@1376: 
ingo@1376:     public static final String XPATH_INITIAL_EXTENT =
ingo@1376:         "/art:floodmap/art:initialExtent/text()";
ingo@1376: 
ingo@1376: 
ingo@1376:     private MapHelper() {
ingo@1376:     }
ingo@1376: 
ingo@1376: 
ingo@1376:     public static MapConfig parseConfig(Document raw) {
ingo@1376:         logger.debug("MapHelper.parseConfig");
ingo@1376: 
sascha@2503:         if (logger.isDebugEnabled()) {
sascha@2503:             logger.debug(XMLUtils.toString(raw));
sascha@2503:         }
ingo@1376: 
ingo@1376:         MapConfig config = new MapConfig();
ingo@1376: 
ingo@1376:         setSrid(config, raw);
ingo@1376:         setMaxExtent(config, raw);
ingo@1376:         setInitialExtent(config, raw);
ingo@1376: 
ingo@1376:         return config;
ingo@1376:     }
ingo@1376: 
ingo@1376: 
ingo@1376:     protected static void setSrid(MapConfig config, Document raw) {
ingo@1376:         String srid = (String) XMLUtils.xpathString(
ingo@1376:             raw,
ingo@1376:             XPATH_SRID,
ingo@1376:             ArtifactNamespaceContext.INSTANCE);
ingo@1376: 
ingo@1376:         logger.debug("Found srid: '" + srid + "'");
ingo@1376: 
ingo@1376:         if (srid != null && srid.length() > 0) {
ingo@1376:             logger.debug("Set srid: '" + srid + "'");
ingo@1376:             config.setSrid(srid);
ingo@1376:         }
ingo@1376:     }
ingo@1376: 
ingo@1376: 
ingo@1376:     protected static void setMaxExtent(MapConfig config, Document raw) {
ingo@1376:         String maxExtent = (String) XMLUtils.xpathString(
ingo@1376:             raw,
ingo@1376:             XPATH_MAX_EXTENT,
ingo@1376:             ArtifactNamespaceContext.INSTANCE);
ingo@1376: 
ingo@1376:         logger.debug("Found max extent: '" + maxExtent + "'");
ingo@1376: 
ingo@1376:         if (maxExtent != null && maxExtent.length() > 0) {
ingo@1376:             logger.debug("Set max extent: '" + maxExtent + "'");
ingo@1376:             config.setMaxExtent(maxExtent);
ingo@1376:         }
ingo@1376:     }
ingo@1376: 
ingo@1376: 
ingo@1376:     protected static void setInitialExtent(MapConfig config, Document raw) {
ingo@1376:         String initialExtent = (String) XMLUtils.xpathString(
ingo@1376:             raw,
ingo@1376:             XPATH_INITIAL_EXTENT,
ingo@1376:             ArtifactNamespaceContext.INSTANCE);
ingo@1376: 
ingo@1376:         if (initialExtent != null && initialExtent.length() > 0) {
ingo@1376:             logger.debug("Set initial extent: '" + initialExtent + "'");
ingo@1376:             config.setInitialExtent(initialExtent);
ingo@1376:         }
ingo@1376:     }
ingo@1376: }
ingo@1376: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :