root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / WMSDataSourceAdapter.java @ 1412
History | View | Annotate | Download (15.8 KB)
1 |
/*
|
---|---|
2 |
* Created on 09-sep-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.gui; |
48 |
|
49 |
import java.awt.geom.Rectangle2D; |
50 |
import java.io.IOException; |
51 |
import java.net.URL; |
52 |
import java.util.ArrayList; |
53 |
|
54 |
import org.exolab.castor.xml.ValidationException; |
55 |
|
56 |
import com.iver.cit.gvsig.gui.wms.LayerInfo; |
57 |
import com.iver.cit.gvsig.gui.wms.WizardData; |
58 |
import com.iver.cit.gvsig.gui.wms.WizardDataSource; |
59 |
import com.iver.wmsclient.UnsupportedVersionException; |
60 |
import com.iver.wmsclient.WMSClient; |
61 |
import com.iver.wmsclient.WMSClientFactory; |
62 |
import com.iver.wmsclient.wms_1_0_0.capabilities.Format; |
63 |
import com.iver.wmsclient.wms_1_0_0.capabilities.Layer; |
64 |
import com.iver.wmsclient.wms_1_0_0.capabilities.Name; |
65 |
import com.iver.wmsclient.wms_1_0_0.capabilities.SRS; |
66 |
import com.iver.wmsclient.wms_1_0_0.capabilities.WMT_MS_Capabilities; |
67 |
|
68 |
|
69 |
/**
|
70 |
* Adapta las capa wms de Fmap a los datasource del WMSWizard
|
71 |
*
|
72 |
* @author Fernando Gonz?lez Cort?s
|
73 |
*/
|
74 |
public class WMSDataSourceAdapter implements WizardDataSource { |
75 |
private WMSClient cliente;
|
76 |
|
77 |
/**
|
78 |
* M?todo detalles para la versi?n 1.0.0
|
79 |
*
|
80 |
* @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
|
81 |
*/
|
82 |
private WizardData detalles_1_0_0(WMT_MS_Capabilities cap) {
|
83 |
WizardData data = new WizardData();
|
84 |
|
85 |
data.setTitle(cap.getService().getTitle().getContent()); |
86 |
data.setAbstract(cap.getService().getAbstract().getContent()); |
87 |
|
88 |
Format f = cap.getCapability().getRequest().getMap().getFormat();
|
89 |
ArrayList formatos = new ArrayList(); |
90 |
|
91 |
if (f.getGIF() != null) { |
92 |
formatos.add("image/gif");
|
93 |
} |
94 |
|
95 |
if (f.getPNG() != null) { |
96 |
formatos.add("image/png");
|
97 |
} |
98 |
|
99 |
if (f.getJPEG() != null) { |
100 |
formatos.add("image/jpeg");
|
101 |
} |
102 |
|
103 |
if (f.getTIFF() != null) { |
104 |
formatos.add("image/tiff");
|
105 |
} |
106 |
|
107 |
data.setFormats((String[]) formatos.toArray(new String[0])); |
108 |
|
109 |
Layer l = cap.getCapability().getLayer(); |
110 |
|
111 |
LayerInfo root = new LayerInfo();
|
112 |
root.text = l.getTitle().getContent(); |
113 |
|
114 |
Name name = l.getName();
|
115 |
|
116 |
if (name != null) { |
117 |
root.name = name.getContent(); |
118 |
} |
119 |
|
120 |
SRS srs = l.getSRS(); |
121 |
|
122 |
if (srs != null) { |
123 |
root.addSRS(l.getSRS().getContent()); |
124 |
} |
125 |
|
126 |
rellena_1_0_0((LayerInfo) root, l); |
127 |
|
128 |
data.setLayer(root); |
129 |
|
130 |
return data;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* M?todo detalles para la versi?n 1.1.0
|
135 |
*
|
136 |
* @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
|
137 |
*/
|
138 |
private WizardData detalles_1_1_0(
|
139 |
com.iver.wmsclient.wms_1_1_0.capabilities.WMT_MS_Capabilities cap) { |
140 |
WizardData data = new WizardData();
|
141 |
|
142 |
data.setTitle(cap.getService().getTitle().getContent()); |
143 |
data.setAbstract(cap.getService().getAbstract().getContent()); |
144 |
|
145 |
com.iver.wmsclient.wms_1_1_0.capabilities.Format[] f = cap.getCapability()
|
146 |
.getRequest() |
147 |
.getGetMap() |
148 |
.getFormat(); |
149 |
ArrayList formatos = new ArrayList(); |
150 |
|
151 |
for (int i = 0; i < f.length; i++) { |
152 |
if (isValidFormat(f[i].getContent())) {
|
153 |
formatos.add(f[i].getContent()); |
154 |
} |
155 |
} |
156 |
|
157 |
data.setFormats((String[]) formatos.toArray(new String[0])); |
158 |
|
159 |
com.iver.wmsclient.wms_1_1_0.capabilities.Layer l = cap.getCapability() |
160 |
.getLayer(); |
161 |
|
162 |
LayerInfo root = new LayerInfo();
|
163 |
root.text = l.getTitle().getContent(); |
164 |
|
165 |
com.iver.wmsclient.wms_1_1_0.capabilities.Name name = l.getName(); |
166 |
|
167 |
if (name != null) { |
168 |
root.name = name.getContent(); |
169 |
} |
170 |
|
171 |
com.iver.wmsclient.wms_1_1_0.capabilities.SRS srs = l.getSRS(); |
172 |
|
173 |
if (srs != null) { |
174 |
root.addSRS(l.getSRS().getContent()); |
175 |
} |
176 |
|
177 |
rellena_1_1_0((LayerInfo) root, l); |
178 |
|
179 |
data.setLayer(root); |
180 |
|
181 |
return data;
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* M?todo detalles para la versi?n 1.3.0
|
186 |
*
|
187 |
* @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
|
188 |
*/
|
189 |
private WizardData detalles_1_3_0(
|
190 |
com.iver.wmsclient.wms_1_3_0.capabilities.WMS_Capabilities cap) { |
191 |
WizardData data = new WizardData();
|
192 |
|
193 |
data.setTitle(cap.getService().getTitle().getContent()); |
194 |
data.setAbstract(cap.getService().getAbstract().getContent()); |
195 |
|
196 |
com.iver.wmsclient.wms_1_3_0.capabilities.Format[] f = cap.getCapability()
|
197 |
.getRequest() |
198 |
.getGetMap() |
199 |
.getFormat(); |
200 |
ArrayList formatos = new ArrayList(); |
201 |
|
202 |
for (int i = 0; i < f.length; i++) { |
203 |
if (isValidFormat(f[i].getContent())) {
|
204 |
formatos.add(f[i].getContent()); |
205 |
} |
206 |
} |
207 |
|
208 |
data.setFormats((String[]) formatos.toArray(new String[0])); |
209 |
|
210 |
com.iver.wmsclient.wms_1_3_0.capabilities.Layer l = cap.getCapability() |
211 |
.getLayer(); |
212 |
|
213 |
LayerInfo root = new LayerInfo();
|
214 |
root.text = l.getTitle().getContent(); |
215 |
|
216 |
com.iver.wmsclient.wms_1_3_0.capabilities.Name name = l.getName(); |
217 |
|
218 |
if (name != null) { |
219 |
root.name = name.getContent(); |
220 |
} |
221 |
|
222 |
String[] srs = l.getCRS(); |
223 |
|
224 |
if (srs != null) { |
225 |
for (int i = 0; i < srs.length; i++) { |
226 |
root.addSRS(srs[i]); |
227 |
} |
228 |
} |
229 |
|
230 |
rellena_1_3_0((LayerInfo) root, l); |
231 |
|
232 |
data.setLayer(root); |
233 |
|
234 |
return data;
|
235 |
} |
236 |
|
237 |
/**
|
238 |
* M?todo detalles para la versi?n 1.1.1
|
239 |
*
|
240 |
* @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
|
241 |
*/
|
242 |
private WizardData detalles_1_1_1(
|
243 |
com.iver.wmsclient.wms_1_1_1.capabilities.WMT_MS_Capabilities cap) { |
244 |
WizardData data = new WizardData();
|
245 |
|
246 |
data.setTitle(cap.getService().getTitle().getContent()); |
247 |
if (cap.getService().getAbstract() != null) |
248 |
data.setAbstract(cap.getService().getAbstract().getContent()); |
249 |
|
250 |
com.iver.wmsclient.wms_1_1_1.capabilities.Format[] f = cap.getCapability()
|
251 |
.getRequest() |
252 |
.getGetMap() |
253 |
.getFormat(); |
254 |
ArrayList formatos = new ArrayList(); |
255 |
|
256 |
for (int i = 0; i < f.length; i++) { |
257 |
if (isValidFormat(f[i].getContent())) {
|
258 |
formatos.add(f[i].getContent()); |
259 |
} |
260 |
} |
261 |
|
262 |
data.setFormats((String[]) formatos.toArray(new String[0])); |
263 |
|
264 |
com.iver.wmsclient.wms_1_1_1.capabilities.Layer l = cap.getCapability() |
265 |
.getLayer(); |
266 |
|
267 |
LayerInfo root = new LayerInfo();
|
268 |
root.text = l.getTitle().getContent(); |
269 |
|
270 |
com.iver.wmsclient.wms_1_1_1.capabilities.Name name = l.getName(); |
271 |
|
272 |
if (name != null) { |
273 |
root.name = name.getContent(); |
274 |
} |
275 |
|
276 |
com.iver.wmsclient.wms_1_1_1.capabilities.SRS[] srs = l.getSRS();
|
277 |
|
278 |
if (srs != null) { |
279 |
for (int i = 0; i < srs.length; i++) { |
280 |
root.addSRS(srs[i].getContent()); |
281 |
} |
282 |
} |
283 |
|
284 |
rellena_1_1_1((LayerInfo) root, l); |
285 |
|
286 |
data.setLayer(root); |
287 |
|
288 |
return data;
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* M?todo para saber los formatos que admite la aplicaci?n
|
293 |
*
|
294 |
* @param format cadena con el formato a validar
|
295 |
*
|
296 |
* @return true si soportamos dicho formato y false en
|
297 |
* caso contrario
|
298 |
*/
|
299 |
private boolean isValidFormat(String format) { |
300 |
if (format.equalsIgnoreCase("image/png") || |
301 |
format.equalsIgnoreCase("image/jpg") ||
|
302 |
format.equalsIgnoreCase("image/tiff") ||
|
303 |
format.equalsIgnoreCase("image/jpeg") ||
|
304 |
format.equalsIgnoreCase("image/tif") ||
|
305 |
format.equalsIgnoreCase("image/gif")) {
|
306 |
return true; |
307 |
} |
308 |
|
309 |
return false; |
310 |
} |
311 |
|
312 |
/**
|
313 |
* Genera la jerarquia de capas para la versi?n 1.0.0
|
314 |
*
|
315 |
* @param nodo nodo raiz de la jerarqu?a que hay que generar
|
316 |
* @param layer objeto layer de la respuesta del servidor
|
317 |
*/
|
318 |
private void rellena_1_0_0(LayerInfo nodo, Layer layer) { |
319 |
for (int i = 0; i < layer.getLayerCount(); i++) { |
320 |
LayerInfo nuevo = new LayerInfo();
|
321 |
nuevo.text = layer.getLayer(i).getTitle().getContent(); |
322 |
|
323 |
Name name = layer.getLayer(i).getName();
|
324 |
|
325 |
if (name != null) { |
326 |
nuevo.name = name.getContent(); |
327 |
} |
328 |
|
329 |
SRS srs = layer.getLayer(i).getSRS(); |
330 |
|
331 |
if (srs != null) { |
332 |
nuevo.addSRS(srs.getContent()); |
333 |
} |
334 |
|
335 |
nuevo.queryable = layer.getLayer(i).getQueryable().toString() |
336 |
.equals("1");
|
337 |
|
338 |
nodo.hijos.add(nuevo); |
339 |
nuevo.padre = nodo; |
340 |
rellena_1_0_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i)); |
341 |
} |
342 |
} |
343 |
|
344 |
/**
|
345 |
* Genera la jerarquia de capas para la versi?n 1.1.0
|
346 |
*
|
347 |
* @param nodo nodo raiz de la jerarqu?a que hay que generar
|
348 |
* @param layer objeto layer de la respuesta del servidor
|
349 |
*/
|
350 |
private void rellena_1_1_0(LayerInfo nodo, |
351 |
com.iver.wmsclient.wms_1_1_0.capabilities.Layer layer) { |
352 |
for (int i = 0; i < layer.getLayerCount(); i++) { |
353 |
LayerInfo nuevo = new LayerInfo();
|
354 |
nuevo.text = layer.getLayer(i).getTitle().getContent(); |
355 |
|
356 |
com.iver.wmsclient.wms_1_1_0.capabilities.Name name = layer.getLayer(i) |
357 |
.getName(); |
358 |
|
359 |
if (name != null) { |
360 |
nuevo.name = name.getContent(); |
361 |
} |
362 |
|
363 |
com.iver.wmsclient.wms_1_1_0.capabilities.SRS srs = layer.getLayer(i) |
364 |
.getSRS(); |
365 |
|
366 |
if (srs != null) { |
367 |
nuevo.addSRS(srs.getContent()); |
368 |
} |
369 |
|
370 |
nuevo.queryable = layer.getLayer(i).getQueryable().toString() |
371 |
.equals("1");
|
372 |
|
373 |
nodo.hijos.add(nuevo); |
374 |
nuevo.padre = nodo; |
375 |
rellena_1_1_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i)); |
376 |
} |
377 |
} |
378 |
|
379 |
/**
|
380 |
* Genera la jerarquia de capas para la versi?n 1.1.1
|
381 |
*
|
382 |
* @param nodo nodo raiz de la jerarqu?a que hay que generar
|
383 |
* @param layer objeto layer de la respuesta del servidor
|
384 |
*/
|
385 |
private void rellena_1_1_1(LayerInfo nodo, |
386 |
com.iver.wmsclient.wms_1_1_1.capabilities.Layer layer) { |
387 |
for (int i = 0; i < layer.getLayerCount(); i++) { |
388 |
LayerInfo nuevo = new LayerInfo();
|
389 |
nuevo.text = layer.getLayer(i).getTitle().getContent(); |
390 |
|
391 |
com.iver.wmsclient.wms_1_1_1.capabilities.Name name = layer.getLayer(i) |
392 |
.getName(); |
393 |
|
394 |
if (name != null){ |
395 |
nuevo.name = name.getContent(); |
396 |
} |
397 |
|
398 |
com.iver.wmsclient.wms_1_1_1.capabilities.SRS[] srs = layer.getLayer(i)
|
399 |
.getSRS(); |
400 |
|
401 |
if (srs != null) { |
402 |
for (int j = 0; j < srs.length; j++) { |
403 |
nuevo.addSRS(srs[j].getContent()); |
404 |
} |
405 |
} |
406 |
|
407 |
nuevo.queryable = layer.getLayer(i).getQueryable().toString() |
408 |
.equals("1");
|
409 |
|
410 |
nodo.hijos.add(nuevo); |
411 |
nuevo.padre = nodo; |
412 |
rellena_1_1_1((LayerInfo) nodo.hijos.get(i), layer.getLayer(i)); |
413 |
} |
414 |
} |
415 |
|
416 |
/**
|
417 |
* Genera la jerarquia de capas para la versi?n 1.3.0
|
418 |
*
|
419 |
* @param nodo nodo raiz de la jerarqu?a que hay que generar
|
420 |
* @param layer objeto layer de la respuesta del servidor
|
421 |
*/
|
422 |
private void rellena_1_3_0(LayerInfo nodo, |
423 |
com.iver.wmsclient.wms_1_3_0.capabilities.Layer layer) { |
424 |
for (int i = 0; i < layer.getLayerCount(); i++) { |
425 |
LayerInfo nuevo = new LayerInfo();
|
426 |
nuevo.text = layer.getLayer(i).getTitle().getContent(); |
427 |
|
428 |
com.iver.wmsclient.wms_1_3_0.capabilities.Name name = layer.getLayer(i) |
429 |
.getName(); |
430 |
|
431 |
if (name != null) { |
432 |
nuevo.name = name.getContent(); |
433 |
} |
434 |
|
435 |
String[] srs = layer.getLayer(i).getCRS(); |
436 |
|
437 |
if (srs != null) { |
438 |
for (int j = 0; j < srs.length; j++) { |
439 |
nuevo.addSRS(srs[j]); |
440 |
} |
441 |
} |
442 |
|
443 |
nuevo.queryable = layer.getLayer(i).getQueryable(); |
444 |
|
445 |
nodo.hijos.add(nuevo); |
446 |
nuevo.padre = nodo; |
447 |
rellena_1_3_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i)); |
448 |
} |
449 |
} |
450 |
|
451 |
/**
|
452 |
* @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
|
453 |
*/
|
454 |
public WizardData detalles(URL host) |
455 |
throws IllegalStateException, ValidationException, |
456 |
UnsupportedVersionException, IOException {
|
457 |
cliente = WMSClientFactory.getClient(host); |
458 |
|
459 |
com.iver.wmsclient.Capabilities c = cliente.getCapabilities(host); |
460 |
|
461 |
String version = c.getVersion();
|
462 |
|
463 |
if (version.equals("1.0.0")) { |
464 |
return detalles_1_0_0((WMT_MS_Capabilities) c.getRoot());
|
465 |
} else if (version.equals("1.1.0")) { |
466 |
return detalles_1_1_0((com.iver.wmsclient.wms_1_1_0.capabilities.WMT_MS_Capabilities) c.getRoot());
|
467 |
} else if (version.equals("1.1.1")) { |
468 |
return detalles_1_1_1((com.iver.wmsclient.wms_1_1_1.capabilities.WMT_MS_Capabilities) c.getRoot());
|
469 |
} else if (version.equals("1.3.0")) { |
470 |
return detalles_1_3_0((com.iver.wmsclient.wms_1_3_0.capabilities.WMS_Capabilities) c.getRoot());
|
471 |
} else {
|
472 |
throw new UnsupportedVersionException(version); |
473 |
} |
474 |
} |
475 |
|
476 |
/**
|
477 |
* @see com.iver.cit.gvsig.gui.wms.WizardDataSource#getBoundingBox(java.lang.String,
|
478 |
* java.lang.String)
|
479 |
*/
|
480 |
public Rectangle2D getBoundingBox(String[] layerName, String srs) { |
481 |
return cliente.getBoundingBox(layerName, srs);
|
482 |
} |
483 |
} |