diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java @ 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
children 8afd6a9bb244
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/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 :

http://dive4elements.wald.intevation.org