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 @ 41249

History | View | Annotate | Download (13.9 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
            keywordList.add(key);
143
    }
144
    
145
    public ArrayList getKeywords() {
146
            return keywordList;
147
    }
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
    /**
158
     * <p>Gets the style vector</p>
159
     * @return
160
     */
161
    public ArrayList getStyles() {
162
            ArrayList list = new ArrayList();
163
            if (styles != null)
164
                    list.addAll(styles);
165
            if (this.getParent()!= null) {
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
            if (layer.getParent()!= null) {
175
                    ArrayList list = getAllStyles(layer.getParent());
176
                    for(int i = 0; i < this.styles.size(); i++) {
177
                            list.add(styles.get(i));
178
                    }
179
                    return list;
180
            } else {
181
                    return styles;
182
            }
183
    }
184
    
185
    /**
186
     * <p>Adds a bbox to the Bboxes vector</p>
187
     * @param bbox
188
     */
189
    public void addBBox(BoundaryBox bbox) {
190
        bBoxes.put(bbox.getSrs(), bbox);
191
    }
192

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

    
214
    /**
215
     * <p>Gets the bBoxes vector</p>
216
     * @return
217
     */
218
    public Hashtable getBboxes() {
219
        return bBoxes;
220
    }
221

    
222

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

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

    
251
    /**
252
     * <p>gets the maximum scale for this layer</p>
253
     * @return
254
     */
255
    public double getScaleMax() {
256
        return scaleMax;
257
    }
258

    
259
    /**
260
     * <p>gets the minimum scale for this layer</p>
261
     * @return
262
     */
263
    public double getScaleMin() {
264
        return scaleMin;
265
    }
266

    
267
    /**
268
     * <p>sets the minimum scale for this layer to be visible.</p>
269
     *
270
     * @param scale
271
     */
272
    public void setScaleMin(double scale) {
273
        scaleMin = scale;
274
    }
275

    
276
    /**
277
     * <p>sets the maximum scale for this layer to be visible</p>
278
     * @param scale
279
     */
280
    public void setScaleMax(double scale) {
281
        scaleMax = scale;
282
    }
283

    
284
    /**
285
     * <p> gets the dimension vector defined in this layer</p>
286
     * @return
287
     */
288
    public abstract ArrayList getDimensions();
289

    
290
    public WMSDimension getDimension(String name) {
291
            for(int i = 0; i < dimensions.size(); i++ ) {
292
                    if(((WMSDimension)dimensions.get(i)).getName().compareTo(name) == 0) {
293
                            return (WMSDimension)dimensions.get(i);
294
                    }
295
            }
296
            return null;
297
    }
298

    
299
    /**
300
     * <p>Adds a dimension to the dimension vector </p>
301
     * @param dimension
302
     */
303
    public void addDimension(org.gvsig.remoteclient.wms.WMSDimension dimension) {
304
        dimensions.add(dimension);
305
    }
306

    
307
    /**
308
     * <p>Gets layer name</p>
309
     * @return
310
     */
311
    public String getName() {
312
        return this.name;
313
    }
314

    
315
    /**
316
     * <p>Sets layer name</p>
317
     * @param _name
318
     */
319
    public void setName(String name) {
320
        this.name = name;
321
    }
322

    
323
    /**
324
     * <p>Gets layer title</p>
325
     * @return
326
     */
327
    public String getTitle() {
328
        return title;
329
    }
330

    
331
    /**
332
     * <p>Sets the layer title</p>
333
     * @param _title
334
     */
335
    public void setTitle(String title) {
336
        this.title = title;
337
    }
338

    
339
    /**
340
     * <p>Gets the layer abstract</p>
341
     * @return
342
     */
343
    public String getAbstract() {
344
        return layerAbstract;
345
    }
346

    
347
    /**
348
     * <p>Sets the layer abstract</p>
349
     * @param m_abstract
350
     */
351
    public void setAbstract(String _abstract) {
352
        layerAbstract = _abstract;
353
    }
354

    
355

    
356
    public ArrayList getChildren() {
357
        return children;
358
    }
359

    
360

    
361
    public void setChildren(ArrayList children) {
362
        this.children = children;
363
    }
364

    
365

    
366
    public WMSLayer getParent() {
367
        return parent;
368
    }
369

    
370

    
371
    public void setParent(WMSLayer parent) {
372
        this.parent = parent;
373
    }
374

    
375
    public String toString(){
376
        return this.getTitle();
377
    }
378

    
379

    
380
    /**
381
     * Tells if this layer accepts getFeatureInfo requests.
382
     */
383
    public boolean isQueryable() {
384
        return queryable;
385
    }
386

    
387

    
388
    /**
389
     * @param queryable The queryable to set.
390
     */
391
    public void setQueryable(boolean queryable) {
392
        this.queryable = queryable;
393
    }
394

    
395
    /**
396
     * Tells if this layer is opaque.
397
     */
398
    public boolean isOpaque() {
399
        return opaque;
400
    }
401
    /**
402
     * @param opaque.
403
     */
404
    public void setOpaque(boolean opaque) {
405
        this.opaque = opaque;
406
    }
407

    
408
    /**
409
     * Tells if this layer is subsettable
410
     */
411
    public boolean noSubSets() {
412
        return this.m_noSubSets;
413
    }
414
    /**
415
     * @param set layer nosubsets attribute.
416
     */
417
    public void setNoSubSets(boolean _noSubSets) {
418
        m_noSubSets = _noSubSets;
419
    }
420

    
421
    public void setfixedWidth(int w) {
422
        fixedWidth = w;
423
    }
424

    
425
    public int getfixedWidth() {
426
        return fixedWidth;
427
    }
428

    
429
    public void setfixedHeight(int h) {
430
        fixedHeight = h;
431
    }
432

    
433
    public int getfixedHeight() {
434
        return fixedHeight;
435
    }
436

    
437
    /**
438
     * @return <b>true</b> if this layer can be served with transparency, otherwise <b>false</b>
439
     */
440
    public boolean hasTransparency() {
441
        return transparency;
442
    }
443

    
444
    //Methods to parse tags that are common to several versions of WMS.
445
    //In case there is a version which has different implemantation of one of this tags
446
    // the subclass can overwrite this method
447

    
448
    /**
449
     * Parses the keywordlist from the capabilities and fills this list in the WMSLayer.
450
     * @param parser
451
     */
452
    protected void parseKeywordList(KXmlParser parser)  throws IOException, XmlPullParserException {
453
            int currentTag;
454
            boolean end = false;
455
            String value;
456

    
457
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.KEYWORDLIST);
458
            currentTag = parser.nextTag();
459

    
460
        while (!end) {
461
                         switch(currentTag) {
462
                                case KXmlParser.START_TAG:
463
                                        if (parser.getName().compareTo(CapabilitiesTags.KEYWORD) == 0) {
464
                                                value = parser.nextText();
465
                                                if ((value != null) && (value.length() > 0 ))
466
                                                        addkeyword(value);
467
                                        }
468
                                        break;
469
                                case KXmlParser.END_TAG:
470
                                        if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0)
471
                                                end = true;
472
                                        break;
473
                                case KXmlParser.TEXT:
474
                                        break;
475
                         }
476
                         if (!end) {
477
                                 currentTag = parser.next();
478
                         }
479
            }
480
            parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.KEYWORDLIST);
481
    }
482

    
483
    /**
484
     * Reads and parses the layer attributes
485
     * Maybe this method should be moved to the WMSLayer. Until now the attributes are teh same for all versions.
486
     * @param parser
487
     */
488
    protected void readLayerAttributes(KXmlParser parser) {
489
            String value = new String();
490

    
491
        //First of all set whether the layer is Queryable reading the attribute.
492
        value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
493
        if (value != null) {
494
            if (value.compareTo("0") == 0)
495
                setQueryable(false);
496
            else
497
                setQueryable(true);
498
        }
499
        value = parser.getAttributeValue("", CapabilitiesTags.OPAQUE);
500
        if (value != null) {
501
            if (value.compareTo("0") == 0)
502
                setOpaque(false);
503
            else
504
                setOpaque(true);
505
        }
506
        value = parser.getAttributeValue("", CapabilitiesTags.NOSUBSETS);
507
        if (value != null) {
508
            if (value.compareTo("0") == 0)
509
                setNoSubSets(false);
510
            else
511
                    setNoSubSets(true);
512
        }
513
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDWIDTH);
514
        if (value != null) {
515
                setfixedWidth(Integer.parseInt(value));
516
        }
517
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDHEIGHT);
518
        if (value != null) {
519
                setfixedHeight(Integer.parseInt(value));
520
        }
521
    }
522

    
523

    
524
    /**
525
     * <p>Inner class describing the MetadataURL tag in OGC specifications in WMS</p>
526
     *
527
     */
528
    protected class MetadataURL {
529
            public MetadataURL() {
530
                    type = new String();
531
                    format = new String();
532
                    onlineResource_xlink = new String();
533
                    onlineResource_type = new String();
534
                    onlineResource_href = new String();
535
            }
536
        public String type;
537
        public String format;
538
        public String onlineResource_xlink;
539
        public String onlineResource_type;
540
        public String onlineResource_href;
541
     }
542

    
543
    /**
544
     * <p>Inner class describing the DataURL tag in OGC specifications in WMS</p>
545
     *
546
     */
547
    protected class DataURL {
548
            public DataURL() {
549
                    type = new String();
550
                    format = new String();
551
                    onlineResource_xlink = new String();
552
                    onlineResource_type = new String();
553
                    onlineResource_href = new String();
554
            }
555
        public String type;
556
        public String format;
557
        public String onlineResource_xlink;
558
        public String onlineResource_type;
559
        public String onlineResource_href;
560
     }
561
}