1 /* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
3 * for the full text of the license. */
6 * @requires OpenLayers/Format/XML.js
7 * @requires OpenLayers/Style.js
8 * @requires OpenLayers/Rule.js
9 * @requires OpenLayers/Filter/FeatureId.js
10 * @requires OpenLayers/Filter/Logical.js
11 * @requires OpenLayers/Filter/Comparison.js
12 * @requires OpenLayers/Filter/Spatial.js
16 * Class: OpenLayers.Format.SLD
17 * Read/Wite SLD. Create a new instance with the <OpenLayers.Format.SLD>
21 * - <OpenLayers.Format.XML>
23 OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
26 * APIProperty: defaultVersion
27 * {String} Version number to assume if none found. Default is "1.0.0".
29 defaultVersion: "1.0.0",
32 * APIProperty: version
33 * {String} Specify a version string if one is known.
38 * APIProperty: namedLayersAsArray
39 * {Boolean} Generate a namedLayers array. If false, the namedLayers
40 * property value will be an object keyed by layer name. Default is
43 namedLayersAsArray: false,
47 * {Object} Instance of the versioned parser. Cached for multiple read and
48 * write calls of the same version.
53 * Constructor: OpenLayers.Format.SLD
54 * Create a new parser for SLD.
57 * options - {Object} An optional object whose properties will be set on
60 initialize: function(options) {
61 OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
66 * Write a SLD document given a list of styles.
69 * sld - {Object} An object representing the SLD.
70 * options - {Object} Optional configuration object.
73 * {String} An SLD document string.
75 write: function(sld, options) {
76 var version = (options && options.version) ||
77 this.version || this.defaultVersion;
78 if(!this.parser || this.parser.VERSION != version) {
79 var format = OpenLayers.Format.SLD[
80 "v" + version.replace(/\./g, "_")
83 throw "Can't find a SLD parser for version " +
86 this.parser = new format(this.options);
88 var root = this.parser.write(sld);
89 return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
94 * Read and SLD doc and return an object representing the SLD.
97 * data - {String | DOMElement} Data to read.
98 * options - {Object} Options for the reader.
101 * {Object} An object representing the SLD.
103 read: function(data, options) {
104 if(typeof data == "string") {
105 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
107 var root = data.documentElement;
108 var version = this.version;
110 version = root.getAttribute("version");
112 version = this.defaultVersion;
115 if(!this.parser || this.parser.VERSION != version) {
116 var format = OpenLayers.Format.SLD[
117 "v" + version.replace(/\./g, "_")
120 throw "Can't find a SLD parser for version " +
123 this.parser = new format(this.options);
125 var sld = this.parser.read(data, options);
129 CLASS_NAME: "OpenLayers.Format.SLD"