]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Format/WMSDescribeLayer.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Format / WMSDescribeLayer.js
1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2  * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3  * full text of the license. */
4
5 /**
6  * @requires OpenLayers/Format/XML.js
7  */
8
9 /**
10  * Class: OpenLayers.Format.WMSDescribeLayer
11  * Read SLD WMS DescribeLayer response
12  * DescribeLayer is meant to couple WMS to WFS and WCS
13  * 
14  * Inherits from:
15  *  - <OpenLayers.Format.XML>
16  */
17 OpenLayers.Format.WMSDescribeLayer = OpenLayers.Class(OpenLayers.Format.XML, {
18
19     /**
20      * APIProperty: defaultVersion
21      * {String} Version number to assume if none found.  Default is "1.1.1".
22      */
23     defaultVersion: "1.1.1",
24    
25     /**
26      * APIProperty: version
27      * {String} Specify a version string if one is known.
28      */
29     version: null,
30
31     /**
32      * Constructor: OpenLayers.Format.WMSDescribeLayer
33      * Create a new parser for WMS DescribeLayer responses.
34      *
35      * Parameters:
36      * options - {Object} An optional object whose properties will be set on
37      *     this instance.
38      */
39     initialize: function(options) {
40         OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
41         this.options = options;
42     },
43
44     /**
45      * APIMethod: read
46      * Read DescribeLayer data from a string, and return the response. 
47      * The OGC currently defines 2 formats which are allowed for output,
48      * so we need to parse these 2 types
49      * 
50      * Parameters: 
51      * data - {String} or {DOMElement} data to read/parse.
52      *
53      * Returns:
54      * {Array} Array of {<LayerDescription>} objects which have:
55      * - {String} owsType: WFS/WCS
56      * - {String} owsURL: the online resource
57      * - {String} typeName: the name of the typename on the service
58      */
59     read: function(data) {
60         if(typeof data == "string") {
61             data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
62         }
63         var root = data.documentElement;
64         var version = this.version;
65         if(!version) {
66             version = root.getAttribute("version");
67             if(!version) {
68                 version = this.defaultVersion;
69             }
70         }
71         // these are identical to us, but some WMS use 1.1.1 and some use 1.1.0
72         if (version == "1.1.1" || version == "1.1.0") {
73             version = "1.1";
74         }
75         var constructor = OpenLayers.Format.WMSDescribeLayer[
76             "v" + version.replace(/\./g, "_")
77         ];
78         if(!constructor) {
79             throw "Can't find a WMS DescribeLayer parser for version " + 
80                 version;
81         }
82         var parser = new constructor(this.options);
83         var describelayer = parser.read(data);
84         describelayer.version = version;
85         return describelayer;
86     },
87     
88     CLASS_NAME: "OpenLayers.Format.WMSDescribeLayer" 
89
90 });