Statistics
| Revision:

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

History | View | Annotate | Download (18.3 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.WizardData;
62
import com.iver.cit.gvsig.gui.wizard.WizardDataSource;
63

    
64

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

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

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

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

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

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

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

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

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

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

110
        Name name = l.getName();
111

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

116
        SRS srs = l.getSRS();
117

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

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

124
        data.setLayer(root);
125

126
        return data;
127
    }*/
128

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

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

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

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

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

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

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

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

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

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

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

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

175
        data.setLayer(root);
176

177
        return data;
178
    }*/
179

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

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

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

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

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

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

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

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

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

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

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

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

228
        data.setLayer(root);
229

230
        return data;
231
    }*/
232

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

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

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

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

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

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

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

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

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

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

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

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

282
        data.setLayer(root);
283

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

    
305
        return false;
306
    }
307

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
565
}