]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Format / WFST / v1_1_0.js
1 /**
2  * @requires OpenLayers/Format/WFST/v1.js
3  * @requires OpenLayers/Format/Filter/v1_1_0.js
4  */
5
6 /**
7  * Class: OpenLayers.Format.WFST.v1_1_0
8  * A format for creating WFS v1.1.0 transactions.  Create a new instance with the
9  *     <OpenLayers.Format.WFST.v1_1_0> constructor.
10  *
11  * Inherits from:
12  *  - <OpenLayers.Format.Filter.v1_1_0>
13  *  - <OpenLayers.Format.WFST.v1>
14  */
15 OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(
16     OpenLayers.Format.Filter.v1_1_0, OpenLayers.Format.WFST.v1, {
17     
18     /**
19      * Property: version
20      * {String} WFS version number.
21      */
22     version: "1.1.0",
23     
24     /**
25      * Property: schemaLocations
26      * {Object} Properties are namespace aliases, values are schema locations.
27      */
28     schemaLocations: {
29         "wfs": "http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
30     },
31     
32     /**
33      * Constructor: OpenLayers.Format.WFST.v1_1_0
34      * A class for parsing and generating WFS v1.1.0 transactions.
35      *
36      * Parameters:
37      * options - {Object} Optional object whose properties will be set on the
38      *     instance.
39      *
40      * Valid options properties:
41      * featureType - {String} Local (without prefix) feature typeName (required).
42      * featureNS - {String} Feature namespace (optional).
43      * featurePrefix - {String} Feature namespace alias (optional - only used
44      *     if featureNS is provided).  Default is 'feature'.
45      * geometryName - {String} Name of geometry attribute.  Default is 'the_geom'.
46      */
47     initialize: function(options) {
48         OpenLayers.Format.Filter.v1_1_0.prototype.initialize.apply(this, [options]);
49         OpenLayers.Format.WFST.v1.prototype.initialize.apply(this, [options]);
50     },
51     
52     /**
53      * Property: readers
54      * Contains public functions, grouped by namespace prefix, that will
55      *     be applied when a namespaced node is found matching the function
56      *     name.  The function will be applied in the scope of this parser
57      *     with two arguments: the node being read and a context object passed
58      *     from the parent.
59      */
60     readers: {
61         "wfs": OpenLayers.Util.applyDefaults({
62             "TransactionResponse": function(node, obj) {
63                 obj.insertIds = [];
64                 obj.success = false;
65                 this.readChildNodes(node, obj);
66             },
67             "TransactionSummary": function(node, obj) {
68                 // this is a limited test of success
69                 obj.success = true;
70             },
71             "InsertResults": function(node, obj) {
72                 this.readChildNodes(node, obj);
73             },
74             "Feature": function(node, container) {
75                 var obj = {fids: []};
76                 this.readChildNodes(node, obj);
77                 container.insertIds.push(obj.fids[0]);
78             }
79         }, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]),
80         "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"],
81         "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"],
82         "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.readers["ogc"]
83     },
84
85     /**
86      * Property: writers
87      * As a compliment to the readers property, this structure contains public
88      *     writing functions grouped by namespace alias and named like the
89      *     node names they produce.
90      */
91     writers: {
92         "wfs": OpenLayers.Util.applyDefaults({
93             "Query": function(options) {
94                 options = OpenLayers.Util.extend({
95                     featureNS: this.featureNS,
96                     featurePrefix: this.featurePrefix,
97                     featureType: this.featureType,
98                     srsName: this.srsName
99                 }, options);
100                 var node = this.createElementNSPlus("wfs:Query", {
101                     attributes: {
102                         typeName: (options.featureNS ? options.featurePrefix + ":" : "") +
103                             options.featureType,
104                         srsName: options.srsName
105                     }
106                 });
107                 if(options.featureNS) {
108                     node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
109                 }
110                 if(options.propertyNames) {
111                     for(var i=0,len = options.propertyNames.length; i<len; i++) {
112                         this.writeNode(
113                             "wfs:PropertyName", 
114                             {property: options.propertyNames[i]},
115                             node
116                         );
117                     }
118                 }
119                 if(options.filter) {
120                     this.setFilterProperty(options.filter);
121                     this.writeNode("ogc:Filter", options.filter, node);
122                 }
123                 return node;
124             },
125             "PropertyName": function(obj) {
126                 return this.createElementNSPlus("wfs:PropertyName", {
127                     value: obj.property
128                 });
129             }            
130         }, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]),
131         "gml": OpenLayers.Format.GML.v3.prototype.writers["gml"],
132         "feature": OpenLayers.Format.GML.v3.prototype.writers["feature"],
133         "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers["ogc"]
134     },
135
136     CLASS_NAME: "OpenLayers.Format.WFST.v1_1_0" 
137 });