]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Format/WMSCapabilities.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Format / WMSCapabilities.js
1 /**
2  * @requires OpenLayers/Format.js
3  */
4
5 /**
6  * Class: OpenLayers.Format.WMSCapabilities
7  * Read WMS Capabilities.
8  * 
9  * Inherits from:
10  *  - <OpenLayers.Format>
11  */
12 OpenLayers.Format.WMSCapabilities = OpenLayers.Class(OpenLayers.Format.XML, {
13     
14     /**
15      * APIProperty: defaultVersion
16      * {String} Version number to assume if none found.  Default is "1.1.1".
17      */
18     defaultVersion: "1.1.1",
19     
20     /**
21      * APIProperty: version
22      * {String} Specify a version string if one is known.
23      */
24     version: null,
25     
26     /**
27      * Property: parser
28      * {<OpenLayers.Format>} A cached versioned format used for reading.
29      */
30     parser: null,
31
32     /**
33      * Constructor: OpenLayers.Format.WMSCapabilities
34      * Create a new parser for WMS capabilities.
35      *
36      * Parameters:
37      * options - {Object} An optional object whose properties will be set on
38      *     this instance.
39      */
40     initialize: function(options) {
41         OpenLayers.Format.prototype.initialize.apply(this, [options]);
42         this.options = options;
43     },
44
45     /**
46      * APIMethod: read
47      * Read capabilities data from a string, and return a list of layers. 
48      * 
49      * Parameters: 
50      * data - {String} or {DOMElement} data to read/parse.
51      *
52      * Returns:
53      * {Array} List of named layers.
54      */
55     read: function(data) {
56         if(typeof data == "string") {
57             data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
58         }
59         var root = data.documentElement;
60         var version = this.version || root.getAttribute("version") || this.defaultVersion;
61         if(!this.parser || this.parser.version !== version) {
62             var constr = OpenLayers.Format.WMSCapabilities[
63                 "v" + version.replace(/\./g, "_")
64             ];
65             if(!constr) {
66                 throw "Can't find a WMS capabilities parser for version " + version;
67             }
68             var parser = new constr(this.options);
69         }
70         var capabilities = parser.read(data);
71         capabilities.version = version;
72         return capabilities;
73     },
74     
75     CLASS_NAME: "OpenLayers.Format.WMSCapabilities" 
76
77 });