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:
@@ -4,7 +4,7 @@
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Format/XML.js
|
||||
* @requires OpenLayers/Format/XML/VersionedOGC.js
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -13,9 +13,9 @@
|
||||
* constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
* - <OpenLayers.Format.XML.VersionedOGC>
|
||||
*/
|
||||
OpenLayers.Format.OWSCommon = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
OpenLayers.Format.OWSCommon = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, {
|
||||
|
||||
/**
|
||||
* APIProperty: defaultVersion
|
||||
@@ -23,19 +23,6 @@ OpenLayers.Format.OWSCommon = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
*/
|
||||
defaultVersion: "1.0.0",
|
||||
|
||||
/**
|
||||
* APIProperty: version
|
||||
* {String} Specify a version string if one is known.
|
||||
*/
|
||||
version: null,
|
||||
|
||||
/**
|
||||
* Property: parser
|
||||
* {Object} Instance of the versioned parser. Cached for multiple read and
|
||||
* write calls of the same version.
|
||||
*/
|
||||
parser: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.OWSCommon
|
||||
* Create a new parser for OWSCommon.
|
||||
@@ -46,21 +33,18 @@ OpenLayers.Format.OWSCommon = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
*/
|
||||
|
||||
/**
|
||||
* APIMethod: read
|
||||
* Read an OWSCommon document and return an object.
|
||||
* Method: getVersion
|
||||
* Returns the version to use. Subclasses can override this function
|
||||
* if a different version detection is needed.
|
||||
*
|
||||
* Parameters:
|
||||
* data - {String | DOMElement} Data to read.
|
||||
* options - {Object} Options for the reader.
|
||||
* root - {DOMElement}
|
||||
* options - {Object} Optional configuration object.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} An object representing the structure of the document.
|
||||
* {String} The version to use.
|
||||
*/
|
||||
read: function(data, options) {
|
||||
if(typeof data == "string") {
|
||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||
}
|
||||
var root = data.documentElement;
|
||||
getVersion: function(root, options) {
|
||||
var version = this.version;
|
||||
if(!version) {
|
||||
// remember version does not correspond to the OWS version
|
||||
@@ -75,19 +59,20 @@ OpenLayers.Format.OWSCommon = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
version = this.defaultVersion;
|
||||
}
|
||||
}
|
||||
if(!this.parser || this.parser.VERSION != version) {
|
||||
var format = OpenLayers.Format.OWSCommon[
|
||||
"v" + version.replace(/\./g, "_")
|
||||
];
|
||||
if(!format) {
|
||||
throw "Can't find a OWSCommon parser for version " +
|
||||
version;
|
||||
}
|
||||
this.parser = new format(this.options);
|
||||
}
|
||||
var ows = this.parser.read(data, options);
|
||||
return ows;
|
||||
return version;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: read
|
||||
* Read an OWSCommon document and return an object.
|
||||
*
|
||||
* Parameters:
|
||||
* data - {String | DOMElement} Data to read.
|
||||
* options - {Object} Options for the reader.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} An object representing the structure of the document.
|
||||
*/
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.OWSCommon"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user