]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Format/Filter/v1_1_0.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Format / Filter / v1_1_0.js
1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2  * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3  * full text of the license. */
4
5 /**
6  * @requires OpenLayers/Format/Filter/v1.js
7  * @requires OpenLayers/Format/GML/v3.js
8  */
9
10 /**
11  * Class: OpenLayers.Format.Filter.v1_1_0
12  * Write ogc:Filter version 1.1.0.
13  *
14  * Differences from the v1.0.0 parser:
15  *  - uses GML v3 instead of GML v2
16  *  - reads matchCase attribute on ogc:PropertyIsEqual and
17  *        ogc:PropertyIsNotEqualelements.
18  *  - writes matchCase attribute from comparison filters of type EQUAL_TO and
19  *        type NOT_EQUAL_TO.
20  * 
21  * Inherits from:
22  *  - <OpenLayers.Format.Filter.v1>
23  */
24 OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
25     OpenLayers.Format.GML.v3, OpenLayers.Format.Filter.v1, {
26     
27     /**
28      * Constant: VERSION
29      * {String} 1.1.0
30      */
31     VERSION: "1.1.0",
32     
33     /**
34      * Property: schemaLocation
35      * {String} http://www.opengis.net/ogc/filter/1.1.0/filter.xsd
36      */
37     schemaLocation: "http://www.opengis.net/ogc/filter/1.1.0/filter.xsd",
38
39     /**
40      * Constructor: OpenLayers.Format.Filter.v1_1_0
41      * Instances of this class are not created directly.  Use the
42      *     <OpenLayers.Format.Filter> constructor instead.
43      *
44      * Parameters:
45      * options - {Object} An optional object whose properties will be set on
46      *     this instance.
47      */
48     initialize: function(options) {
49         OpenLayers.Format.GML.v3.prototype.initialize.apply(
50             this, [options]
51         );
52     },
53
54     /**
55      * Property: readers
56      * Contains public functions, grouped by namespace prefix, that will
57      *     be applied when a namespaced node is found matching the function
58      *     name.  The function will be applied in the scope of this parser
59      *     with two arguments: the node being read and a context object passed
60      *     from the parent.
61      */
62     readers: {
63         "ogc": OpenLayers.Util.applyDefaults({
64             "PropertyIsEqualTo": function(node, obj) {
65                 var matchCase = node.getAttribute("matchCase");
66                 var filter = new OpenLayers.Filter.Comparison({
67                     type: OpenLayers.Filter.Comparison.EQUAL_TO,
68                     matchCase: !(matchCase === "false" || matchCase === "0")
69                 });
70                 this.readChildNodes(node, filter);
71                 obj.filters.push(filter);
72             },
73             "PropertyIsNotEqualTo": function(node, obj) {
74                 var matchCase = node.getAttribute("matchCase");
75                 var filter = new OpenLayers.Filter.Comparison({
76                     type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
77                     matchCase: !(matchCase === "false" || matchCase === "0")
78                 });
79                 this.readChildNodes(node, filter);
80                 obj.filters.push(filter);
81             }
82         }, OpenLayers.Format.Filter.v1.prototype.readers["ogc"]),
83         "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"],
84         "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"]        
85     },
86
87     /**
88      * Property: writers
89      * As a compliment to the readers property, this structure contains public
90      *     writing functions grouped by namespace alias and named like the
91      *     node names they produce.
92      */
93     writers: {
94         "ogc": OpenLayers.Util.applyDefaults({
95             "PropertyIsEqualTo": function(filter) {
96                 var node = this.createElementNSPlus("ogc:PropertyIsEqualTo", {
97                     attributes: {matchCase: filter.matchCase}
98                 });
99                 // no ogc:expression handling for now
100                 this.writeNode("PropertyName", filter, node);
101                 this.writeNode("Literal", filter.value, node);
102                 return node;
103             },
104             "PropertyIsNotEqualTo": function(filter) {
105                 var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo", {
106                     attributes: {matchCase: filter.matchCase}
107                 });
108                 // no ogc:expression handling for now
109                 this.writeNode("PropertyName", filter, node);
110                 this.writeNode("Literal", filter.value, node);
111                 return node;
112             },
113             "BBOX": function(filter) {
114                 var node = this.createElementNSPlus("ogc:BBOX");
115                 this.writeNode("PropertyName", filter, node);
116                 var box = this.writeNode("gml:Envelope", filter.value);
117                 if(filter.projection) {
118                     box.setAttribute("srsName", filter.projection);
119                 }
120                 node.appendChild(box); 
121                 return node;
122             }}, OpenLayers.Format.Filter.v1.prototype.writers["ogc"]),
123             
124         "gml": OpenLayers.Format.GML.v3.prototype.writers["gml"],
125         "feature": OpenLayers.Format.GML.v3.prototype.writers["feature"]
126     },
127
128     /**
129      * Method: writeSpatial
130      *
131      * Read a {<OpenLayers.Filter.Spatial>} filter and converts it into XML.
132      *
133      * Parameters:
134      * filter - {<OpenLayers.Filter.Spatial>} The filter.
135      * name - {String} Name of the generated XML element.
136      *
137      * Returns:
138      * {DOMElement} The created XML element.
139      */
140     writeSpatial: function(filter, name) {
141         var node = this.createElementNSPlus("ogc:"+name);
142         this.writeNode("PropertyName", filter, node);
143         var child;
144         if(filter.value instanceof OpenLayers.Geometry) {
145             child = this.writeNode("feature:_geometry", filter.value).firstChild;
146         } else {
147             child = this.writeNode("gml:Envelope", filter.value);
148         }
149         if(filter.projection) {
150             child.setAttribute("srsName", filter.projection);
151         }
152         node.appendChild(child);
153         return node;
154     },
155
156     CLASS_NAME: "OpenLayers.Format.Filter.v1_1_0" 
157
158 });