]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Format/WMSDescribeLayer/v1_1.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Format / WMSDescribeLayer / v1_1.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/WMSDescribeLayer.js
7  */
8
9 /**
10  * Class: OpenLayers.Format.WMSDescribeLayer.v1_1
11  * Read SLD WMS DescribeLayer response for WMS 1.1.X
12  * WMS 1.1.X is tightly coupled to SLD 1.0.0
13  *
14  * Example DescribeLayer request: 
15  * http://demo.opengeo.org/geoserver/wms?request=DescribeLayer&version=1.1.1&layers=topp:states
16  *
17  * Inherits from:
18  *  - <OpenLayers.Format.WMSDescribeLayer>
19  */
20 OpenLayers.Format.WMSDescribeLayer.v1_1 = OpenLayers.Class(
21     OpenLayers.Format.WMSDescribeLayer, {
22     
23     /**
24      * Constructor: OpenLayers.Format.WMSDescribeLayer
25      * Create a new parser for WMS DescribeLayer responses.
26      *
27      * Parameters:
28      * options - {Object} An optional object whose properties will be set on
29      *     this instance.
30      */
31     initialize: function(options) {
32         OpenLayers.Format.WMSDescribeLayer.prototype.initialize.apply(this, 
33             [options]);
34     },
35
36     /**
37      * APIMethod: read
38      * Read DescribeLayer data from a string, and return the response. 
39      * The OGC defines 2 formats which are allowed for output,
40      * so we need to parse these 2 types for version 1.1.X
41      * 
42      * Parameters: 
43      * data - {String} or {DOMElement} data to read/parse.
44      *
45      * Returns:
46      * {Array} Array of {<LayerDescription>} objects which have:
47      * - {String} owsType: WFS/WCS
48      * - {String} owsURL: the online resource
49      * - {String} typeName: the name of the typename on the service
50      */
51     read: function(data) {
52         if(typeof data == "string") {
53             data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
54         }
55         var root = data.documentElement;
56         var children = root.childNodes; 
57         var describelayer = [];
58         for(var i=0; i<children.length; ++i) { 
59             childNode = children[i];
60             nodeName = childNode.nodeName; 
61             if (nodeName == 'LayerDescription') {
62                 var owsType = '';
63                 var owsURL = '';
64                 var typeName = '';
65                 // check for owsType and owsURL attributes
66                 if (childNode.getAttribute('owsType')) {
67                   owsType = childNode.getAttribute('owsType');
68                   owsURL = childNode.getAttribute('owsURL');
69                 } else {
70                     // look for wfs or wcs attribute
71                     if (childNode.getAttribute('wfs') != '') {
72                         owsType = 'WFS';
73                         owsURL = childNode.getAttribute('wfs');
74                     } else if (childNode.getAttribute('wcs') != '') {
75                         owsType = 'WCS';
76                         owsURL = childNode.getAttribute('wcs');
77                     }
78                 }
79                 // look for Query child
80                 query = childNode.getElementsByTagName('Query');
81                 if(query.length > 0) {
82                     typeName = query[0].getAttribute('typeName');
83                     if (!typeName) {
84                         // because of Ionic bug
85                         typeName = query[0].getAttribute('typename');
86                     }
87                 }
88                 describelayer.push({owsType: owsType, owsURL: owsURL, typeName: typeName}); 
89             }
90         }
91         return describelayer;
92     },
93     
94     CLASS_NAME: "OpenLayers.Format.WMSDescribeLayer.v1_1" 
95
96 });