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