Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java @ 2424:092e519ff461
merged flys-artifacts/2.6.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:26 +0200 |
parents | fde3db5e68e8 |
children | 453d2d0c4258 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java Fri Sep 28 12:14:26 2012 +0200 @@ -0,0 +1,161 @@ +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; + + protected Document cfg; + + protected Map<String, String> variables; + + + 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()"); + + initVariables(artifact); + + if (url == null || layer == null) { + // XXX I don't remember why 'srid', 'url' and 'layer' are member + // variables. I think the reason was buffering those values. + srid = getSrid(); + url = getUrl(); + layer = getLayer(); + } + + 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, + getFacetType(), + getTitle(meta), + ComputeType.INIT, + getID(), hash, + url); + + facet.addLayer(layer); + facet.setSrid(srid); + + facets.add(facet); + + return null; + } + + + protected Document getConfig() { + if (cfg == null) { + cfg = Config.getConfig(); + } + + return cfg; + } + + + protected void initVariables(FLYSArtifact artifact) { + String river = artifact.getDataAsString("river"); + + variables = new HashMap<String, String>(); + variables.put("name", river); + } + + + protected String getFacetType() { + return FLOODMAP_WMSBACKGROUND; + } + + + protected String getSrid() { + return (String) XMLUtils.xpath( + getConfig(), + XPATH_SRID, + XPathConstants.STRING, + null, + variables); + } + + + protected String getUrl() { + return (String) XMLUtils.xpath( + getConfig(), + XPATH_WMS_URL, + XPathConstants.STRING, + null, + variables); + } + + + protected String getLayer() { + return (String) XMLUtils.xpath( + getConfig(), + XPATH_WMS_LAYER, + XPathConstants.STRING, + null, + variables); + } + + + protected String getTitle(CallMeta meta) { + return Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :