ingo@942: package de.intevation.flys.artifacts.states; ingo@942: ingo@1063: import java.util.HashMap; ingo@942: import java.util.List; ingo@1063: import java.util.Map; ingo@1063: ingo@1063: import javax.xml.xpath.XPathConstants; ingo@942: ingo@942: import org.apache.log4j.Logger; ingo@1063: import org.w3c.dom.Document; ingo@956: import org.w3c.dom.Node; ingo@956: ingo@3302: import de.intevation.artifactdatabase.state.Facet; ingo@942: import de.intevation.artifacts.CallMeta; ingo@956: import de.intevation.artifacts.common.utils.Config; ingo@1063: import de.intevation.artifacts.common.utils.XMLUtils; ingo@942: import de.intevation.flys.artifacts.FLYSArtifact; ingo@3302: import de.intevation.flys.artifacts.model.map.WMSLayerFacet; ingo@954: import de.intevation.flys.artifacts.resources.Resources; ingo@942: ingo@942: ingo@942: public class WMSBackgroundState extends OutputState { ingo@942: ingo@954: public static final String I18N_DESCRIPTION = "floodmap.wmsbackground"; ingo@954: ingo@1066: public static final String XPATH_SRID = ingo@1066: "/artifact-database/floodmap/river[@name=$name]/srid/@value"; ingo@1066: ingo@956: public static final String XPATH_WMS_URL = ingo@1063: "/artifact-database/floodmap/river[@name=$name]/background-wms/@url"; ingo@956: ingo@956: public static final String XPATH_WMS_LAYER = ingo@1063: "/artifact-database/floodmap/river[@name=$name]/background-wms/@layers"; ingo@956: ingo@956: ingo@956: protected String url; ingo@956: protected String layer; ingo@1066: protected String srid; ingo@956: ingo@1926: protected Document cfg; ingo@1926: ingo@1926: protected Map variables; ingo@1926: ingo@954: ingo@942: private static final Logger logger = Logger.getLogger(WMSBackgroundState.class); ingo@942: ingo@956: ingo@956: @Override ingo@956: public void setup(Node config) { ingo@956: super.setup(config); ingo@956: ingo@956: logger.debug("WMSBackgroundState.setup()"); ingo@956: } ingo@956: ingo@956: ingo@942: @Override ingo@942: public Object computeInit( ingo@942: FLYSArtifact artifact, ingo@942: String hash, ingo@958: Object context, ingo@942: CallMeta meta, ingo@942: List facets ingo@942: ) { ingo@942: logger.debug("WMSBackgroundState.computeInit()"); ingo@942: ingo@1926: initVariables(artifact); ingo@1063: ingo@1926: if (url == null || layer == null) { ingo@1926: // XXX I don't remember why 'srid', 'url' and 'layer' are member ingo@1926: // variables. I think the reason was buffering those values. ingo@1926: srid = getSrid(); ingo@1926: url = getUrl(); ingo@1926: layer = getLayer(); ingo@1063: } ingo@1063: ingo@1063: if (url == null || layer == null) { ingo@956: logger.warn("No background layers currently configured:"); ingo@956: logger.warn("... add config for WMS url: " + XPATH_WMS_URL); ingo@956: logger.warn("... add config for WMS layer: " + XPATH_WMS_LAYER); ingo@956: return null; ingo@956: } ingo@956: ingo@942: WMSLayerFacet facet = new WMSLayerFacet( ingo@942: 0, ingo@1926: getFacetType(), ingo@1926: getTitle(meta), ingo@942: ComputeType.INIT, ingo@942: getID(), hash, ingo@956: url); ingo@942: ingo@956: facet.addLayer(layer); ingo@1066: facet.setSrid(srid); ingo@942: ingo@942: facets.add(facet); ingo@942: ingo@942: return null; ingo@942: } ingo@1926: ingo@1926: ingo@1926: protected Document getConfig() { ingo@1926: if (cfg == null) { ingo@1926: cfg = Config.getConfig(); ingo@1926: } ingo@1926: ingo@1926: return cfg; ingo@1926: } ingo@1926: ingo@1926: ingo@1926: protected void initVariables(FLYSArtifact artifact) { ingo@1926: String river = artifact.getDataAsString("river"); ingo@1926: ingo@1926: variables = new HashMap(); ingo@1926: variables.put("name", river); ingo@1926: } ingo@1926: ingo@1926: ingo@1926: protected String getFacetType() { ingo@1926: return FLOODMAP_WMSBACKGROUND; ingo@1926: } ingo@1926: ingo@1926: ingo@1926: protected String getSrid() { ingo@1926: return (String) XMLUtils.xpath( ingo@1926: getConfig(), ingo@1926: XPATH_SRID, ingo@1926: XPathConstants.STRING, ingo@1926: null, ingo@1926: variables); ingo@1926: } ingo@1926: ingo@1926: ingo@1926: protected String getUrl() { ingo@1926: return (String) XMLUtils.xpath( ingo@1926: getConfig(), ingo@1926: XPATH_WMS_URL, ingo@1926: XPathConstants.STRING, ingo@1926: null, ingo@1926: variables); ingo@1926: } ingo@1926: ingo@1926: ingo@1926: protected String getLayer() { ingo@1926: return (String) XMLUtils.xpath( ingo@1926: getConfig(), ingo@1926: XPATH_WMS_LAYER, ingo@1926: XPathConstants.STRING, ingo@1926: null, ingo@1926: variables); ingo@1926: } ingo@1926: ingo@1926: ingo@1926: protected String getTitle(CallMeta meta) { ingo@1926: return Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION); ingo@1926: } ingo@942: } ingo@942: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :