Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_WMSv2 / extensions / extWMS / src / com / iver / cit / gvsig / gui / WMSDataSourceAdapter.java @ 3385

History | View | Annotate | Download (18.4 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
import java.util.Vector;
54

    
55
import org.exolab.castor.xml.ValidationException;
56
import org.gvsig.remoteClient.wms.WMSClient;
57
import org.gvsig.remoteClient.wms.WMSLayer;
58
import org.gvsig.remoteClient.wms.WMSProtocolHandler;
59

    
60
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
61
import com.iver.cit.gvsig.gui.wizard.WMSWizardData;
62
import com.iver.cit.gvsig.gui.wizard.WMSWizardDataSource;
63
import com.iver.cit.gvsig.gui.wizards.WizardData;
64

    
65

    
66
/**
67
 * Adapta las capa wms de Fmap a los datasource del WMSWizard
68
 *
69
 * @author Fernando Gonz?lez Cort?s
70
 */
71
public class WMSDataSourceAdapter implements WMSWizardDataSource {
72
    //private WMSClient cliente;
73
        private WMSClient wms;
74
    /**
75
     * M?todo detalles para la versi?n 1.0.0
76
     *
77
     * @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
78
     */
79
    /*private WizardData detalles_1_0_0(WMT_MS_Capabilities cap) {
80
        WizardData data = new WizardData();
81

82
        data.setTitle(cap.getService().getTitle().getContent());
83
        data.setAbstract(cap.getService().getAbstract().getContent());
84

85
        Format f = cap.getCapability().getRequest().getMap().getFormat();
86
        ArrayList formatos = new ArrayList();
87

88
        if (f.getGIF() != null) {
89
            formatos.add("image/gif");
90
        }
91

92
        if (f.getPNG() != null) {
93
            formatos.add("image/png");
94
        }
95

96
        if (f.getJPEG() != null) {
97
            formatos.add("image/jpeg");
98
        }
99

100
        if (f.getTIFF() != null) {
101
            formatos.add("image/tiff");
102
        }
103

104
        data.setFormats((String[]) formatos.toArray(new String[0]));
105

106
        Layer l = cap.getCapability().getLayer();
107

108
        LayerInfo root = new LayerInfo();
109
        root.text = l.getTitle().getContent();
110

111
        Name name = l.getName();
112

113
        if (name != null) {
114
            root.name = name.getContent();
115
        }
116

117
        SRS srs = l.getSRS();
118

119
        if (srs != null) {
120
            root.addSRS(l.getSRS().getContent());
121
        }
122

123
        rellena_1_0_0((LayerInfo) root, l);
124

125
        data.setLayer(root);
126

127
        return data;
128
    }*/
129

    
130
    /**
131
     * M?todo detalles para la versi?n 1.1.0
132
     *
133
     * @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
134
     */
135
    /*private WizardData detalles_1_1_0(
136
        com.iver.wmsclient.wms_1_1_0.capabilities.WMT_MS_Capabilities cap) {
137
        WizardData data = new WizardData();
138

139
        data.setTitle(cap.getService().getTitle().getContent());
140
        data.setAbstract(cap.getService().getAbstract().getContent());
141

142
        com.iver.wmsclient.wms_1_1_0.capabilities.Format[] f = cap.getCapability()
143
                                                                           .getRequest()
144
                                                                           .getGetMap()
145
                                                                           .getFormat();
146
        ArrayList formatos = new ArrayList();
147

148
        for (int i = 0; i < f.length; i++) {
149
            if (isValidFormat(f[i].getContent())) {
150
                formatos.add(f[i].getContent());
151
            }
152
        }
153

154
        data.setFormats((String[]) formatos.toArray(new String[0]));
155

156
        com.iver.wmsclient.wms_1_1_0.capabilities.Layer l = cap.getCapability()
157
                                                                        .getLayer();
158

159
        LayerInfo root = new LayerInfo();
160
        root.text = l.getTitle().getContent();
161

162
        com.iver.wmsclient.wms_1_1_0.capabilities.Name name = l.getName();
163

164
        if (name != null) {
165
            root.name = name.getContent();
166
        }
167

168
        com.iver.wmsclient.wms_1_1_0.capabilities.SRS srs = l.getSRS();
169

170
        if (srs != null) {
171
            root.addSRS(l.getSRS().getContent());
172
        }
173

174
        rellena_1_1_0((LayerInfo) root, l);
175

176
        data.setLayer(root);
177

178
        return data;
179
    }*/
180

    
181
    /**
182
     * M?todo detalles para la versi?n 1.3.0
183
     *
184
     * @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
185
     */
186
    /*private WizardData detalles_1_3_0(
187
        com.iver.wmsclient.wms_1_3_0.capabilities.WMS_Capabilities cap) {
188
        WizardData data = new WizardData();
189

190
        data.setTitle(cap.getService().getTitle().getContent());
191
        data.setAbstract(cap.getService().getAbstract().getContent());
192

193
        com.iver.wmsclient.wms_1_3_0.capabilities.Format[] f = cap.getCapability()
194
                                                                           .getRequest()
195
                                                                           .getGetMap()
196
                                                                           .getFormat();
197
        ArrayList formatos = new ArrayList();
198

199
        for (int i = 0; i < f.length; i++) {
200
            if (isValidFormat(f[i].getContent())) {
201
                formatos.add(f[i].getContent());
202
            }
203
        }
204

205
        data.setFormats((String[]) formatos.toArray(new String[0]));
206

207
        com.iver.wmsclient.wms_1_3_0.capabilities.Layer l = cap.getCapability()
208
                                                                        .getLayer();
209

210
        LayerInfo root = new LayerInfo();
211
        root.text = l.getTitle().getContent();
212

213
        com.iver.wmsclient.wms_1_3_0.capabilities.Name name = l.getName();
214

215
        if (name != null) {
216
            root.name = name.getContent();
217
        }
218

219
        String[] srs = l.getCRS();
220

221
        if (srs != null) {
222
            for (int i = 0; i < srs.length; i++) {
223
                root.addSRS(srs[i]);
224
            }
225
        }
226

227
        rellena_1_3_0((LayerInfo) root, l);
228

229
        data.setLayer(root);
230

231
        return data;
232
    }*/
233

    
234
    /**
235
     * M?todo detalles para la versi?n 1.1.1
236
     *
237
     * @see com.iver.cit.gvsig.gui.wms.WizardDataSource#detalles()
238
     */
239
/*    private WizardData detalles_1_1_1(
240
        com.iver.wmsclient.wms_1_1_1.capabilities.WMT_MS_Capabilities cap) {
241
        WizardData data = new WizardData();
242

243
        data.setTitle(cap.getService().getTitle().getContent());
244
        if (cap.getService().getAbstract() != null)
245
        data.setAbstract(cap.getService().getAbstract().getContent());
246

247
        com.iver.wmsclient.wms_1_1_1.capabilities.Format[] f = cap.getCapability()
248
                                                                           .getRequest()
249
                                                                           .getGetMap()
250
                                                                           .getFormat();
251
        ArrayList formatos = new ArrayList();
252

253
        for (int i = 0; i < f.length; i++) {
254
            if (isValidFormat(f[i].getContent())) {
255
                formatos.add(f[i].getContent());
256
            }
257
        }
258

259
        data.setFormats((String[]) formatos.toArray(new String[0]));
260

261
        com.iver.wmsclient.wms_1_1_1.capabilities.Layer l = cap.getCapability()
262
                                                                        .getLayer();
263

264
        LayerInfo root = new LayerInfo();
265
        root.text = l.getTitle().getContent();
266

267
        com.iver.wmsclient.wms_1_1_1.capabilities.Name name = l.getName();
268

269
        if (name != null) {
270
            root.name = name.getContent();
271
        }
272

273
        com.iver.wmsclient.wms_1_1_1.capabilities.SRS[] srs = l.getSRS();
274

275
        if (srs != null) {
276
            for (int i = 0; i < srs.length; i++) {
277
                root.addSRS(srs[i].getContent());
278
            }
279
        }
280

281
        rellena_1_1_1((LayerInfo) root, l);
282

283
        data.setLayer(root);
284

285
        return data;
286
    }
287
*/
288
    /**
289
     * M?todo para saber los formatos que admite la aplicaci?n
290
     *
291
     * @param format cadena con el formato a validar
292
     *
293
     * @return true si soportamos dicho formato y false en
294
     * caso contrario
295
     */
296
    private boolean isValidFormat(String format) {
297
        if (format.equalsIgnoreCase("image/png") ||
298
                format.equalsIgnoreCase("image/jpg") ||
299
                format.equalsIgnoreCase("image/tiff") ||
300
                format.equalsIgnoreCase("image/jpeg") ||
301
                format.equalsIgnoreCase("image/tif") ||
302
                format.equalsIgnoreCase("image/gif")) {
303
            return true;
304
        }
305

    
306
        return false;
307
    }
308

    
309
    /**
310
     * Genera la jerarquia de capas para la versi?n 1.0.0
311
     *
312
     * @param nodo nodo raiz de la jerarqu?a que hay que generar
313
     * @param layer objeto layer de la respuesta del servidor
314
     */
315
/*    private void rellena_1_0_0(LayerInfo nodo, Layer layer) {
316
        for (int i = 0; i < layer.getLayerCount(); i++) {
317
            LayerInfo nuevo = new LayerInfo();
318
            nuevo.text = layer.getLayer(i).getTitle().getContent();
319

320
            Name name = layer.getLayer(i).getName();
321

322
            if (name != null) {
323
                nuevo.name = name.getContent();
324
            }
325

326
            SRS srs = layer.getLayer(i).getSRS();
327

328
            if (srs != null) {
329
                nuevo.addSRS(srs.getContent());
330
            }
331

332
            nuevo.queryable = layer.getLayer(i).getQueryable().toString()
333
                                   .equals("1");
334

335
            nodo.hijos.add(nuevo);
336
            nuevo.padre = nodo;
337
            rellena_1_0_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i));
338
        }
339
    }
340
*/
341
    /**
342
     * Genera la jerarquia de capas para la versi?n 1.1.0
343
     *
344
     * @param nodo nodo raiz de la jerarqu?a que hay que generar
345
     * @param layer objeto layer de la respuesta del servidor
346
     */
347
  /*  private void rellena_1_1_0(LayerInfo nodo,
348
        com.iver.wmsclient.wms_1_1_0.capabilities.Layer layer) {
349
        for (int i = 0; i < layer.getLayerCount(); i++) {
350
            LayerInfo nuevo = new LayerInfo();
351
            nuevo.text = layer.getLayer(i).getTitle().getContent();
352

353
            com.iver.wmsclient.wms_1_1_0.capabilities.Name name = layer.getLayer(i)
354
                                                                                .getName();
355

356
            if (name != null) {
357
                nuevo.name = name.getContent();
358
            }
359

360
            com.iver.wmsclient.wms_1_1_0.capabilities.SRS srs = layer.getLayer(i)
361
                                                                              .getSRS();
362

363
            if (srs != null) {
364
                nuevo.addSRS(srs.getContent());
365
            }
366

367
            nuevo.queryable = layer.getLayer(i).getQueryable().toString()
368
                                   .equals("1");
369

370
            nodo.hijos.add(nuevo);
371
            nuevo.padre = nodo;
372
            rellena_1_1_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i));
373
        }
374
    }
375
*/
376
    /**
377
     * Genera la jerarquia de capas para la versi?n 1.1.1
378
     *
379
     * @param nodo nodo raiz de la jerarqu?a que hay que generar
380
     * @param layer objeto layer de la respuesta del servidor
381
     */
382
  /*  private void rellena_1_1_1(LayerInfo nodo,
383
        com.iver.wmsclient.wms_1_1_1.capabilities.Layer layer) {
384
        for (int i = 0; i < layer.getLayerCount(); i++) {
385
            LayerInfo nuevo = new LayerInfo();
386
            nuevo.text = layer.getLayer(i).getTitle().getContent();
387

388
            com.iver.wmsclient.wms_1_1_1.capabilities.Name name = layer.getLayer(i)
389
                                                                                .getName();
390
                                                                                
391
            if (name != null){
392
                                nuevo.name = name.getContent();
393
            }
394

395
            com.iver.wmsclient.wms_1_1_1.capabilities.SRS[] srs = layer.getLayer(i)
396
                                                                                .getSRS();
397

398
            if (srs != null) {
399
                for (int j = 0; j < srs.length; j++) {
400
                    nuevo.addSRS(srs[j].getContent());
401
                }
402
            }
403

404
            nuevo.queryable = layer.getLayer(i).getQueryable().toString()
405
                                   .equals("1");
406

407
            nodo.hijos.add(nuevo);
408
            nuevo.padre = nodo;
409
            rellena_1_1_1((LayerInfo) nodo.hijos.get(i), layer.getLayer(i));
410
        }
411
    }
412

413
    /**
414
     * Genera la jerarquia de capas para la versi?n 1.3.0
415
     *
416
     * @param nodo nodo raiz de la jerarqu?a que hay que generar
417
     * @param layer objeto layer de la respuesta del servidor
418
     */
419
    /*private void rellena_1_3_0(LayerInfo nodo,
420
        com.iver.wmsclient.wms_1_3_0.capabilities.Layer layer) {
421
        for (int i = 0; i < layer.getLayerCount(); i++) {
422
            LayerInfo nuevo = new LayerInfo();
423
            nuevo.text = layer.getLayer(i).getTitle().getContent();
424

425
            com.iver.wmsclient.wms_1_3_0.capabilities.Name name = layer.getLayer(i)
426
                                                                                .getName();
427

428
            if (name != null) {
429
                nuevo.name = name.getContent();
430
            }
431

432
            String[] srs = layer.getLayer(i).getCRS();
433

434
            if (srs != null) {
435
                for (int j = 0; j < srs.length; j++) {
436
                    nuevo.addSRS(srs[j]);
437
                }
438
            }
439

440
            nuevo.queryable = layer.getLayer(i).getQueryable();
441

442
            nodo.hijos.add(nuevo);
443
            nuevo.padre = nodo;
444
            rellena_1_3_0((LayerInfo) nodo.hijos.get(i), layer.getLayer(i));
445
        }
446
    }
447
*/
448
    /**
449
     * @see com.iver.cit.gvsig.gui.wms.WMSWizardDataSource#detalles()
450
     */
451
    public WMSWizardData detalles(URL host)
452
        throws IllegalStateException, ValidationException, 
453
            UnsupportedVersionException, IOException {
454
        try {
455
                        wms = new WMSClient(host.toString());
456
                        
457
                        // Send a getCapabilities request;
458
                        wms.connect();
459
                        
460
                        //TODO
461
                        //Implement this
462
                        String version = wms.getVersion();
463
                if (version.equals("1.0.0")) {
464
                    //return detalles_1_0_0();
465
                } else if (version.equals("1.1.1")) {
466
                    return detalles_1_1_1();
467
                } else {
468
                    throw new UnsupportedVersionException(version);
469
                }                
470
                        
471
                /*com.iver.wmsclient.Capabilities c = cliente.getCapabilities(host);
472
                String version = c.getVersion();
473
        
474
                if (version.equals("1.0.0")) {
475
                    return detalles_1_0_0((WMT_MS_Capabilities) c.getRoot());
476
                } else if (version.equals("1.1.0")) {
477
                    return detalles_1_1_0((com.iver.wmsclient.wms_1_1_0.capabilities.WMT_MS_Capabilities) c.getRoot());
478
                } else if (version.equals("1.1.1")) {
479
                    return detalles_1_1_1((com.iver.wmsclient.wms_1_1_1.capabilities.WMT_MS_Capabilities) c.getRoot());
480
                } else if (version.equals("1.3.0")) {
481
                    return detalles_1_3_0((com.iver.wmsclient.wms_1_3_0.capabilities.WMS_Capabilities) c.getRoot());
482
                } else {
483
                    throw new UnsupportedVersionException(version);
484
                }*/
485
                } catch (Exception e) {
486
                        throw new UnsupportedVersionException(e);
487
                }
488
                return null;
489
    }
490

    
491
    /**
492
     * M?todo detalles para la versi?n 1.1.1
493
     *
494
     * @see com.iver.cit.gvsig.gui.wms.WMSWizardDataSource#detalles()
495
     */
496
   private WMSWizardData detalles_1_1_1()
497
     {
498
        WMSWizardData data = new WMSWizardData();
499
        
500
        //TODO: change this to an outter class or create Capabilities object
501
        WMSProtocolHandler.ServiceInformation serviceInformation;
502
        serviceInformation = wms.getServiceInformation();
503
        
504
        data.setTitle(serviceInformation.title);
505
        
506
        if (serviceInformation.abstr  != null)
507
        data.setAbstract(serviceInformation.abstr);
508

    
509
//        com.iver.wmsclient.wms_1_1_1.capabilities.Format[] f = cap.getCapability()
510
//                                                                           .getRequest()
511
//                                                                           .getGetMap()
512
//                                                                           .getFormat();
513
//        ArrayList formatos = new ArrayList();
514
//
515
//        for (int i = 0; i < f.length; i++) {
516
//            if (isValidFormat(f[i].getContent())) {
517
//                formatos.add(f[i].getContent());
518
//            }
519
//        }
520

    
521
        Vector f = wms.getFormats(); 
522
        ArrayList formatos = new ArrayList();
523
        for (int i = 0; i < f.size(); i++) {
524
          if (isValidFormat((String)f.elementAt(i))) {
525
              formatos.add((String)f.elementAt(i));
526
          }
527
        }
528
        data.setFormats((String[]) formatos.toArray(new String[0]));
529
        
530
        WMSLayer root = wms.getLayersRoot(); // root of the Layers node within the Capabilities document
531
        /*root.text = l.getTitle().getContent();
532

533
        com.iver.wmsclient.wms_1_1_1.capabilities.Name name = l.getName();
534

535
        if (name != null) {
536
            root.name = name.getContent();
537
        }
538

539
        com.iver.wmsclient.wms_1_1_1.capabilities.SRS[] srs = l.getSRS();
540

541
        if (srs != null) {
542
            for (int i = 0; i < srs.length; i++) {
543
                root.addSRS(srs[i].getContent());
544
            }o
545
        }
546

547
        rellena_1_1_1((LayerInfo) root, l);
548
*/
549
        data.setLayer(root);
550
        
551
        return data;
552
    }
553
    
554
    
555
    
556
    /**
557
     * @see com.iver.cit.gvsig.gui.wms.WMSWizardDataSource#getBoundingBox(java.lang.String,
558
     *      java.lang.String)
559
     */
560
    public Rectangle2D getBoundingBox(String[] layerName, String srs) {
561
        //return wms.getBoundingBox(layerName, srs);
562
                        
563
            return wms.getLayersExtent(layerName, srs);
564
    }
565

    
566
}