svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / WMSDataSourceAdapter.java @ 1265
History | View | Annotate | Download (15.7 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 |
data.setAbstract(cap.getService().getAbstract().getContent()); |
248 |
|
249 |
com.iver.wmsclient.wms_1_1_1.capabilities.Format[] f = cap.getCapability()
|
250 |
.getRequest() |
251 |
.getGetMap() |
252 |
.getFormat(); |
253 |
ArrayList formatos = new ArrayList(); |
254 |
|
255 |
for (int i = 0; i < f.length; i++) { |
256 |
if (isValidFormat(f[i].getContent())) {
|
257 |
formatos.add(f[i].getContent()); |
258 |
} |
259 |
} |
260 |
|
261 |
data.setFormats((String[]) formatos.toArray(new String[0])); |
262 |
|
263 |
com.iver.wmsclient.wms_1_1_1.capabilities.Layer l = cap.getCapability() |
264 |
.getLayer(); |
265 |
|
266 |
LayerInfo root = new LayerInfo();
|
267 |
root.text = l.getTitle().getContent(); |
268 |
|
269 |
com.iver.wmsclient.wms_1_1_1.capabilities.Name name = l.getName(); |
270 |
|
271 |
if (name != null) { |
272 |
root.name = name.getContent(); |
273 |
} |
274 |
|
275 |
com.iver.wmsclient.wms_1_1_1.capabilities.SRS[] srs = l.getSRS();
|
276 |
|
277 |
if (srs != null) { |
278 |
for (int i = 0; i < srs.length; i++) { |
279 |
root.addSRS(srs[i].getContent()); |
280 |
} |
281 |
} |
282 |
|
283 |
rellena_1_1_1((LayerInfo) root, l); |
284 |
|
285 |
data.setLayer(root); |
286 |
|
287 |
return data;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* M?todo para saber los formatos que admite la aplicaci?n
|
292 |
*
|
293 |
* @param format cadena con el formato a validar
|
294 |
*
|
295 |
* @return true si soportamos dicho formato y false en
|
296 |
* caso contrario
|
297 |
*/
|
298 |
private boolean isValidFormat(String format) { |
299 |
if (format.equalsIgnoreCase("image/png") || |
300 |
format.equalsIgnoreCase("image/jpg") ||
|
301 |
format.equalsIgnoreCase("image/tiff") ||
|
302 |
format.equalsIgnoreCase("image/jpeg") ||
|
303 |
format.equalsIgnoreCase("image/tif") ||
|
304 |
format.equalsIgnoreCase("image/gif")) {
|
305 |
return true; |
306 |
} |
307 |
|
308 |
return false; |
309 |
} |
310 |
|
311 |
/**
|
312 |
* Genera la jerarquia de capas para la versi?n 1.0.0
|
313 |
*
|
314 |
* @param nodo nodo raiz de la jerarqu?a que hay que generar
|
315 |
* @param layer objeto layer de la respuesta del servidor
|
316 |
*/
|
317 |
private void rellena_1_0_0(LayerInfo nodo, Layer layer) { |
318 |
for (int i = 0; i < layer.getLayerCount(); i++) { |
319 |
LayerInfo nuevo = new LayerInfo();
|
320 |
nuevo.text = layer.getLayer(i).getTitle().getContent(); |
321 |
|
322 |
Name name = layer.getLayer(i).getName();
|
323 |
|
324 |
if (name != null) { |
325 |
nuevo.name = name.getContent(); |
326 |
} |
327 |
|
328 |
SRS srs = layer.getLayer(i).getSRS(); |
329 |
|
330 |
if (srs != null) { |
331 |
nuevo.addSRS(srs.getContent()); |
332 |
} |
333 |
|
334 |
nuevo.queryable = layer.getLayer(i).getQueryable().toString() |
335 |
.equals("1");
|
336 |
|
337 |
nodo.hijos.add(nuevo); |
338 |
nuevo.padre = nodo; |
339 |
rellena_1_0_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i)); |
340 |
} |
341 |
} |
342 |
|
343 |
/**
|
344 |
* Genera la jerarquia de capas para la versi?n 1.1.0
|
345 |
*
|
346 |
* @param nodo nodo raiz de la jerarqu?a que hay que generar
|
347 |
* @param layer objeto layer de la respuesta del servidor
|
348 |
*/
|
349 |
private void rellena_1_1_0(LayerInfo nodo, |
350 |
com.iver.wmsclient.wms_1_1_0.capabilities.Layer layer) { |
351 |
for (int i = 0; i < layer.getLayerCount(); i++) { |
352 |
LayerInfo nuevo = new LayerInfo();
|
353 |
nuevo.text = layer.getLayer(i).getTitle().getContent(); |
354 |
|
355 |
com.iver.wmsclient.wms_1_1_0.capabilities.Name name = layer.getLayer(i) |
356 |
.getName(); |
357 |
|
358 |
if (name != null) { |
359 |
nuevo.name = name.getContent(); |
360 |
} |
361 |
|
362 |
com.iver.wmsclient.wms_1_1_0.capabilities.SRS srs = layer.getLayer(i) |
363 |
.getSRS(); |
364 |
|
365 |
if (srs != null) { |
366 |
nuevo.addSRS(srs.getContent()); |
367 |
} |
368 |
|
369 |
nuevo.queryable = layer.getLayer(i).getQueryable().toString() |
370 |
.equals("1");
|
371 |
|
372 |
nodo.hijos.add(nuevo); |
373 |
nuevo.padre = nodo; |
374 |
rellena_1_1_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i)); |
375 |
} |
376 |
} |
377 |
|
378 |
/**
|
379 |
* Genera la jerarquia de capas para la versi?n 1.1.1
|
380 |
*
|
381 |
* @param nodo nodo raiz de la jerarqu?a que hay que generar
|
382 |
* @param layer objeto layer de la respuesta del servidor
|
383 |
*/
|
384 |
private void rellena_1_1_1(LayerInfo nodo, |
385 |
com.iver.wmsclient.wms_1_1_1.capabilities.Layer layer) { |
386 |
for (int i = 0; i < layer.getLayerCount(); i++) { |
387 |
LayerInfo nuevo = new LayerInfo();
|
388 |
nuevo.text = layer.getLayer(i).getTitle().getContent(); |
389 |
|
390 |
com.iver.wmsclient.wms_1_1_1.capabilities.Name name = layer.getLayer(i) |
391 |
.getName(); |
392 |
|
393 |
if (name != null){ |
394 |
nuevo.name = name.getContent(); |
395 |
} |
396 |
|
397 |
com.iver.wmsclient.wms_1_1_1.capabilities.SRS[] srs = layer.getLayer(i)
|
398 |
.getSRS(); |
399 |
|
400 |
if (srs != null) { |
401 |
for (int j = 0; j < srs.length; j++) { |
402 |
nuevo.addSRS(srs[j].getContent()); |
403 |
} |
404 |
} |
405 |
|
406 |
nuevo.queryable = layer.getLayer(i).getQueryable().toString() |
407 |
.equals("1");
|
408 |
|
409 |
nodo.hijos.add(nuevo); |
410 |
nuevo.padre = nodo; |
411 |
rellena_1_1_1((LayerInfo) nodo.hijos.get(i), layer.getLayer(i)); |
412 |
} |
413 |
} |
414 |
|
415 |
/**
|
416 |
* Genera la jerarquia de capas para la versi?n 1.3.0
|
417 |
*
|
418 |
* @param nodo nodo raiz de la jerarqu?a que hay que generar
|
419 |
* @param layer objeto layer de la respuesta del servidor
|
420 |
*/
|
421 |
private void rellena_1_3_0(LayerInfo nodo, |
422 |
com.iver.wmsclient.wms_1_3_0.capabilities.Layer layer) { |
423 |
for (int i = 0; i < layer.getLayerCount(); i++) { |
424 |
LayerInfo nuevo = new LayerInfo();
|
425 |
nuevo.text = layer.getLayer(i).getTitle().getContent(); |
426 |
|
427 |
com.iver.wmsclient.wms_1_3_0.capabilities.Name name = layer.getLayer(i) |
428 |
.getName(); |
429 |
|
430 |
if (name != null) { |
431 |
nuevo.name = name.getContent(); |
432 |
} |
433 |
|
434 |
String[] srs = layer.getLayer(i).getCRS(); |
435 |
|
436 |
if (srs != null) { |
437 |
for (int j = 0; j < srs.length; j++) { |
438 |
nuevo.addSRS(srs[j]); |
439 |
} |
440 |
} |
441 |
|
442 |
nuevo.queryable = layer.getLayer(i).getQueryable(); |
443 |
|
444 |
nodo.hijos.add(nuevo); |
445 |
nuevo.padre = nodo; |
446 |
rellena_1_3_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i)); |
447 |
} |
448 |
} |
449 |
|
450 |
/**
|
451 |
* @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
|
452 |
*/
|
453 |
public WizardData detalles(URL host) |
454 |
throws IllegalStateException, ValidationException, |
455 |
UnsupportedVersionException, IOException {
|
456 |
cliente = WMSClientFactory.getClient(host); |
457 |
|
458 |
com.iver.wmsclient.Capabilities c = cliente.getCapabilities(host); |
459 |
|
460 |
String version = c.getVersion();
|
461 |
|
462 |
if (version.equals("1.0.0")) { |
463 |
return detalles_1_0_0((WMT_MS_Capabilities) c.getRoot());
|
464 |
} else if (version.equals("1.1.0")) { |
465 |
return detalles_1_1_0((com.iver.wmsclient.wms_1_1_0.capabilities.WMT_MS_Capabilities) c.getRoot());
|
466 |
} else if (version.equals("1.1.1")) { |
467 |
return detalles_1_1_1((com.iver.wmsclient.wms_1_1_1.capabilities.WMT_MS_Capabilities) c.getRoot());
|
468 |
} else if (version.equals("1.3.0")) { |
469 |
return detalles_1_3_0((com.iver.wmsclient.wms_1_3_0.capabilities.WMS_Capabilities) c.getRoot());
|
470 |
} else {
|
471 |
throw new UnsupportedVersionException(version); |
472 |
} |
473 |
} |
474 |
|
475 |
/**
|
476 |
* @see com.iver.cit.gvsig.gui.wms.WizardDataSource#getBoundingBox(java.lang.String,
|
477 |
* java.lang.String)
|
478 |
*/
|
479 |
public Rectangle2D getBoundingBox(String[] layerName, String srs) { |
480 |
return cliente.getBoundingBox(layerName, srs);
|
481 |
} |
482 |
} |