Mercurial > dive4elements > river
changeset 1926:fde3db5e68e8
Added a new Artifact to enable users to add external WMS layers to floodmaps.
flys-artifacts/trunk@3302 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 22 Nov 2011 20:04:46 +0000 |
parents | 01f2473e362d |
children | 1f90fdd4fa04 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java |
diffstat | 6 files changed, 265 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Nov 22 14:00:55 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Nov 22 20:04:46 2011 +0000 @@ -1,3 +1,21 @@ +2011-11-22 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java: New. + This Artifact is used to allow users adding external WMS layers to their + floodmaps. An ExternalWMSArtifact stores an URL of a WMS, the name and the + title of the WMS layer. The internal State extends WMSBackgroundState. + + * doc/conf/conf.xml: Registered the ExternalWMSArtifact. + + * src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java: Added a + new type "floodmap.externalwms" which is used by the ExternalWMSArtifact. + + * doc/conf/artifacts/winfo.xml: Allowed the "floodmap.externalwms" facet for + floodmaps. + + * src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java: + Some refactoring to allow easier subclassing. + 2011-11-22 Felix Wolfsteller <felix.wolfsteller@intevation.de> Fixed flys/411.
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml Tue Nov 22 14:00:55 2011 +0000 +++ b/flys-artifacts/doc/conf/artifacts/winfo.xml Tue Nov 22 20:04:46 2011 +0000 @@ -386,6 +386,7 @@ <facet name="floodmap.lines"/> <facet name="floodmap.buildings"/> <facet name="floodmap.fixpoints"/> + <facet name="floodmap.externalwms"/> </facets> </outputmode> <outputmode name="wsplgen_report" description="output.wsplgen_report" mime-type="text/xml" type="report">
--- a/flys-artifacts/doc/conf/conf.xml Tue Nov 22 14:00:55 2011 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Tue Nov 22 20:04:46 2011 +0000 @@ -44,6 +44,9 @@ <artifact-factory name="wmsbackground" description="Factory to create an artifact to be used in WINFO" ttl="3600000" artifact="de.intevation.flys.artifacts.WMSBackgroundArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory> + <artifact-factory name="externalwmsfactory" description="Factory to create an artifact to be used in Floodmaps to display external WMS layers" + ttl="3600000" + artifact="de.intevation.flys.artifacts.ExternalWMSArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory> <artifact-factory name="annotations" description="Factory to create an artifact to access Annotations for Points at rivers" ttl="3600000" artifact="de.intevation.flys.artifacts.AnnotationArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java Tue Nov 22 20:04:46 2011 +0000 @@ -0,0 +1,172 @@ +package de.intevation.flys.artifacts; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactFactory; +import de.intevation.artifacts.CallMeta; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifactdatabase.data.DefaultStateData; +import de.intevation.artifactdatabase.state.DefaultOutput; +import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifactdatabase.state.State; + +import de.intevation.flys.artifacts.states.WMSBackgroundState; + + +public class ExternalWMSArtifact extends StaticFLYSArtifact { + + public static final String XPATH_IDS = "/art:action/art:ids/@value"; + + public static final String NAME = "external_wms"; + + private static final Logger logger = + Logger.getLogger(ExternalWMSArtifact.class); + + + @Override + public String getName() { + return NAME; + } + + + @Override + public void setup( + String identifier, + ArtifactFactory factory, + Object context, + CallMeta callMeta, + Document data) + { + logger.info("ExternalWMSArtifact.setup"); + + super.setup(identifier, factory, context, callMeta, data); + + String ids = XMLUtils.xpathString( + data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); + + if (ids != null && ids.length() > 0) { + addData("ids", new DefaultStateData("ids", null, null, ids)); + } + else { + throw new IllegalArgumentException("No attribute 'ids' found!"); + } + + List<Facet> fs = new ArrayList<Facet>(); + + WMSBackgroundState s = (WMSBackgroundState) getCurrentState(context); + s.computeInit(this, hash(), context, callMeta, fs); + + if (!fs.isEmpty()) { + facets.put(getCurrentStateId(), fs); + } + } + + + @Override + protected void initialize( + Artifact artifact, + Object context, + CallMeta callMeta) + { + // do nothing + } + + + @Override + public State getCurrentState(Object cc) { + State s = new ExternalWMSState(this); + + List<Facet> fs = facets.get(getCurrentStateId()); + + DefaultOutput o = new DefaultOutput( + "floodmap", + "floodmap", + "image/png", + fs, + "map"); + + s.getOutputs().add(o); + + return s; + } + + + /** + * Get a list containing the one and only State. + * @param context ignored. + * @return list with one and only state. + */ + @Override + protected List<State> getStates(Object context) { + ArrayList<State> states = new ArrayList<State>(); + states.add(getCurrentState(context)); + + return states; + } + + + public static class ExternalWMSState extends WMSBackgroundState { + + protected ExternalWMSArtifact artifact; + + protected String ids; + + + public ExternalWMSState(ExternalWMSArtifact artifact) { + super(); + this.artifact = artifact; + } + + protected String getIds() { + if (ids == null || ids.length() == 0) { + ids = artifact.getDataAsString("ids"); + } + + return ids; + } + + @Override + protected String getFacetType() { + return FLOODMAP_EXTERNAL_WMS; + } + + @Override + protected String getSrid() { + return ""; + } + + @Override + protected String getUrl() { + String ids = getIds(); + String[] parts = ids.split(";"); + + return parts[0]; + } + + @Override + protected String getLayer() { + String ids = getIds(); + String[] parts = ids.split(";"); + + return parts[1]; + } + + @Override + protected String getTitle(CallMeta meta) { + String ids = getIds(); + String[] parts = ids.split(";"); + + return parts[2]; + } + } // end of class ExternalWMSState +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java Tue Nov 22 14:00:55 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java Tue Nov 22 20:04:46 2011 +0000 @@ -26,6 +26,7 @@ String FLOODMAP_LINES = "floodmap.lines"; String FLOODMAP_BUILDINGS = "floodmap.buildings"; String FLOODMAP_FIXPOINTS = "floodmap.fixpoints"; + String FLOODMAP_EXTERNAL_WMS = "floodmap.externalwms"; String DISCHARGE_LONGITUDINAL_W = "discharge_longitudinal_section.w"; String DISCHARGE_LONGITUDINAL_Q = "discharge_longitudinal_section.q";
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java Tue Nov 22 14:00:55 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java Tue Nov 22 20:04:46 2011 +0000 @@ -42,6 +42,10 @@ protected String layer; protected String srid; + protected Document cfg; + + protected Map<String, String> variables; + private static final Logger logger = Logger.getLogger(WMSBackgroundState.class); @@ -64,34 +68,14 @@ ) { logger.debug("WMSBackgroundState.computeInit()"); - if (url == null || layer == null) { - Document cfg = Config.getConfig(); - - String river = artifact.getDataAsString("river"); - - Map<String, String> variables = new HashMap<String, String>(); - variables.put("name", river); + initVariables(artifact); - srid = (String) XMLUtils.xpath( - cfg, - XPATH_SRID, - XPathConstants.STRING, - null, - variables); - - url = (String) XMLUtils.xpath( - cfg, - XPATH_WMS_URL, - XPathConstants.STRING, - null, - variables); - - layer = (String) XMLUtils.xpath( - cfg, - XPATH_WMS_LAYER, - XPathConstants.STRING, - null, - variables); + 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) { @@ -103,8 +87,8 @@ WMSLayerFacet facet = new WMSLayerFacet( 0, - FLOODMAP_WMSBACKGROUND, - Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION), + getFacetType(), + getTitle(meta), ComputeType.INIT, getID(), hash, url); @@ -116,5 +100,62 @@ 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 :