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
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -14,29 +14,23 @@
|
||||
* specifically only for Geocoding. No support for Reverse Geocoding as yet.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
* - <OpenLayers.Format.XML.VersionedOGC>
|
||||
*/
|
||||
OpenLayers.Format.XLS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
OpenLayers.Format.XLS = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, {
|
||||
|
||||
/**
|
||||
* APIProperty: defaultVersion
|
||||
* {String} Version number to assume if none found. Default is "1.1.0".
|
||||
*/
|
||||
defaultVersion: "1.1.0",
|
||||
|
||||
|
||||
/**
|
||||
* APIProperty: version
|
||||
* {String} Specify a version string if one is known.
|
||||
* APIProperty: stringifyOutput
|
||||
* {Boolean} If true, write will return a string otherwise a DOMElement.
|
||||
* Default is true.
|
||||
*/
|
||||
version: null,
|
||||
stringifyOutput: true,
|
||||
|
||||
/**
|
||||
* Property: parser
|
||||
* {Object} Instance of the versioned parser. Cached for multiple read and
|
||||
* write calls of the same version.
|
||||
*/
|
||||
parser: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.XLS
|
||||
* Create a new parser for XLS.
|
||||
@@ -45,9 +39,6 @@ OpenLayers.Format.XLS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: write
|
||||
@@ -60,22 +51,6 @@ OpenLayers.Format.XLS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
* Returns:
|
||||
* {String} An XLS document string.
|
||||
*/
|
||||
write: function(request, options) {
|
||||
var version = (options && options.version) ||
|
||||
this.version || this.defaultVersion;
|
||||
if(!this.parser || this.parser.VERSION != version) {
|
||||
var format = OpenLayers.Format.XLS[
|
||||
"v" + version.replace(/\./g, "_")
|
||||
];
|
||||
if(!format) {
|
||||
throw "Can't find an XLS parser for version " +
|
||||
version;
|
||||
}
|
||||
this.parser = new format(this.options);
|
||||
}
|
||||
var root = this.parser.write(request);
|
||||
return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: read
|
||||
@@ -88,31 +63,6 @@ OpenLayers.Format.XLS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
* Returns:
|
||||
* {Object} An object representing the GeocodeResponse.
|
||||
*/
|
||||
read: function(data, options) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
if(!this.parser || this.parser.VERSION != version) {
|
||||
var format = OpenLayers.Format.XLS[
|
||||
"v" + version.replace(/\./g, "_")
|
||||
];
|
||||
if(!format) {
|
||||
throw "Can't find an XLS parser for version " +
|
||||
version;
|
||||
}
|
||||
this.parser = new format(this.options);
|
||||
}
|
||||
var xls = this.parser.read(data, options);
|
||||
return xls;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.XLS"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user