Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 063b784b60b4 |
children | a2735a4bf75e |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.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 de.intevation.artifacts.Artifact; | |
11 import de.intevation.artifacts.ArtifactFactory; | |
12 import de.intevation.artifacts.CallMeta; | |
13 | |
14 import de.intevation.artifactdatabase.state.DefaultOutput; | |
15 import de.intevation.artifactdatabase.state.Facet; | |
16 import de.intevation.artifactdatabase.state.State; | |
17 | |
18 import de.intevation.flys.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 facets.put(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 = facets.get(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 : |