comparison artifacts/src/main/java/org/dive4elements/river/artifacts/ExternalWMSArtifact.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/ExternalWMSArtifact.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.artifacts;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import org.w3c.dom.Document;
9
10 import org.dive4elements.artifacts.Artifact;
11 import org.dive4elements.artifacts.ArtifactFactory;
12 import org.dive4elements.artifacts.CallMeta;
13
14 import org.dive4elements.artifactdatabase.state.DefaultOutput;
15 import org.dive4elements.artifactdatabase.state.Facet;
16 import org.dive4elements.artifactdatabase.state.State;
17
18 import org.dive4elements.river.artifacts.states.WMSBackgroundState;
19
20
21 public class ExternalWMSArtifact extends StaticFLYSArtifact {
22
23 public static final String NAME = "external_wms";
24
25 private static final Logger logger =
26 Logger.getLogger(ExternalWMSArtifact.class);
27
28
29 @Override
30 public String getName() {
31 return NAME;
32 }
33
34
35 @Override
36 public void setup(
37 String identifier,
38 ArtifactFactory factory,
39 Object context,
40 CallMeta callMeta,
41 Document data)
42 {
43 logger.info("ExternalWMSArtifact.setup");
44
45 super.setup(identifier, factory, context, callMeta, data);
46
47 String ids = getDatacageIDValue(data);
48
49 if (ids != null && ids.length() > 0) {
50 addStringData("ids", ids);
51 }
52 else {
53 throw new IllegalArgumentException("No attribute 'ids' found!");
54 }
55
56 List<Facet> fs = new ArrayList<Facet>();
57
58 WMSBackgroundState s = (WMSBackgroundState) getCurrentState(context);
59 s.computeInit(this, hash(), context, callMeta, fs);
60
61 if (!fs.isEmpty()) {
62 addFacets(getCurrentStateId(), fs);
63 }
64 }
65
66
67 @Override
68 protected void initialize(
69 Artifact artifact,
70 Object context,
71 CallMeta callMeta)
72 {
73 // do nothing
74 }
75
76
77 @Override
78 public State getCurrentState(Object cc) {
79 State s = new ExternalWMSState(this);
80
81 List<Facet> fs = getFacets(getCurrentStateId());
82
83 DefaultOutput o = new DefaultOutput(
84 "floodmap",
85 "floodmap",
86 "image/png",
87 fs,
88 "map");
89
90 s.getOutputs().add(o);
91
92 return s;
93 }
94
95
96 /**
97 * Get a list containing the one and only State.
98 * @param context ignored.
99 * @return list with one and only state.
100 */
101 @Override
102 protected List<State> getStates(Object context) {
103 ArrayList<State> states = new ArrayList<State>();
104 states.add(getCurrentState(context));
105
106 return states;
107 }
108
109
110 public static class ExternalWMSState extends WMSBackgroundState {
111
112 protected ExternalWMSArtifact artifact;
113
114 protected String ids;
115
116
117 public ExternalWMSState(ExternalWMSArtifact artifact) {
118 super();
119 this.artifact = artifact;
120 }
121
122 protected String getIds() {
123 if (ids == null || ids.length() == 0) {
124 ids = artifact.getDataAsString("ids");
125 }
126
127 return ids;
128 }
129
130 @Override
131 protected String getFacetType() {
132 return FLOODMAP_EXTERNAL_WMS;
133 }
134
135 @Override
136 protected String getSrid() {
137 return "";
138 }
139
140 @Override
141 protected String getUrl() {
142 String ids = getIds();
143 String[] parts = ids.split(";");
144
145 return parts[0];
146 }
147
148 @Override
149 protected String getLayer() {
150 String ids = getIds();
151 String[] parts = ids.split(";");
152
153 return parts[1];
154 }
155
156 @Override
157 protected String getTitle(CallMeta meta) {
158 String ids = getIds();
159 String[] parts = ids.split(";");
160
161 return parts[2];
162 }
163 } // end of class ExternalWMSState
164 }
165 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org