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
* @requires OpenLayers/Style.js
* @requires OpenLayers/Rule.js
* @requires OpenLayers/Filter/FeatureId.js
@@ -19,9 +19,9 @@
* constructor.
*
* Inherits from:
* - <OpenLayers.Format.XML>
* - <OpenLayers.Format.XML.VersionedOGC>
*/
OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, {
/**
* APIProperty: defaultVersion
@@ -30,10 +30,11 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
defaultVersion: "1.0.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,
/**
* APIProperty: namedLayersAsArray
@@ -43,22 +44,6 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
*/
namedLayersAsArray: false,
/**
* Property: parser
* {Object} Instance of the versioned parser. Cached for multiple read and
* write calls of the same version.
*/
parser: null,
/**
* Constructor: OpenLayers.Format.SLD
* Create a new parser for SLD.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
/**
* APIMethod: write
* Write a SLD document given a list of styles.
@@ -70,22 +55,6 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
* Returns:
* {String} An SLD document string.
*/
write: function(sld, options) {
var version = (options && options.version) ||
this.version || this.defaultVersion;
if(!this.parser || this.parser.VERSION != version) {
var format = OpenLayers.Format.SLD[
"v" + version.replace(/\./g, "_")
];
if(!format) {
throw "Can't find a SLD parser for version " +
version;
}
this.parser = new format(this.options);
}
var root = this.parser.write(sld);
return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
},
/**
* APIMethod: read
@@ -98,31 +67,6 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
* Returns:
* {Object} An object representing the SLD.
*/
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.SLD[
"v" + version.replace(/\./g, "_")
];
if(!format) {
throw "Can't find a SLD parser for version " +
version;
}
this.parser = new format(this.options);
}
var sld = this.parser.read(data, options);
return sld;
},
CLASS_NAME: "OpenLayers.Format.SLD"
});