Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wms / WMSLayer.java @ 38579

History | View | Annotate | Download (13.5 KB)

1
package org.gvsig.remoteclient.wms;
2

    
3
import java.io.IOException;
4
import java.util.ArrayList;
5
import java.util.Hashtable;
6
import java.util.TreeMap;
7
import java.util.Vector;
8

    
9
import org.kxml2.io.KXmlParser;
10
import org.xmlpull.v1.XmlPullParserException;
11

    
12
import org.gvsig.remoteclient.utils.BoundaryBox;
13
import org.gvsig.remoteclient.utils.CapabilitiesTags;
14

    
15
/**
16
 * <p>Abstract class that defines an WMSLayer.</p>
17
 *
18
 */
19
public abstract class WMSLayer implements org.gvsig.remoteclient.ILayer {
20

    
21
    protected ArrayList children;
22
    protected WMSLayer parent;
23

    
24
    /**
25
     * <p>Layer Abstract field in the capabilities document </p>
26
     */
27
    private String layerAbstract;
28

    
29
    /**
30
     * <p>Themes provided by the WMS for the layer</p>
31
     */
32
    public ArrayList styles = new ArrayList();
33

    
34
    /**
35
     * <p>Layer name</p>
36
     */
37
    private String name;
38

    
39
    /**
40
     * <p>Layer title</p>
41
     */
42
    private String title;
43

    
44
    private ArrayList keywordList = new ArrayList();
45
    /**
46
     * <p>Layer srs.</p>
47
     */
48
    protected Vector srs = new Vector();
49

    
50
    /**
51
     * <p>extents for each srs the layer can be reproyected to</p>
52
     */
53
    private Hashtable bBoxes  = new Hashtable();
54

    
55
    /**
56
     * <p>extents that defines the bbox for the LatLon projection
57
     * It can be included in the bBoxes vector as well, because it is the most used, we keep it separeted too, according
58
     *  with the OGC WMSCapabilities specifications...
59
     */
60
    private org.gvsig.remoteclient.utils.BoundaryBox latLonBbox;
61

    
62
    /**
63
     * <p>min scale for the layer to be visible</p>
64
     */
65
    private double scaleMin;
66

    
67
    /**
68
     * <p>max scale for the layer to be visible</p>
69
     */
70
    private double scaleMax;
71

    
72
    /**
73
     * <p>Dimensions defined for the layer in the capabilities doc</p>
74
     */
75
    protected java.util.ArrayList dimensions = new ArrayList();
76

    
77
    /**
78
     * Tells if this layer accepts getFeatureInfo requests.
79
     */
80
    private boolean queryable = false;
81

    
82
    /**
83
     * Tells if this layer is opaque.
84
     */
85
    private boolean opaque = false;
86
    /**
87
     * when set to true, noSubsets indicates that the server is not able to make a map
88
     * of a geographic area other than the layer's bounding box.
89
     */
90
    private boolean m_noSubSets = false;
91

    
92
    /**
93
     * when present and non-zero fixedWidth and fixedHeight indicate that the server is not
94
     * able to produce a map of the layer at a width and height different from the fixed sizes indicated.
95
     */
96
    private int fixedWidth = 0;
97
    private int fixedHeight = 0;
98

    
99
    /**
100
     * Tells if this layer can be served with transparency.
101
     */
102
    private boolean transparency;
103

    
104
    /**
105
     * <p>Parses the LAYER tag in the WMS capabilities, filling the WMSLayer object
106
     * loading the data in memory to be easily accesed</p>
107
     *
108
     */
109
    public abstract void parse(KXmlParser parser, TreeMap layerTreeMap)
110
    throws IOException, XmlPullParserException;
111

    
112
    //public abstract ArrayList getAllDimensions();
113

    
114
    /**
115
     * add a new keyword to the keywordList.
116
     * @param key
117
     */
118
    protected void addkeyword(String key)
119
    {
120
            keywordList.add(key);
121
    }
122
    public ArrayList getKeywords()
123
    {
124
            return keywordList;
125
    }
126
    /**
127
     * <p>Adds a style to the styles vector</p>
128
     * @param _style
129
     */
130
    public void addStyle(org.gvsig.remoteclient.wms.WMSStyle _style) {
131
        styles.add( _style );    }
132

    
133
   /**
134
     * <p>Gets the style vector</p>
135
     * @return
136
     */
137
    public ArrayList getStyles() {
138
            ArrayList list = new ArrayList();
139
            if (styles != null)
140
                    list.addAll(styles);
141
            if (this.getParent()!= null)
142
            {
143
                    //return getAllStyles(this);
144
                    if(this.getParent().getStyles() != null)
145
                            list.addAll(this.getParent().getStyles());
146
            }
147
        return list;
148
    }
149

    
150
    public ArrayList getAllStyles(WMSLayer layer)
151
    {
152
            if (layer.getParent()!= null)
153
            {
154
                    ArrayList list = getAllStyles(layer.getParent());
155
                    for(int i = 0; i < this.styles.size(); i++)
156
                    {
157
                            list.add(styles.get(i));
158
                    }
159
                    return list;
160
            }
161
            else
162
            {
163
                    return styles;
164
            }
165
    }
166
    /**
167
     * <p>Adds a bbox to the Bboxes vector</p>
168
     * @param bbox
169
     */
170
    public void addBBox(BoundaryBox bbox) {
171
        bBoxes.put(bbox.getSrs(), bbox);
172
    }
173

    
174
    /**
175
     * <p>returns the bbox with that id in the Bboxes vector</p>
176
     * @param id
177
     */
178
    public BoundaryBox getBbox(String id) {
179
            if ((id.compareToIgnoreCase( CapabilitiesTags.EPSG_4326 )==0)
180
                    ||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0))
181
            {
182
                    if (latLonBbox != null)
183
                    return (BoundaryBox)latLonBbox;
184
            }
185
        BoundaryBox b = (BoundaryBox) bBoxes.get(id);
186
        if (b == null && parent!=null)
187
            return parent.getBbox(id);
188
        return (BoundaryBox)bBoxes.get(id);
189
    }
190

    
191
    /**
192
     * <p>Gets the bBoxes vector</p>
193
     * @return
194
     */
195
    public Hashtable getBboxes() {
196
        return bBoxes;
197
    }
198

    
199

    
200
    //Methods to manipulate the box that defines the layer extent in LatLon SRS.
201
    public BoundaryBox getLatLonBox()
202
    {
203
        return latLonBbox;
204
    }
205
    public void setLatLonBox(BoundaryBox box)
206
    {
207
        latLonBbox = box;
208
    }
209
    /**
210
     * <p>adds a new srs to the srs vector</p>
211
     */
212
    public void addSrs(String srs)
213
    {
214
            if (!this.srs.contains(srs))
215
                    this.srs.add(srs);
216
    }
217

    
218
    public Vector getAllSrs()
219
    {
220
        Vector mySRSs = (Vector) this.srs.clone();
221
        if (parent!=null)
222
            mySRSs.addAll(parent.getAllSrs());
223
        return mySRSs;
224

    
225
//            if (this.getParent()!= null)
226
//            {
227
//                    Vector list = this.getParent().getAllSrs();
228
//                    for(int i = 0; i < this.srs.size(); i++)
229
//                    {
230
//                            list.add(srs.get(i));
231
//                    }
232
//                    return list;
233
//            }
234
//            else
235
//            {
236
//                    return srs;
237
//            }
238

    
239
    }
240
    /**
241
     * <p>gets the maximum scale for this layer</p>
242
     * @return
243
     */
244
    public double getScaleMax() {
245
        return scaleMax;
246
    }
247

    
248
    /**
249
     * <p>gets the minimum scale for this layer</p>
250
     * @return
251
     */
252
    public double getScaleMin() {
253
        return scaleMin;
254
    }
255

    
256
    /**
257
     * <p>sets the minimum scale for this layer to be visible.</p>
258
     *
259
     * @param scale
260
     */
261
    public void setScaleMin(double scale) {
262
        scaleMin = scale;
263
    }
264

    
265
    /**
266
     * <p>sets the maximum scale for this layer to be visible</p>
267
     * @param scale
268
     */
269
    public void setScaleMax(double scale) {
270
        scaleMax = scale;
271
    }
272

    
273
    /**
274
     * <p> gets the dimension vector defined in this layer</p>
275
     * @return
276
     */
277
    public abstract ArrayList getDimensions();
278
//    public ArrayList getDimensions() {
279
//        return dimensions;
280
//    }
281

    
282
    public WMSDimension getDimension(String name)
283
    {
284
            for(int i = 0; i < dimensions.size(); i++ ){
285
                    if(((WMSDimension)dimensions.get(i)).getName().compareTo(name)==0)
286
                    {
287
                            return (WMSDimension)dimensions.get(i);
288
                    }
289
            }
290
            return null;
291
    }
292

    
293
//    /**
294
//     * <p>Sets the dimension vector defined for this layer</p>
295
//     * @param v
296
//     */
297
//    public void setDimensions(ArrayList v) {
298
//        dimensions = (ArrayList)v.clone();
299
//    }
300

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

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

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

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

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

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

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

    
357

    
358
    public ArrayList getChildren() {
359
        return children;
360
    }
361

    
362

    
363
    public void setChildren(ArrayList children) {
364
        this.children = children;
365
    }
366

    
367

    
368
    public WMSLayer getParent() {
369
        return parent;
370
    }
371

    
372

    
373
    public void setParent(WMSLayer parent) {
374
        this.parent = parent;
375
    }
376

    
377
    public String toString(){
378
        return this.getTitle();
379
    }
380

    
381

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

    
389

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

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

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

    
423
    public void setfixedWidth(int w) {
424
        fixedWidth = w;
425
    }
426

    
427
    public int getfixedWidth() {
428
        return fixedWidth;
429
    }
430

    
431
    public void setfixedHeight(int h) {
432
        fixedHeight = h;
433
    }
434

    
435
    public int getfixedHeight() {
436
        return fixedHeight;
437
    }
438

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

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

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

    
460
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.KEYWORDLIST);
461
            currentTag = parser.nextTag();
462

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

    
490
    /**
491
     * Reads and parses the layer attributes
492
     * Maybe this method should be moved to the WMSLayer. Until now the attributes are teh same for all versions.
493
     * @param parser
494
     */
495
    protected void readLayerAttributes(KXmlParser parser)
496
    {
497
            String value = new String();
498

    
499
        //First of all set whether the layer is Queryable reading the attribute.
500
        value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
501
        if (value != null)
502
        {
503
            if (value.compareTo("0")==0)
504
                setQueryable(false);
505
            else
506
                setQueryable(true);
507
        }
508
        value = parser.getAttributeValue("", CapabilitiesTags.OPAQUE);
509
        if (value != null)
510
        {
511
            if (value.compareTo("0")==0)
512
                setOpaque(false);
513
            else
514
                setOpaque(true);
515
        }
516
        value = parser.getAttributeValue("", CapabilitiesTags.NOSUBSETS);
517
        if (value != null)
518
        {
519
            if (value.compareTo("0")==0)
520
                setNoSubSets(false);
521
            else
522
                    setNoSubSets(true);
523
        }
524
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDWIDTH);
525
        if (value != null)
526
        {
527
                setfixedWidth(Integer.parseInt(value));
528
        }
529
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDHEIGHT);
530
        if (value != null)
531
        {
532
                setfixedHeight(Integer.parseInt(value));
533
        }
534
    }
535

    
536

    
537
    /**
538
     * <p>Inner class describing the MetadataURL tag in OGC specifications in WMS</p>
539
     *
540
     */
541
    protected class MetadataURL
542
    {
543
            public MetadataURL()
544
            {
545
                    type = new String();
546
                    format = new String();
547
                    onlineResource_xlink = new String();
548
                    onlineResource_type = new String();
549
                    onlineResource_href = new String();
550
            }
551
        public String type;
552
        public String format;
553
        public String onlineResource_xlink;
554
        public String onlineResource_type;
555
        public String onlineResource_href;
556
     }
557

    
558
    /**
559
     * <p>Inner class describing the DataURL tag in OGC specifications in WMS</p>
560
     *
561
     */
562
    protected class DataURL
563
    {
564
            public DataURL()
565
            {
566
                    type = new String();
567
                    format = new String();
568
                    onlineResource_xlink = new String();
569
                    onlineResource_type = new String();
570
                    onlineResource_href = new String();
571
            }
572
        public String type;
573
        public String format;
574
        public String onlineResource_xlink;
575
        public String onlineResource_type;
576
        public String onlineResource_href;
577
     }
578
}