Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wms / WMSLayer.java @ 41242

History | View | Annotate | Download (14.5 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.wms;
25

    
26
import java.io.IOException;
27
import java.util.ArrayList;
28
import java.util.Hashtable;
29
import java.util.TreeMap;
30
import java.util.Vector;
31

    
32
import org.kxml2.io.KXmlParser;
33
import org.xmlpull.v1.XmlPullParserException;
34

    
35
import org.gvsig.remoteclient.utils.BoundaryBox;
36
import org.gvsig.remoteclient.utils.CapabilitiesTags;
37

    
38
/**
39
 * <p>Abstract class that defines an WMSLayer.</p>
40
 *
41
 */
42
public abstract class WMSLayer implements org.gvsig.remoteclient.ILayer {
43

    
44
    protected ArrayList children;
45
    protected WMSLayer parent;
46

    
47
    /**
48
     * <p>Layer Abstract field in the capabilities document </p>
49
     */
50
    private String layerAbstract;
51

    
52
    /**
53
     * <p>Themes provided by the WMS for the layer</p>
54
     */
55
    public ArrayList styles = new ArrayList();
56

    
57
    /**
58
     * <p>Layer name</p>
59
     */
60
    private String name;
61

    
62
    /**
63
     * <p>Layer title</p>
64
     */
65
    private String title;
66

    
67
    private ArrayList keywordList = new ArrayList();
68
    /**
69
     * <p>CRS list of this layer (Tag CRS)</p>
70
     */
71
    protected Vector srs = new Vector();
72

    
73
    /**
74
     * <p>Bounding box por CRS (Tag BoundingBox)</p>
75
     */
76
    private Hashtable bBoxes  = new Hashtable();
77

    
78
    /**
79
     * <p>extents that defines the bbox for the LatLon projection
80
     * It can be included in the bBoxes vector as well, because it is the most used, we keep it separeted too, according
81
     *  with the OGC WMSCapabilities specifications...
82
     */
83
    private org.gvsig.remoteclient.utils.BoundaryBox latLonBbox;
84

    
85
    /**
86
     * <p>min scale for the layer to be visible</p>
87
     */
88
    private double scaleMin;
89

    
90
    /**
91
     * <p>max scale for the layer to be visible</p>
92
     */
93
    private double scaleMax;
94

    
95
    /**
96
     * <p>Dimensions defined for the layer in the capabilities doc</p>
97
     */
98
    protected java.util.ArrayList dimensions = new ArrayList();
99

    
100
    /**
101
     * Tells if this layer accepts getFeatureInfo requests.
102
     */
103
    private boolean queryable = false;
104

    
105
    /**
106
     * Tells if this layer is opaque.
107
     */
108
    private boolean opaque = false;
109
    /**
110
     * when set to true, noSubsets indicates that the server is not able to make a map
111
     * of a geographic area other than the layer's bounding box.
112
     */
113
    private boolean m_noSubSets = false;
114

    
115
    /**
116
     * when present and non-zero fixedWidth and fixedHeight indicate that the server is not
117
     * able to produce a map of the layer at a width and height different from the fixed sizes indicated.
118
     */
119
    private int fixedWidth = 0;
120
    private int fixedHeight = 0;
121

    
122
    /**
123
     * Tells if this layer can be served with transparency.
124
     */
125
    private boolean transparency;
126

    
127
    /**
128
     * <p>Parses the LAYER tag in the WMS capabilities, filling the WMSLayer object
129
     * loading the data in memory to be easily accesed</p>
130
     *
131
     */
132
    public abstract void parse(KXmlParser parser, TreeMap layerTreeMap)
133
    throws IOException, XmlPullParserException;
134

    
135
    //public abstract ArrayList getAllDimensions();
136

    
137
    /**
138
     * add a new keyword to the keywordList.
139
     * @param key
140
     */
141
    protected void addkeyword(String key)
142
    {
143
            keywordList.add(key);
144
    }
145
    public ArrayList getKeywords()
146
    {
147
            return keywordList;
148
    }
149
    /**
150
     * <p>Adds a style to the styles vector</p>
151
     * @param _style
152
     */
153
    public void addStyle(org.gvsig.remoteclient.wms.WMSStyle _style) {
154
        styles.add( _style );    }
155

    
156
   /**
157
     * <p>Gets the style vector</p>
158
     * @return
159
     */
160
    public ArrayList getStyles() {
161
            ArrayList list = new ArrayList();
162
            if (styles != null)
163
                    list.addAll(styles);
164
            if (this.getParent()!= null)
165
            {
166
                    //return getAllStyles(this);
167
                    if(this.getParent().getStyles() != null)
168
                            list.addAll(this.getParent().getStyles());
169
            }
170
        return list;
171
    }
172

    
173
    public ArrayList getAllStyles(WMSLayer layer)
174
    {
175
            if (layer.getParent()!= null)
176
            {
177
                    ArrayList list = getAllStyles(layer.getParent());
178
                    for(int i = 0; i < this.styles.size(); i++)
179
                    {
180
                            list.add(styles.get(i));
181
                    }
182
                    return list;
183
            }
184
            else
185
            {
186
                    return styles;
187
            }
188
    }
189
    /**
190
     * <p>Adds a bbox to the Bboxes vector</p>
191
     * @param bbox
192
     */
193
    public void addBBox(BoundaryBox bbox) {
194
        bBoxes.put(bbox.getSrs(), bbox);
195
    }
196

    
197
    /**
198
     * <p>returns the bbox with that id in the Bboxes vector</p>
199
     * @param id
200
     */
201
    public BoundaryBox getBbox(String id) {
202
            //Si hay una bounding box definida para esa capa y ese crs, se usa esa
203
            BoundaryBox b = (BoundaryBox) bBoxes.get(id);
204
            if(b != null)
205
                    return b;
206
            
207
            if ((id.compareToIgnoreCase( CapabilitiesTags.EPSG_4326 )==0)
208
                    ||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0)) {
209
                    if (latLonBbox != null)
210
                    return (BoundaryBox)latLonBbox;
211
            }
212
        
213
        if (parent!=null)
214
            return parent.getBbox(id);
215
        return null;
216
    }
217

    
218
    /**
219
     * <p>Gets the bBoxes vector</p>
220
     * @return
221
     */
222
    public Hashtable getBboxes() {
223
        return bBoxes;
224
    }
225

    
226

    
227
    //Methods to manipulate the box that defines the layer extent in LatLon SRS.
228
    public BoundaryBox getLatLonBox()
229
    {
230
        return latLonBbox;
231
    }
232
    public void setLatLonBox(BoundaryBox box)
233
    {
234
        latLonBbox = box;
235
    }
236
    /**
237
     * <p>adds a new srs to the srs vector</p>
238
     */
239
    public void addSrs(String srs)
240
    {
241
            if (!this.srs.contains(srs))
242
                    this.srs.add(srs);
243
    }
244

    
245
    public Vector getAllSrs()
246
    {
247
        Vector mySRSs = (Vector) this.srs.clone();
248
        if (parent!=null)
249
            mySRSs.addAll(parent.getAllSrs());
250
        return mySRSs;
251

    
252
//            if (this.getParent()!= null)
253
//            {
254
//                    Vector list = this.getParent().getAllSrs();
255
//                    for(int i = 0; i < this.srs.size(); i++)
256
//                    {
257
//                            list.add(srs.get(i));
258
//                    }
259
//                    return list;
260
//            }
261
//            else
262
//            {
263
//                    return srs;
264
//            }
265

    
266
    }
267
    /**
268
     * <p>gets the maximum scale for this layer</p>
269
     * @return
270
     */
271
    public double getScaleMax() {
272
        return scaleMax;
273
    }
274

    
275
    /**
276
     * <p>gets the minimum scale for this layer</p>
277
     * @return
278
     */
279
    public double getScaleMin() {
280
        return scaleMin;
281
    }
282

    
283
    /**
284
     * <p>sets the minimum scale for this layer to be visible.</p>
285
     *
286
     * @param scale
287
     */
288
    public void setScaleMin(double scale) {
289
        scaleMin = scale;
290
    }
291

    
292
    /**
293
     * <p>sets the maximum scale for this layer to be visible</p>
294
     * @param scale
295
     */
296
    public void setScaleMax(double scale) {
297
        scaleMax = scale;
298
    }
299

    
300
    /**
301
     * <p> gets the dimension vector defined in this layer</p>
302
     * @return
303
     */
304
    public abstract ArrayList getDimensions();
305
//    public ArrayList getDimensions() {
306
//        return dimensions;
307
//    }
308

    
309
    public WMSDimension getDimension(String name)
310
    {
311
            for(int i = 0; i < dimensions.size(); i++ ){
312
                    if(((WMSDimension)dimensions.get(i)).getName().compareTo(name)==0)
313
                    {
314
                            return (WMSDimension)dimensions.get(i);
315
                    }
316
            }
317
            return null;
318
    }
319

    
320
//    /**
321
//     * <p>Sets the dimension vector defined for this layer</p>
322
//     * @param v
323
//     */
324
//    public void setDimensions(ArrayList v) {
325
//        dimensions = (ArrayList)v.clone();
326
//    }
327

    
328
    /**
329
     * <p>Adds a dimension to the dimension vector </p>
330
     * @param dimension
331
     */
332
    public void addDimension(org.gvsig.remoteclient.wms.WMSDimension dimension) {
333
        dimensions.add(dimension);
334
    }
335

    
336
    /**
337
     * <p>Gets layer name</p>
338
     * @return
339
     */
340
    public String getName() {
341
        return this.name;
342
    }
343

    
344
    /**
345
     * <p>Sets layer name</p>
346
     * @param _name
347
     */
348
    public void setName(String name) {
349
        this.name = name;
350
    }
351

    
352
    /**
353
     * <p>Gets layer title</p>
354
     * @return
355
     */
356
    public String getTitle() {
357
        return title;
358
    }
359

    
360
    /**
361
     * <p>Sets the layer title</p>
362
     * @param _title
363
     */
364
    public void setTitle(String title) {
365
        this.title = title;
366
    }
367

    
368
    /**
369
     * <p>Gets the layer abstract</p>
370
     * @return
371
     */
372
    public String getAbstract() {
373
        return layerAbstract;
374
    }
375

    
376
    /**
377
     * <p>Sets the layer abstract</p>
378
     * @param m_abstract
379
     */
380
    public void setAbstract(String _abstract) {
381
        layerAbstract = _abstract;
382
    }
383

    
384

    
385
    public ArrayList getChildren() {
386
        return children;
387
    }
388

    
389

    
390
    public void setChildren(ArrayList children) {
391
        this.children = children;
392
    }
393

    
394

    
395
    public WMSLayer getParent() {
396
        return parent;
397
    }
398

    
399

    
400
    public void setParent(WMSLayer parent) {
401
        this.parent = parent;
402
    }
403

    
404
    public String toString(){
405
        return this.getTitle();
406
    }
407

    
408

    
409
    /**
410
     * Tells if this layer accepts getFeatureInfo requests.
411
     */
412
    public boolean isQueryable() {
413
        return queryable;
414
    }
415

    
416

    
417
    /**
418
     * @param queryable The queryable to set.
419
     */
420
    public void setQueryable(boolean queryable) {
421
        this.queryable = queryable;
422
    }
423

    
424
    /**
425
     * Tells if this layer is opaque.
426
     */
427
    public boolean isOpaque() {
428
        return opaque;
429
    }
430
    /**
431
     * @param opaque.
432
     */
433
    public void setOpaque(boolean opaque) {
434
        this.opaque = opaque;
435
    }
436

    
437
    /**
438
     * Tells if this layer is subsettable
439
     */
440
    public boolean noSubSets() {
441
        return this.m_noSubSets;
442
    }
443
    /**
444
     * @param set layer nosubsets attribute.
445
     */
446
    public void setNoSubSets(boolean _noSubSets) {
447
        m_noSubSets = _noSubSets;
448
    }
449

    
450
    public void setfixedWidth(int w) {
451
        fixedWidth = w;
452
    }
453

    
454
    public int getfixedWidth() {
455
        return fixedWidth;
456
    }
457

    
458
    public void setfixedHeight(int h) {
459
        fixedHeight = h;
460
    }
461

    
462
    public int getfixedHeight() {
463
        return fixedHeight;
464
    }
465

    
466
    /**
467
     * @return <b>true</b> if this layer can be served with transparency, otherwise <b>false</b>
468
     */
469
    public boolean hasTransparency() {
470
        return transparency;
471
    }
472

    
473
    //Methods to parse tags that are common to several versions of WMS.
474
    //In case there is a version which has different implemantation of one of this tags
475
    // the subclass can overwrite this method
476

    
477
    /**
478
     * Parses the keywordlist from the capabilities and fills this list in the WMSLayer.
479
     * @param parser
480
     */
481
    protected void parseKeywordList(KXmlParser parser)  throws IOException, XmlPullParserException
482
    {
483
            int currentTag;
484
            boolean end = false;
485
            String value;
486

    
487
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.KEYWORDLIST);
488
            currentTag = parser.nextTag();
489

    
490
        while (!end)
491
            {
492
                         switch(currentTag)
493
                         {
494
                                case KXmlParser.START_TAG:
495
                                        if (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0)
496
                                        {
497
                                                value = parser.nextText();
498
                                                if ((value != null) && (value.length() > 0 ))
499
                                                        addkeyword(value);
500
                                        }
501
                                        break;
502
                                case KXmlParser.END_TAG:
503
                                        if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0)
504
                                                end = true;
505
                                        break;
506
                                case KXmlParser.TEXT:
507
                                        break;
508
                         }
509
                         if (!end)
510
                         {
511
                                 currentTag = parser.next();
512
                         }
513
            }
514
            parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.KEYWORDLIST);
515
    }
516

    
517
    /**
518
     * Reads and parses the layer attributes
519
     * Maybe this method should be moved to the WMSLayer. Until now the attributes are teh same for all versions.
520
     * @param parser
521
     */
522
    protected void readLayerAttributes(KXmlParser parser)
523
    {
524
            String value = new String();
525

    
526
        //First of all set whether the layer is Queryable reading the attribute.
527
        value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
528
        if (value != null)
529
        {
530
            if (value.compareTo("0")==0)
531
                setQueryable(false);
532
            else
533
                setQueryable(true);
534
        }
535
        value = parser.getAttributeValue("", CapabilitiesTags.OPAQUE);
536
        if (value != null)
537
        {
538
            if (value.compareTo("0")==0)
539
                setOpaque(false);
540
            else
541
                setOpaque(true);
542
        }
543
        value = parser.getAttributeValue("", CapabilitiesTags.NOSUBSETS);
544
        if (value != null)
545
        {
546
            if (value.compareTo("0")==0)
547
                setNoSubSets(false);
548
            else
549
                    setNoSubSets(true);
550
        }
551
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDWIDTH);
552
        if (value != null)
553
        {
554
                setfixedWidth(Integer.parseInt(value));
555
        }
556
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDHEIGHT);
557
        if (value != null)
558
        {
559
                setfixedHeight(Integer.parseInt(value));
560
        }
561
    }
562

    
563

    
564
    /**
565
     * <p>Inner class describing the MetadataURL tag in OGC specifications in WMS</p>
566
     *
567
     */
568
    protected class MetadataURL
569
    {
570
            public MetadataURL()
571
            {
572
                    type = new String();
573
                    format = new String();
574
                    onlineResource_xlink = new String();
575
                    onlineResource_type = new String();
576
                    onlineResource_href = new String();
577
            }
578
        public String type;
579
        public String format;
580
        public String onlineResource_xlink;
581
        public String onlineResource_type;
582
        public String onlineResource_href;
583
     }
584

    
585
    /**
586
     * <p>Inner class describing the DataURL tag in OGC specifications in WMS</p>
587
     *
588
     */
589
    protected class DataURL
590
    {
591
            public DataURL()
592
            {
593
                    type = new String();
594
                    format = new String();
595
                    onlineResource_xlink = new String();
596
                    onlineResource_type = new String();
597
                    onlineResource_href = new String();
598
            }
599
        public String type;
600
        public String format;
601
        public String onlineResource_xlink;
602
        public String onlineResource_type;
603
        public String onlineResource_href;
604
     }
605
}