Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2020 / libraries / libRemoteServices / src / org / gvsig / remoteclient / wms / WMSLayer.java @ 33910

History | View | Annotate | Download (13.5 KB)

1 29658 jpiera
package org.gvsig.remoteclient.wms;
2 3323 ldiaz
3
import java.io.IOException;
4 3377 ldiaz
import java.util.ArrayList;
5 3341 ldiaz
import java.util.Hashtable;
6 3457 ldiaz
import java.util.TreeMap;
7 3323 ldiaz
import java.util.Vector;
8
9
import org.kxml2.io.KXmlParser;
10
import org.xmlpull.v1.XmlPullParserException;
11
12 33738 jpiera
import org.gvsig.remoteclient.utils.BoundaryBox;
13
import org.gvsig.remoteclient.utils.CapabilitiesTags;
14
15 3323 ldiaz
/**
16
 * <p>Abstract class that defines an WMSLayer.</p>
17 6185 jaume
 *
18 3323 ldiaz
 */
19 29658 jpiera
public abstract class WMSLayer implements org.gvsig.remoteclient.ILayer {
20 6185 jaume
21 3483 jaume
    protected ArrayList children;
22 3523 jaume
    protected WMSLayer parent;
23 6185 jaume
24 3483 jaume
    /**
25 6185 jaume
     * <p>Layer Abstract field in the capabilities document </p>
26 3483 jaume
     */
27 3323 ldiaz
    private String layerAbstract;
28 6185 jaume
29 3483 jaume
    /**
30 6185 jaume
     * <p>Themes provided by the WMS for the layer</p>
31 3483 jaume
     */
32 3520 jaume
    public ArrayList styles = new ArrayList();
33 6185 jaume
34 3483 jaume
    /**
35
     * <p>Layer name</p>
36
     */
37 3323 ldiaz
    private String name;
38 6185 jaume
39 3483 jaume
    /**
40
     * <p>Layer title</p>
41
     */
42 3323 ldiaz
    private String title;
43 6185 jaume
44 3750 ldiaz
    private ArrayList keywordList = new ArrayList();
45 3483 jaume
    /**
46
     * <p>Layer srs.</p>
47
     */
48 4222 jaume
    protected Vector srs = new Vector();
49 6185 jaume
50 3483 jaume
    /**
51
     * <p>extents for each srs the layer can be reproyected to</p>
52
     */
53 3523 jaume
    private Hashtable bBoxes  = new Hashtable();
54 6185 jaume
55 3483 jaume
    /**
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 6185 jaume
     */
60 29658 jpiera
    private org.gvsig.remoteclient.utils.BoundaryBox latLonBbox;
61 6185 jaume
62 3483 jaume
    /**
63
     * <p>min scale for the layer to be visible</p>
64
     */
65 3323 ldiaz
    private double scaleMin;
66 6185 jaume
67 3483 jaume
    /**
68
     * <p>max scale for the layer to be visible</p>
69
     */
70 3323 ldiaz
    private double scaleMax;
71 6185 jaume
72 3483 jaume
    /**
73
     * <p>Dimensions defined for the layer in the capabilities doc</p>
74
     */
75 4314 ldiaz
    protected java.util.ArrayList dimensions = new ArrayList();
76 6185 jaume
77 3483 jaume
    /**
78
     * Tells if this layer accepts getFeatureInfo requests.
79
     */
80 4301 ldiaz
    private boolean queryable = false;
81 6185 jaume
82 3505 jaume
    /**
83 3750 ldiaz
     * 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 6185 jaume
92 3750 ldiaz
    /**
93
     * when present and non-zero fixedWidth and fixedHeight indicate that the server is not
94 6185 jaume
     * able to produce a map of the layer at a width and height different from the fixed sizes indicated.
95 3750 ldiaz
     */
96 4222 jaume
    private int fixedWidth = 0;
97
    private int fixedHeight = 0;
98 6185 jaume
99 3750 ldiaz
    /**
100 3505 jaume
     * Tells if this layer can be served with transparency.
101
     */
102
    private boolean transparency;
103 6185 jaume
104 3323 ldiaz
    /**
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 6185 jaume
     *
108 3323 ldiaz
     */
109 6185 jaume
    public abstract void parse(KXmlParser parser, TreeMap layerTreeMap)
110
    throws IOException, XmlPullParserException;
111
112 4314 ldiaz
    //public abstract ArrayList getAllDimensions();
113 6185 jaume
114 3755 ldiaz
    /**
115
     * add a new keyword to the keywordList.
116
     * @param key
117
     */
118 3750 ldiaz
    protected void addkeyword(String key)
119
    {
120 6185 jaume
            keywordList.add(key);
121 3750 ldiaz
    }
122
    public ArrayList getKeywords()
123
    {
124
            return keywordList;
125
    }
126 3483 jaume
    /**
127
     * <p>Adds a style to the styles vector</p>
128 6185 jaume
     * @param _style
129 3483 jaume
     */
130 29658 jpiera
    public void addStyle(org.gvsig.remoteclient.wms.WMSStyle _style) {
131 6185 jaume
        styles.add( _style );    }
132
133 3520 jaume
   /**
134 6185 jaume
     * <p>Gets the style vector</p>
135
     * @return
136 3483 jaume
     */
137 6185 jaume
    public ArrayList getStyles() {
138 3780 ldiaz
            ArrayList list = new ArrayList();
139
            if (styles != null)
140
                    list.addAll(styles);
141 3779 ldiaz
            if (this.getParent()!= null)
142
            {
143 3780 ldiaz
                    //return getAllStyles(this);
144
                    if(this.getParent().getStyles() != null)
145
                            list.addAll(this.getParent().getStyles());
146 3779 ldiaz
            }
147 3780 ldiaz
        return list;
148 6185 jaume
    }
149
150 3779 ldiaz
    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 3780 ldiaz
                            list.add(styles.get(i));
158 3779 ldiaz
                    }
159
                    return list;
160
            }
161
            else
162
            {
163
                    return styles;
164
            }
165
    }
166 3341 ldiaz
    /**
167
     * <p>Adds a bbox to the Bboxes vector</p>
168
     * @param bbox
169
     */
170 3523 jaume
    public void addBBox(BoundaryBox bbox) {
171 3483 jaume
        bBoxes.put(bbox.getSrs(), bbox);
172 6185 jaume
    }
173
174 3341 ldiaz
    /**
175 6185 jaume
     * <p>returns the bbox with that id in the Bboxes vector</p>
176
     * @param id
177 3341 ldiaz
     */
178 3523 jaume
    public BoundaryBox getBbox(String id) {
179 3824 ldiaz
            if ((id.compareToIgnoreCase( CapabilitiesTags.EPSG_4326 )==0)
180
                    ||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0))
181
            {
182
                    if (latLonBbox != null)
183 6185 jaume
                    return (BoundaryBox)latLonBbox;
184 3824 ldiaz
            }
185 3523 jaume
        BoundaryBox b = (BoundaryBox) bBoxes.get(id);
186
        if (b == null && parent!=null)
187
            return parent.getBbox(id);
188 3483 jaume
        return (BoundaryBox)bBoxes.get(id);
189 6185 jaume
    }
190
191 3341 ldiaz
    /**
192 6185 jaume
     * <p>Gets the bBoxes vector</p>
193
     * @return
194 3341 ldiaz
     */
195 3523 jaume
    public Hashtable getBboxes() {
196 3483 jaume
        return bBoxes;
197 6185 jaume
    }
198
199
200 3341 ldiaz
    //Methods to manipulate the box that defines the layer extent in LatLon SRS.
201 3483 jaume
    public BoundaryBox getLatLonBox()
202
    {
203
        return latLonBbox;
204
    }
205
    public void setLatLonBox(BoundaryBox box)
206
    {
207
        latLonBbox = box;
208 6185 jaume
    }
209 3341 ldiaz
    /**
210 6185 jaume
     * <p>adds a new srs to the srs vector</p>
211
     */
212 3341 ldiaz
    public void addSrs(String srs)
213
    {
214 4222 jaume
            if (!this.srs.contains(srs))
215
                    this.srs.add(srs);
216 3341 ldiaz
    }
217 6185 jaume
218 3341 ldiaz
    public Vector getAllSrs()
219 6185 jaume
    {
220 3655 jaume
        Vector mySRSs = (Vector) this.srs.clone();
221
        if (parent!=null)
222
            mySRSs.addAll(parent.getAllSrs());
223
        return mySRSs;
224 6185 jaume
225 4222 jaume
//            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 6185 jaume
//            }
238
239 3341 ldiaz
    }
240 3483 jaume
    /**
241
     * <p>gets the maximum scale for this layer</p>
242 6185 jaume
     * @return
243 3483 jaume
     */
244 6185 jaume
    public double getScaleMax() {
245 3323 ldiaz
        return scaleMax;
246 6185 jaume
    }
247
248 3483 jaume
    /**
249
     * <p>gets the minimum scale for this layer</p>
250 6185 jaume
     * @return
251 3483 jaume
     */
252 6185 jaume
    public double getScaleMin() {
253 3323 ldiaz
        return scaleMin;
254 6185 jaume
    }
255
256 3483 jaume
    /**
257
     * <p>sets the minimum scale for this layer to be visible.</p>
258 6185 jaume
     *
259
     * @param scale
260 3483 jaume
     */
261 6185 jaume
    public void setScaleMin(double scale) {
262 3323 ldiaz
        scaleMin = scale;
263 6185 jaume
    }
264
265 3483 jaume
    /**
266
     * <p>sets the maximum scale for this layer to be visible</p>
267 6185 jaume
     * @param scale
268 3483 jaume
     */
269 6185 jaume
    public void setScaleMax(double scale) {
270 3323 ldiaz
        scaleMax = scale;
271 6185 jaume
    }
272
273 3483 jaume
    /**
274
     * <p> gets the dimension vector defined in this layer</p>
275 6185 jaume
     * @return
276 3483 jaume
     */
277 4314 ldiaz
    public abstract ArrayList getDimensions();
278 6185 jaume
//    public ArrayList getDimensions() {
279 4314 ldiaz
//        return dimensions;
280 6185 jaume
//    }
281
282 4314 ldiaz
    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 3537 jaume
//    /**
294
//     * <p>Sets the dimension vector defined for this layer</p>
295 6185 jaume
//     * @param v
296 3537 jaume
//     */
297 6185 jaume
//    public void setDimensions(ArrayList v) {
298
//        dimensions = (ArrayList)v.clone();
299
//    }
300
301 3483 jaume
    /**
302
     * <p>Adds a dimension to the dimension vector </p>
303 6185 jaume
     * @param dimension
304 3483 jaume
     */
305 29658 jpiera
    public void addDimension(org.gvsig.remoteclient.wms.WMSDimension dimension) {
306 3535 jaume
        dimensions.add(dimension);
307 6185 jaume
    }
308
309 3483 jaume
    /**
310
     * <p>Gets layer name</p>
311 6185 jaume
     * @return
312 3483 jaume
     */
313 6185 jaume
    public String getName() {
314 3341 ldiaz
        return this.name;
315 6185 jaume
    }
316
317 3483 jaume
    /**
318
     * <p>Sets layer name</p>
319 6185 jaume
     * @param _name
320 3483 jaume
     */
321 6185 jaume
    public void setName(String name) {
322
        this.name = name;
323
    }
324
325 3483 jaume
    /**
326
     * <p>Gets layer title</p>
327 6185 jaume
     * @return
328 3483 jaume
     */
329 6185 jaume
    public String getTitle() {
330 3323 ldiaz
        return title;
331 6185 jaume
    }
332
333 3483 jaume
    /**
334
     * <p>Sets the layer title</p>
335 6185 jaume
     * @param _title
336 3483 jaume
     */
337 6185 jaume
    public void setTitle(String title) {
338 3341 ldiaz
        this.title = title;
339 6185 jaume
    }
340
341 3483 jaume
    /**
342
     * <p>Gets the layer abstract</p>
343 6185 jaume
     * @return
344 3483 jaume
     */
345 6185 jaume
    public String getAbstract() {
346 3323 ldiaz
        return layerAbstract;
347 6185 jaume
    }
348
349 3483 jaume
    /**
350
     * <p>Sets the layer abstract</p>
351 6185 jaume
     * @param m_abstract
352 3483 jaume
     */
353 6185 jaume
    public void setAbstract(String _abstract) {
354 3323 ldiaz
        layerAbstract = _abstract;
355 3377 ldiaz
    }
356 6185 jaume
357
358 3403 jaume
    public ArrayList getChildren() {
359 3483 jaume
        return children;
360 3403 jaume
    }
361 6185 jaume
362
363 3403 jaume
    public void setChildren(ArrayList children) {
364 3483 jaume
        this.children = children;
365 3403 jaume
    }
366 6185 jaume
367
368 3523 jaume
    public WMSLayer getParent() {
369 3483 jaume
        return parent;
370 3403 jaume
    }
371 6185 jaume
372
373 3660 ldiaz
    public void setParent(WMSLayer parent) {
374 3483 jaume
        this.parent = parent;
375 3403 jaume
    }
376 6185 jaume
377 3403 jaume
    public String toString(){
378 3483 jaume
        return this.getTitle();
379 3403 jaume
    }
380 3483 jaume
381 6185 jaume
382 3483 jaume
    /**
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 3505 jaume
397
    /**
398 3750 ldiaz
     * 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 6185 jaume
410 3750 ldiaz
    /**
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 6185 jaume
    }
422
423 4222 jaume
    public void setfixedWidth(int w) {
424 3750 ldiaz
        fixedWidth = w;
425
    }
426 6185 jaume
427 4222 jaume
    public int getfixedWidth() {
428 3750 ldiaz
        return fixedWidth;
429
    }
430 6185 jaume
431 4222 jaume
    public void setfixedHeight(int h) {
432 3750 ldiaz
        fixedHeight = h;
433
    }
434 6185 jaume
435 4222 jaume
    public int getfixedHeight() {
436 3750 ldiaz
        return fixedHeight;
437 6185 jaume
    }
438
439 3750 ldiaz
    /**
440 3505 jaume
     * @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 6185 jaume
446 3755 ldiaz
    //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 6185 jaume
450 3750 ldiaz
    /**
451 3755 ldiaz
     * 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 6185 jaume
460 3755 ldiaz
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.KEYWORDLIST);
461
            currentTag = parser.nextTag();
462 6185 jaume
463
        while (!end)
464 3755 ldiaz
            {
465
                         switch(currentTag)
466
                         {
467
                                case KXmlParser.START_TAG:
468
                                        if (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0)
469 6185 jaume
                                        {
470 3755 ldiaz
                                                value = parser.nextText();
471
                                                if ((value != null) && (value.length() > 0 ))
472 6185 jaume
                                                        addkeyword(value);
473
                                        }
474 3755 ldiaz
                                        break;
475
                                case KXmlParser.END_TAG:
476
                                        if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0)
477
                                                end = true;
478
                                        break;
479 6185 jaume
                                case KXmlParser.TEXT:
480 3755 ldiaz
                                        break;
481
                         }
482
                         if (!end)
483
                         {
484
                                 currentTag = parser.next();
485
                         }
486
            }
487 6185 jaume
            parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.KEYWORDLIST);
488 3755 ldiaz
    }
489 6185 jaume
490 3755 ldiaz
    /**
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 6185 jaume
499 3755 ldiaz
        //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 4222 jaume
                setfixedWidth(Integer.parseInt(value));
528 6185 jaume
        }
529 3755 ldiaz
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDHEIGHT);
530
        if (value != null)
531
        {
532 4222 jaume
                setfixedHeight(Integer.parseInt(value));
533 6185 jaume
        }
534
    }
535
536
537 3755 ldiaz
    /**
538 3750 ldiaz
     * <p>Inner class describing the MetadataURL tag in OGC specifications in WMS</p>
539 6185 jaume
     *
540 3750 ldiaz
     */
541
    protected class MetadataURL
542 6185 jaume
    {
543 3750 ldiaz
            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 6185 jaume
     }
557 3750 ldiaz
558
    /**
559
     * <p>Inner class describing the DataURL tag in OGC specifications in WMS</p>
560 6185 jaume
     *
561 3750 ldiaz
     */
562
    protected class DataURL
563 6185 jaume
    {
564 3750 ldiaz
            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 6185 jaume
     }
578 3377 ldiaz
}