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