implement versioned format base class, r=ahocevar (closes #2954)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12155 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2011-07-05 09:42:34 +00:00
parent 3b70536695
commit c59e225d8f
17 changed files with 346 additions and 504 deletions

View File

@@ -4,7 +4,7 @@
* full text of the license. */
/**
* @requires OpenLayers/Format/XML.js
* @requires OpenLayers/Format/XML/VersionedOGC.js
*/
/**
@@ -13,9 +13,9 @@
* DescribeLayer is meant to couple WMS to WFS and WCS
*
* Inherits from:
* - <OpenLayers.Format.XML>
* - <OpenLayers.Format.XML.VersionedOGC>
*/
OpenLayers.Format.WMSDescribeLayer = OpenLayers.Class(OpenLayers.Format.XML, {
OpenLayers.Format.WMSDescribeLayer = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, {
/**
* APIProperty: defaultVersion
@@ -24,10 +24,26 @@ OpenLayers.Format.WMSDescribeLayer = OpenLayers.Class(OpenLayers.Format.XML, {
defaultVersion: "1.1.1",
/**
* APIProperty: version
* {String} Specify a version string if one is known.
* Method: getVersion
* Returns the version to use. Subclasses can override this function
* if a different version detection is needed.
*
* Parameters:
* root - {DOMElement}
* options - {Object} Optional configuration object.
*
* Returns:
* {String} The version to use.
*/
version: null,
getVersion: function(root, options) {
var version = OpenLayers.Format.XML.VersionedOGC.prototype.getVersion.apply(
this, arguments);
// these are identical to us, but some WMS use 1.1.1 and some use 1.1.0
if (version == "1.1.1" || version == "1.1.0") {
version = "1.1";
}
return version;
},
/**
* Constructor: OpenLayers.Format.WMSDescribeLayer
@@ -53,34 +69,6 @@ OpenLayers.Format.WMSDescribeLayer = OpenLayers.Class(OpenLayers.Format.XML, {
* - {String} owsURL: the online resource
* - {String} typeName: the name of the typename on the service
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
var root = data.documentElement;
var version = this.version;
if(!version) {
version = root.getAttribute("version");
if(!version) {
version = this.defaultVersion;
}
}
// these are identical to us, but some WMS use 1.1.1 and some use 1.1.0
if (version == "1.1.1" || version == "1.1.0") {
version = "1.1";
}
var constructor = OpenLayers.Format.WMSDescribeLayer[
"v" + version.replace(/\./g, "_")
];
if(!constructor) {
throw "Can't find a WMS DescribeLayer parser for version " +
version;
}
var parser = new constructor(this.options);
var describelayer = parser.read(data);
describelayer.version = version;
return describelayer;
},
CLASS_NAME: "OpenLayers.Format.WMSDescribeLayer"