Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wms / WMSLayer.java @ 29658

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.gvsig.remoteclient.utils.BoundaryBox;
10
import org.gvsig.remoteclient.utils.CapabilitiesTags;
11
import org.kxml2.io.KXmlParser;
12
import org.xmlpull.v1.XmlPullParserException;
13

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

    
20
    protected ArrayList children;
21
    protected WMSLayer parent;
22

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
111
    //public abstract ArrayList getAllDimensions();
112

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

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

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

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

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

    
198

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
356

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

    
361

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

    
366

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

    
371

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

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

    
380

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

    
388

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
535

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

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