svn-gvsig-desktop / branches / v05 / libraries / libRemoteServices / src / org / gvsig / remoteClient / wms / WMSLayer.java @ 3946
History | View | Annotate | Download (13.6 KB)
1 | 3323 | ldiaz | package org.gvsig.remoteClient.wms; |
---|---|---|---|
2 | |||
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 | 3341 | ldiaz | import org.gvsig.remoteClient.utils.BoundaryBox; |
10 | 3755 | ldiaz | import org.gvsig.remoteClient.utils.CapabilitiesTags; |
11 | 3323 | ldiaz | 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 | 3483 | jaume | |
20 | protected ArrayList children; |
||
21 | 3523 | jaume | protected WMSLayer parent;
|
22 | 3483 | jaume | |
23 | /**
|
||
24 | * <p>Layer Abstract field in the capabilities document </p>
|
||
25 | */
|
||
26 | 3323 | ldiaz | private String layerAbstract; |
27 | 3483 | jaume | |
28 | /**
|
||
29 | * <p>Themes provided by the WMS for the layer</p>
|
||
30 | */
|
||
31 | 3520 | jaume | public ArrayList styles = new ArrayList(); |
32 | 3323 | ldiaz | |
33 | 3483 | jaume | /**
|
34 | * <p>Layer name</p>
|
||
35 | */
|
||
36 | 3323 | ldiaz | private String name; |
37 | 3483 | jaume | |
38 | /**
|
||
39 | * <p>Layer title</p>
|
||
40 | */
|
||
41 | 3323 | ldiaz | private String title; |
42 | 3483 | jaume | |
43 | 3750 | ldiaz | private ArrayList keywordList = new ArrayList(); |
44 | 3483 | jaume | /**
|
45 | * <p>Layer srs.</p>
|
||
46 | */
|
||
47 | 3911 | ldiaz | protected Vector srs = new Vector(); |
48 | 3483 | jaume | |
49 | /**
|
||
50 | * <p>extents for each srs the layer can be reproyected to</p>
|
||
51 | */
|
||
52 | 3523 | jaume | private Hashtable bBoxes = new Hashtable(); |
53 | 3341 | ldiaz | |
54 | 3483 | jaume | /**
|
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 | 3341 | ldiaz | private org.gvsig.remoteClient.utils.BoundaryBox latLonBbox;
|
60 | 3483 | jaume | |
61 | /**
|
||
62 | * <p>min scale for the layer to be visible</p>
|
||
63 | */
|
||
64 | 3323 | ldiaz | private double scaleMin; |
65 | 3483 | jaume | |
66 | /**
|
||
67 | * <p>max scale for the layer to be visible</p>
|
||
68 | */
|
||
69 | 3323 | ldiaz | private double scaleMax; |
70 | 3483 | jaume | |
71 | /**
|
||
72 | * <p>Dimensions defined for the layer in the capabilities doc</p>
|
||
73 | */
|
||
74 | 3535 | jaume | private java.util.ArrayList dimensions = new ArrayList(); |
75 | 3483 | jaume | /**
|
76 | * Tells if this layer accepts getFeatureInfo requests.
|
||
77 | */
|
||
78 | 3341 | ldiaz | private boolean queryable; |
79 | 3750 | ldiaz | |
80 | 3505 | jaume | /**
|
81 | 3750 | ldiaz | * Tells if this layer is opaque.
|
82 | */
|
||
83 | private boolean opaque = false; |
||
84 | /**
|
||
85 | * when set to true, noSubsets indicates that the server is not able to make a map
|
||
86 | * of a geographic area other than the layer's bounding box.
|
||
87 | */
|
||
88 | private boolean m_noSubSets = false; |
||
89 | |||
90 | /**
|
||
91 | * when present and non-zero fixedWidth and fixedHeight indicate that the server is not
|
||
92 | * able to produce a map of the layer at a width and height different from the fixed sizes indicated.
|
||
93 | */
|
||
94 | private double fixedWidth = 0; |
||
95 | private double fixedHeight = 0; |
||
96 | |||
97 | /**
|
||
98 | 3505 | jaume | * Tells if this layer can be served with transparency.
|
99 | */
|
||
100 | private boolean transparency; |
||
101 | 3341 | ldiaz | |
102 | 3323 | ldiaz | /**
|
103 | * <p>Parses the LAYER tag in the WMS capabilities, filling the WMSLayer object
|
||
104 | * loading the data in memory to be easily accesed</p>
|
||
105 | *
|
||
106 | */
|
||
107 | 3483 | jaume | public abstract void parse(KXmlParser parser, TreeMap layerTreeMap) |
108 | throws IOException, XmlPullParserException; |
||
109 | |||
110 | |||
111 | 3755 | ldiaz | /**
|
112 | * add a new keyword to the keywordList.
|
||
113 | * @param key
|
||
114 | */
|
||
115 | 3750 | ldiaz | protected void addkeyword(String key) |
116 | { |
||
117 | keywordList.add(key); |
||
118 | } |
||
119 | public ArrayList getKeywords() |
||
120 | { |
||
121 | return keywordList;
|
||
122 | } |
||
123 | 3483 | jaume | /**
|
124 | * <p>Adds a style to the styles vector</p>
|
||
125 | * @param _style
|
||
126 | */
|
||
127 | 3323 | ldiaz | public void addStyle(org.gvsig.remoteClient.wms.WMSStyle _style) { |
128 | 3520 | jaume | styles.add( _style ); } |
129 | 3483 | jaume | |
130 | 3520 | jaume | /**
|
131 | 3483 | jaume | * <p>Gets the style vector</p>
|
132 | * @return
|
||
133 | */
|
||
134 | 3779 | ldiaz | public ArrayList getStyles() { |
135 | 3780 | ldiaz | ArrayList list = new ArrayList(); |
136 | if (styles != null) |
||
137 | list.addAll(styles); |
||
138 | 3779 | ldiaz | if (this.getParent()!= null) |
139 | { |
||
140 | 3780 | ldiaz | //return getAllStyles(this);
|
141 | if(this.getParent().getStyles() != null) |
||
142 | list.addAll(this.getParent().getStyles());
|
||
143 | 3779 | ldiaz | } |
144 | 3780 | ldiaz | return list;
|
145 | 3323 | ldiaz | } |
146 | 3483 | jaume | |
147 | 3779 | ldiaz | public ArrayList getAllStyles(WMSLayer layer) |
148 | { |
||
149 | if (layer.getParent()!= null) |
||
150 | { |
||
151 | ArrayList list = getAllStyles(layer.getParent());
|
||
152 | for(int i = 0; i < this.styles.size(); i++) |
||
153 | { |
||
154 | 3780 | ldiaz | list.add(styles.get(i)); |
155 | 3779 | ldiaz | } |
156 | return list;
|
||
157 | } |
||
158 | else
|
||
159 | { |
||
160 | return styles;
|
||
161 | } |
||
162 | } |
||
163 | 3341 | ldiaz | /**
|
164 | * <p>Adds a bbox to the Bboxes vector</p>
|
||
165 | * @param bbox
|
||
166 | */
|
||
167 | 3523 | jaume | public void addBBox(BoundaryBox bbox) { |
168 | 3483 | jaume | bBoxes.put(bbox.getSrs(), bbox); |
169 | } |
||
170 | |||
171 | 3341 | ldiaz | /**
|
172 | * <p>returns the bbox with that id in the Bboxes vector</p>
|
||
173 | * @param id
|
||
174 | */
|
||
175 | 3523 | jaume | public BoundaryBox getBbox(String id) { |
176 | 3824 | ldiaz | if ((id.compareToIgnoreCase( CapabilitiesTags.EPSG_4326 )==0) |
177 | ||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0))
|
||
178 | { |
||
179 | if (latLonBbox != null) |
||
180 | return (BoundaryBox)latLonBbox;
|
||
181 | } |
||
182 | 3523 | jaume | BoundaryBox b = (BoundaryBox) bBoxes.get(id); |
183 | if (b == null && parent!=null) |
||
184 | return parent.getBbox(id);
|
||
185 | 3483 | jaume | return (BoundaryBox)bBoxes.get(id);
|
186 | } |
||
187 | |||
188 | 3341 | ldiaz | /**
|
189 | * <p>Gets the bBoxes vector</p>
|
||
190 | * @return
|
||
191 | */
|
||
192 | 3523 | jaume | public Hashtable getBboxes() { |
193 | 3483 | jaume | return bBoxes;
|
194 | } |
||
195 | 3341 | ldiaz | |
196 | 3483 | jaume | |
197 | 3341 | ldiaz | //Methods to manipulate the box that defines the layer extent in LatLon SRS.
|
198 | 3483 | jaume | public BoundaryBox getLatLonBox()
|
199 | { |
||
200 | return latLonBbox;
|
||
201 | } |
||
202 | public void setLatLonBox(BoundaryBox box) |
||
203 | { |
||
204 | latLonBbox = box; |
||
205 | } |
||
206 | 3341 | ldiaz | /**
|
207 | * <p>adds a new srs to the srs vector</p>
|
||
208 | */
|
||
209 | public void addSrs(String srs) |
||
210 | { |
||
211 | 3872 | ldiaz | if (!this.srs.contains(srs)) |
212 | this.srs.add(srs);
|
||
213 | 3341 | ldiaz | } |
214 | |||
215 | public Vector getAllSrs() |
||
216 | 3655 | jaume | { |
217 | 3914 | ldiaz | Vector mySRSs = (Vector) this.srs.clone(); |
218 | if (parent!=null) |
||
219 | mySRSs.addAll(parent.getAllSrs()); |
||
220 | return mySRSs;
|
||
221 | 3911 | ldiaz | |
222 | 3914 | ldiaz | // if (this.getParent()!= null)
|
223 | // {
|
||
224 | // Vector list = this.getParent().getAllSrs();
|
||
225 | // for(int i = 0; i < this.srs.size(); i++)
|
||
226 | // {
|
||
227 | // list.add(srs.get(i));
|
||
228 | // }
|
||
229 | // return list;
|
||
230 | // }
|
||
231 | // else
|
||
232 | // {
|
||
233 | // return srs;
|
||
234 | // }
|
||
235 | 3911 | ldiaz | |
236 | 3341 | ldiaz | } |
237 | 3483 | jaume | /**
|
238 | * <p>gets the maximum scale for this layer</p>
|
||
239 | * @return
|
||
240 | */
|
||
241 | 3323 | ldiaz | public double getScaleMax() { |
242 | return scaleMax;
|
||
243 | } |
||
244 | 3483 | jaume | |
245 | /**
|
||
246 | * <p>gets the minimum scale for this layer</p>
|
||
247 | * @return
|
||
248 | */
|
||
249 | 3323 | ldiaz | public double getScaleMin() { |
250 | return scaleMin;
|
||
251 | } |
||
252 | 3483 | jaume | |
253 | /**
|
||
254 | * <p>sets the minimum scale for this layer to be visible.</p>
|
||
255 | *
|
||
256 | * @param scale
|
||
257 | */
|
||
258 | 3323 | ldiaz | public void setScaleMin(double scale) { |
259 | scaleMin = scale; |
||
260 | } |
||
261 | 3483 | jaume | |
262 | /**
|
||
263 | * <p>sets the maximum scale for this layer to be visible</p>
|
||
264 | * @param scale
|
||
265 | */
|
||
266 | 3323 | ldiaz | public void setScaleMax(double scale) { |
267 | scaleMax = scale; |
||
268 | } |
||
269 | 3483 | jaume | |
270 | /**
|
||
271 | * <p> gets the dimension vector defined in this layer</p>
|
||
272 | * @return
|
||
273 | */
|
||
274 | 3535 | jaume | public ArrayList getDimensions() { |
275 | 3323 | ldiaz | return dimensions;
|
276 | } |
||
277 | 3483 | jaume | |
278 | 3537 | jaume | // /**
|
279 | // * <p>Sets the dimension vector defined for this layer</p>
|
||
280 | // * @param v
|
||
281 | // */
|
||
282 | // public void setDimensions(ArrayList v) {
|
||
283 | // dimensions = (ArrayList)v.clone();
|
||
284 | // }
|
||
285 | 3483 | jaume | |
286 | /**
|
||
287 | * <p>Adds a dimension to the dimension vector </p>
|
||
288 | * @param dimension
|
||
289 | */
|
||
290 | 3520 | jaume | public void addDimension(org.gvsig.remoteClient.wms.WMSDimension dimension) { |
291 | 3535 | jaume | dimensions.add(dimension); |
292 | 3323 | ldiaz | } |
293 | 3483 | jaume | |
294 | /**
|
||
295 | * <p>Gets layer name</p>
|
||
296 | * @return
|
||
297 | */
|
||
298 | 3323 | ldiaz | public String getName() { |
299 | 3341 | ldiaz | return this.name; |
300 | 3323 | ldiaz | } |
301 | 3483 | jaume | |
302 | /**
|
||
303 | * <p>Sets layer name</p>
|
||
304 | * @param _name
|
||
305 | */
|
||
306 | 3341 | ldiaz | public void setName(String name) { |
307 | this.name = name;
|
||
308 | 3323 | ldiaz | } |
309 | 3483 | jaume | |
310 | /**
|
||
311 | * <p>Gets layer title</p>
|
||
312 | * @return
|
||
313 | */
|
||
314 | 3323 | ldiaz | public String getTitle() { |
315 | return title;
|
||
316 | } |
||
317 | 3483 | jaume | |
318 | /**
|
||
319 | * <p>Sets the layer title</p>
|
||
320 | * @param _title
|
||
321 | */
|
||
322 | 3341 | ldiaz | public void setTitle(String title) { |
323 | this.title = title;
|
||
324 | 3323 | ldiaz | } |
325 | 3483 | jaume | |
326 | /**
|
||
327 | * <p>Gets the layer abstract</p>
|
||
328 | * @return
|
||
329 | */
|
||
330 | 3323 | ldiaz | public String getAbstract() { |
331 | return layerAbstract;
|
||
332 | } |
||
333 | 3483 | jaume | |
334 | /**
|
||
335 | * <p>Sets the layer abstract</p>
|
||
336 | * @param m_abstract
|
||
337 | */
|
||
338 | 3323 | ldiaz | public void setAbstract(String _abstract) { |
339 | layerAbstract = _abstract; |
||
340 | 3377 | ldiaz | } |
341 | 3403 | jaume | |
342 | |||
343 | public ArrayList getChildren() { |
||
344 | 3483 | jaume | return children;
|
345 | 3403 | jaume | } |
346 | |||
347 | |||
348 | public void setChildren(ArrayList children) { |
||
349 | 3483 | jaume | this.children = children;
|
350 | 3403 | jaume | } |
351 | |||
352 | |||
353 | 3523 | jaume | public WMSLayer getParent() {
|
354 | 3483 | jaume | return parent;
|
355 | 3403 | jaume | } |
356 | |||
357 | |||
358 | 3660 | ldiaz | public void setParent(WMSLayer parent) { |
359 | 3483 | jaume | this.parent = parent;
|
360 | 3403 | jaume | } |
361 | |||
362 | public String toString(){ |
||
363 | 3483 | jaume | return this.getTitle(); |
364 | 3403 | jaume | } |
365 | 3520 | jaume | |
366 | 3483 | jaume | |
367 | /**
|
||
368 | * Tells if this layer accepts getFeatureInfo requests.
|
||
369 | */
|
||
370 | public boolean isQueryable() { |
||
371 | return queryable;
|
||
372 | } |
||
373 | |||
374 | |||
375 | /**
|
||
376 | * @param queryable The queryable to set.
|
||
377 | */
|
||
378 | public void setQueryable(boolean queryable) { |
||
379 | this.queryable = queryable;
|
||
380 | } |
||
381 | 3505 | jaume | |
382 | /**
|
||
383 | 3750 | ldiaz | * Tells if this layer is opaque.
|
384 | */
|
||
385 | public boolean isOpaque() { |
||
386 | return opaque;
|
||
387 | } |
||
388 | /**
|
||
389 | * @param opaque.
|
||
390 | */
|
||
391 | public void setOpaque(boolean opaque) { |
||
392 | this.opaque = opaque;
|
||
393 | } |
||
394 | |||
395 | /**
|
||
396 | * Tells if this layer is subsettable
|
||
397 | */
|
||
398 | public boolean noSubSets() { |
||
399 | return this.m_noSubSets; |
||
400 | } |
||
401 | /**
|
||
402 | * @param set layer nosubsets attribute.
|
||
403 | */
|
||
404 | public void setNoSubSets(boolean _noSubSets) { |
||
405 | m_noSubSets = _noSubSets; |
||
406 | } |
||
407 | |||
408 | public void setfixedWidth(double w) { |
||
409 | fixedWidth = w; |
||
410 | } |
||
411 | |||
412 | public double getfixedWidth() { |
||
413 | return fixedWidth;
|
||
414 | } |
||
415 | |||
416 | public void setfixedHeight(double h) { |
||
417 | fixedHeight = h; |
||
418 | } |
||
419 | |||
420 | public double getfixedHeight() { |
||
421 | return fixedHeight;
|
||
422 | } |
||
423 | |||
424 | /**
|
||
425 | 3505 | jaume | * @return <b>true</b> if this layer can be served with transparency, otherwise <b>false</b>
|
426 | */
|
||
427 | public boolean hasTransparency() { |
||
428 | return transparency;
|
||
429 | } |
||
430 | 3750 | ldiaz | |
431 | 3755 | ldiaz | //Methods to parse tags that are common to several versions of WMS.
|
432 | //In case there is a version which has different implemantation of one of this tags
|
||
433 | // the subclass can overwrite this method
|
||
434 | |||
435 | 3750 | ldiaz | /**
|
436 | 3755 | ldiaz | * Parses the keywordlist from the capabilities and fills this list in the WMSLayer.
|
437 | * @param parser
|
||
438 | */
|
||
439 | protected void parseKeywordList(KXmlParser parser) throws IOException, XmlPullParserException |
||
440 | { |
||
441 | int currentTag;
|
||
442 | boolean end = false; |
||
443 | String value;
|
||
444 | |||
445 | parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.KEYWORDLIST);
|
||
446 | currentTag = parser.nextTag(); |
||
447 | |||
448 | while (!end)
|
||
449 | { |
||
450 | switch(currentTag)
|
||
451 | { |
||
452 | case KXmlParser.START_TAG:
|
||
453 | if (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0) |
||
454 | { |
||
455 | value = parser.nextText(); |
||
456 | if ((value != null) && (value.length() > 0 )) |
||
457 | addkeyword(value); |
||
458 | } |
||
459 | break;
|
||
460 | case KXmlParser.END_TAG:
|
||
461 | if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0) |
||
462 | end = true;
|
||
463 | break;
|
||
464 | case KXmlParser.TEXT:
|
||
465 | break;
|
||
466 | } |
||
467 | if (!end)
|
||
468 | { |
||
469 | currentTag = parser.next(); |
||
470 | } |
||
471 | } |
||
472 | parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.KEYWORDLIST);
|
||
473 | } |
||
474 | |||
475 | /**
|
||
476 | * Reads and parses the layer attributes
|
||
477 | * Maybe this method should be moved to the WMSLayer. Until now the attributes are teh same for all versions.
|
||
478 | * @param parser
|
||
479 | */
|
||
480 | protected void readLayerAttributes(KXmlParser parser) |
||
481 | { |
||
482 | String value = new String(); |
||
483 | |||
484 | //First of all set whether the layer is Queryable reading the attribute.
|
||
485 | value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
|
||
486 | if (value != null) |
||
487 | { |
||
488 | if (value.compareTo("0")==0) |
||
489 | setQueryable(false);
|
||
490 | else
|
||
491 | setQueryable(true);
|
||
492 | } |
||
493 | value = parser.getAttributeValue("", CapabilitiesTags.OPAQUE);
|
||
494 | if (value != null) |
||
495 | { |
||
496 | if (value.compareTo("0")==0) |
||
497 | setOpaque(false);
|
||
498 | else
|
||
499 | setOpaque(true);
|
||
500 | } |
||
501 | value = parser.getAttributeValue("", CapabilitiesTags.NOSUBSETS);
|
||
502 | if (value != null) |
||
503 | { |
||
504 | if (value.compareTo("0")==0) |
||
505 | setNoSubSets(false);
|
||
506 | else
|
||
507 | setNoSubSets(true);
|
||
508 | } |
||
509 | value = parser.getAttributeValue("", CapabilitiesTags.FIXEDWIDTH);
|
||
510 | if (value != null) |
||
511 | { |
||
512 | setfixedWidth(Double.parseDouble(value));
|
||
513 | } |
||
514 | value = parser.getAttributeValue("", CapabilitiesTags.FIXEDHEIGHT);
|
||
515 | if (value != null) |
||
516 | { |
||
517 | setfixedHeight(Double.parseDouble(value));
|
||
518 | } |
||
519 | } |
||
520 | |||
521 | |||
522 | /**
|
||
523 | 3750 | ldiaz | * <p>Inner class describing the MetadataURL tag in OGC specifications in WMS</p>
|
524 | *
|
||
525 | */
|
||
526 | protected class MetadataURL |
||
527 | { |
||
528 | public MetadataURL()
|
||
529 | { |
||
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 | { |
||
549 | public DataURL()
|
||
550 | { |
||
551 | type = new String(); |
||
552 | format = new String(); |
||
553 | onlineResource_xlink = new String(); |
||
554 | onlineResource_type = new String(); |
||
555 | onlineResource_href = new String(); |
||
556 | } |
||
557 | public String type; |
||
558 | public String format; |
||
559 | public String onlineResource_xlink; |
||
560 | public String onlineResource_type; |
||
561 | public String onlineResource_href; |
||
562 | } |
||
563 | 3377 | ldiaz | } |