]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Format/Filter.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Format / Filter.js
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. */
4
5 /**
6  * @requires OpenLayers/Format/XML.js
7  * @requires OpenLayers/Filter/FeatureId.js
8  * @requires OpenLayers/Filter/Logical.js
9  * @requires OpenLayers/Filter/Comparison.js
10  */
11
12 /**
13  * Class: OpenLayers.Format.Filter
14  * Read/Wite ogc:Filter. Create a new instance with the <OpenLayers.Format.Filter>
15  *     constructor.
16  * 
17  * Inherits from:
18  *  - <OpenLayers.Format.XML>
19  */
20 OpenLayers.Format.Filter = OpenLayers.Class(OpenLayers.Format.XML, {
21     
22     /**
23      * APIProperty: defaultVersion
24      * {String} Version number to assume if none found.  Default is "1.0.0".
25      */
26     defaultVersion: "1.0.0",
27     
28     /**
29      * APIProperty: version
30      * {String} Specify a version string if one is known.
31      */
32     version: null,
33     
34     /**
35      * Property: parser
36      * {Object} Instance of the versioned parser.  Cached for multiple read and
37      *     write calls of the same version.
38      */
39     parser: null,
40
41     /**
42      * Constructor: OpenLayers.Format.Filter
43      * Create a new parser for Filter.
44      *
45      * Parameters:
46      * options - {Object} An optional object whose properties will be set on
47      *     this instance.
48      */
49     initialize: function(options) {
50         OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
51     },
52
53     /**
54      * APIMethod: write
55      * Write an ogc:Filter given a filter object.
56      *
57      * Parameters:
58      * filter - {<OpenLayers.Filter>} An filter.
59      * options - {Object} Optional configuration object.
60      *
61      * Returns:
62      * {Elment} An ogc:Filter element node.
63      */
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, "_")
70             ];
71             if(!format) {
72                 throw "Can't find a Filter parser for version " +
73                       version;
74             }
75             this.parser = new format(this.options);
76         }
77         return this.parser.write(filter);
78         //return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
79     },
80     
81     /**
82      * APIMethod: read
83      * Read and Filter doc and return an object representing the Filter.
84      *
85      * Parameters:
86      * data - {String | DOMElement} Data to read.
87      *
88      * Returns:
89      * {<OpenLayers.Filter>} A filter object.
90      */
91     read: function(data) {
92         if(typeof data == "string") {
93             data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
94         }
95         var version = this.version;
96         if(!version) {
97             version = this.defaultVersion;
98         }
99         if(!this.parser || this.parser.VERSION != version) {
100             var format = OpenLayers.Format.Filter[
101                 "v" + version.replace(/\./g, "_")
102             ];
103             if(!format) {
104                 throw "Can't find a Filter parser for version " +
105                       version;
106             }
107             this.parser = new format(this.options);
108         }
109         var filter = this.parser.read(data);
110         return filter;
111     },
112
113     CLASS_NAME: "OpenLayers.Format.Filter" 
114 });