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/Filter/FeatureId.js
8 * @requires OpenLayers/Filter/Logical.js
9 * @requires OpenLayers/Filter/Comparison.js
13 * Class: OpenLayers.Format.Filter
14 * Read/Wite ogc:Filter. Create a new instance with the <OpenLayers.Format.Filter>
18 * - <OpenLayers.Format.XML>
20 OpenLayers.Format.Filter = OpenLayers.Class(OpenLayers.Format.XML, {
23 * APIProperty: defaultVersion
24 * {String} Version number to assume if none found. Default is "1.0.0".
26 defaultVersion: "1.0.0",
29 * APIProperty: version
30 * {String} Specify a version string if one is known.
36 * {Object} Instance of the versioned parser. Cached for multiple read and
37 * write calls of the same version.
42 * Constructor: OpenLayers.Format.Filter
43 * Create a new parser for Filter.
46 * options - {Object} An optional object whose properties will be set on
49 initialize: function(options) {
50 OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
55 * Write an ogc:Filter given a filter object.
58 * filter - {<OpenLayers.Filter>} An filter.
59 * options - {Object} Optional configuration object.
62 * {Elment} An ogc:Filter element node.
64 write: function(filter, options) {
65 var version = (options && options.version) ||
66 this.version || this.defaultVersion;
67 if(!this.parser || this.parser.VERSION != version) {
68 var format = OpenLayers.Format.Filter[
69 "v" + version.replace(/\./g, "_")
72 throw "Can't find a Filter parser for version " +
75 this.parser = new format(this.options);
77 return this.parser.write(filter);
78 //return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
83 * Read and Filter doc and return an object representing the Filter.
86 * data - {String | DOMElement} Data to read.
89 * {<OpenLayers.Filter>} A filter object.
91 read: function(data) {
92 if(typeof data == "string") {
93 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
95 var version = this.version;
97 version = this.defaultVersion;
99 if(!this.parser || this.parser.VERSION != version) {
100 var format = OpenLayers.Format.Filter[
101 "v" + version.replace(/\./g, "_")
104 throw "Can't find a Filter parser for version " +
107 this.parser = new format(this.options);
109 var filter = this.parser.read(data);
113 CLASS_NAME: "OpenLayers.Format.Filter"