diff options
author | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
commit | ea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch) | |
tree | af67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/lib/OpenLayers/Protocol | |
parent | 59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff) | |
download | postrunner-ea346a785dc1b3f7c156f6fc33da634e1f1a627b.zip |
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/lib/OpenLayers/Protocol')
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/CSW.js | 30 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/CSW/v2_0_2.js | 127 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/HTTP.js | 580 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/SOS.js | 33 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/SOS/v1_0_0.js | 133 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/Script.js | 377 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/WFS.js | 86 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/WFS/v1.js | 453 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/WFS/v1_0_0.js | 44 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Protocol/WFS/v1_1_0.js | 68 |
10 files changed, 1931 insertions, 0 deletions
diff --git a/misc/openlayers/lib/OpenLayers/Protocol/CSW.js b/misc/openlayers/lib/OpenLayers/Protocol/CSW.js new file mode 100644 index 0000000..5641182 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/CSW.js @@ -0,0 +1,30 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol.js + */ + +/** + * Class: OpenLayers.Protocol.CSW + * Used to create a versioned CSW protocol. Default version is 2.0.2. + */ +OpenLayers.Protocol.CSW = function(options) { + options = OpenLayers.Util.applyDefaults( + options, OpenLayers.Protocol.CSW.DEFAULTS + ); + var cls = OpenLayers.Protocol.CSW["v"+options.version.replace(/\./g, "_")]; + if(!cls) { + throw "Unsupported CSW version: " + options.version; + } + return new cls(options); +}; + +/** + * Constant: OpenLayers.Protocol.CSW.DEFAULTS + */ +OpenLayers.Protocol.CSW.DEFAULTS = { + "version": "2.0.2" +}; diff --git a/misc/openlayers/lib/OpenLayers/Protocol/CSW/v2_0_2.js b/misc/openlayers/lib/OpenLayers/Protocol/CSW/v2_0_2.js new file mode 100644 index 0000000..88bfd75 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/CSW/v2_0_2.js @@ -0,0 +1,127 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol/CSW.js + * @requires OpenLayers/Format/CSWGetRecords/v2_0_2.js + */ + +/** + * Class: OpenLayers.Protocol.CSW.v2_0_2 + * CS-W (Catalogue services for the Web) version 2.0.2 protocol. + * + * Inherits from: + * - <OpenLayers.Protocol> + */ +OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { + + /** + * Property: formatOptions + * {Object} Optional options for the format. If a format is not provided, + * this property can be used to extend the default format options. + */ + formatOptions: null, + + /** + * Constructor: OpenLayers.Protocol.CSW.v2_0_2 + * A class for CSW version 2.0.2 protocol management. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + */ + initialize: function(options) { + OpenLayers.Protocol.prototype.initialize.apply(this, [options]); + if(!options.format) { + this.format = new OpenLayers.Format.CSWGetRecords.v2_0_2(OpenLayers.Util.extend({ + }, this.formatOptions)); + } + }, + + /** + * APIMethod: destroy + * Clean up the protocol. + */ + destroy: function() { + if(this.options && !this.options.format) { + this.format.destroy(); + } + this.format = null; + OpenLayers.Protocol.prototype.destroy.apply(this); + }, + + /** + * Method: read + * Construct a request for reading new records from the Catalogue. + */ + read: function(options) { + options = OpenLayers.Util.extend({}, options); + OpenLayers.Util.applyDefaults(options, this.options || {}); + var response = new OpenLayers.Protocol.Response({requestType: "read"}); + + var data = this.format.write(options.params || options); + + response.priv = OpenLayers.Request.POST({ + url: options.url, + callback: this.createCallback(this.handleRead, response, options), + params: options.params, + headers: options.headers, + data: data + }); + + return response; + }, + + /** + * Method: handleRead + * Deal with response from the read request. + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} The response object to pass + * to the user callback. + * This response is given a code property, and optionally a data property. + * The latter represents the CSW records as returned by the call to + * the CSW format read method. + * options - {Object} The user options passed to the read call. + */ + handleRead: function(response, options) { + if(options.callback) { + var request = response.priv; + if(request.status >= 200 && request.status < 300) { + // success + response.data = this.parseData(request); + response.code = OpenLayers.Protocol.Response.SUCCESS; + } else { + // failure + response.code = OpenLayers.Protocol.Response.FAILURE; + } + options.callback.call(options.scope, response); + } + }, + + /** + * Method: parseData + * Read HTTP response body and return records + * + * Parameters: + * request - {XMLHttpRequest} The request object + * + * Returns: + * {Object} The CSW records as returned by the call to the format read method. + */ + parseData: function(request) { + var doc = request.responseXML; + if(!doc || !doc.documentElement) { + doc = request.responseText; + } + if(!doc || doc.length <= 0) { + return null; + } + return this.format.read(doc); + }, + + CLASS_NAME: "OpenLayers.Protocol.CSW.v2_0_2" + +}); diff --git a/misc/openlayers/lib/OpenLayers/Protocol/HTTP.js b/misc/openlayers/lib/OpenLayers/Protocol/HTTP.js new file mode 100644 index 0000000..a53b497 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/HTTP.js @@ -0,0 +1,580 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol.js + * @requires OpenLayers/Request/XMLHttpRequest.js + */ + +/** + * if application uses the query string, for example, for BBOX parameters, + * OpenLayers/Format/QueryStringFilter.js should be included in the build config file + */ + +/** + * Class: OpenLayers.Protocol.HTTP + * A basic HTTP protocol for vector layers. Create a new instance with the + * <OpenLayers.Protocol.HTTP> constructor. + * + * Inherits from: + * - <OpenLayers.Protocol> + */ +OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, { + + /** + * Property: url + * {String} Service URL, read-only, set through the options + * passed to constructor. + */ + url: null, + + /** + * Property: headers + * {Object} HTTP request headers, read-only, set through the options + * passed to the constructor, + * Example: {'Content-Type': 'plain/text'} + */ + headers: null, + + /** + * Property: params + * {Object} Parameters of GET requests, read-only, set through the options + * passed to the constructor, + * Example: {'bbox': '5,5,5,5'} + */ + params: null, + + /** + * Property: callback + * {Object} Function to be called when the <read>, <create>, + * <update>, <delete> or <commit> operation completes, read-only, + * set through the options passed to the constructor. + */ + callback: null, + + /** + * Property: scope + * {Object} Callback execution scope, read-only, set through the + * options passed to the constructor. + */ + scope: null, + + /** + * APIProperty: readWithPOST + * {Boolean} true if read operations are done with POST requests + * instead of GET, defaults to false. + */ + readWithPOST: false, + + /** + * APIProperty: updateWithPOST + * {Boolean} true if update operations are done with POST requests + * defaults to false. + */ + updateWithPOST: false, + + /** + * APIProperty: deleteWithPOST + * {Boolean} true if delete operations are done with POST requests + * defaults to false. + * if true, POST data is set to output of format.write(). + */ + deleteWithPOST: false, + + /** + * Property: wildcarded. + * {Boolean} If true percent signs are added around values + * read from LIKE filters, for example if the protocol + * read method is passed a LIKE filter whose property + * is "foo" and whose value is "bar" the string + * "foo__ilike=%bar%" will be sent in the query string; + * defaults to false. + */ + wildcarded: false, + + /** + * APIProperty: srsInBBOX + * {Boolean} Include the SRS identifier in BBOX query string parameter. + * Default is false. If true and the layer has a projection object set, + * any BBOX filter will be serialized with a fifth item identifying the + * projection. E.g. bbox=-1000,-1000,1000,1000,EPSG:900913 + */ + srsInBBOX: false, + + /** + * Constructor: OpenLayers.Protocol.HTTP + * A class for giving layers generic HTTP protocol. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + * + * Valid options include: + * url - {String} + * headers - {Object} + * params - {Object} URL parameters for GET requests + * format - {<OpenLayers.Format>} + * callback - {Function} + * scope - {Object} + */ + initialize: function(options) { + options = options || {}; + this.params = {}; + this.headers = {}; + OpenLayers.Protocol.prototype.initialize.apply(this, arguments); + + if (!this.filterToParams && OpenLayers.Format.QueryStringFilter) { + var format = new OpenLayers.Format.QueryStringFilter({ + wildcarded: this.wildcarded, + srsInBBOX: this.srsInBBOX + }); + this.filterToParams = function(filter, params) { + return format.write(filter, params); + }; + } + }, + + /** + * APIMethod: destroy + * Clean up the protocol. + */ + destroy: function() { + this.params = null; + this.headers = null; + OpenLayers.Protocol.prototype.destroy.apply(this); + }, + + /** + * APIMethod: filterToParams + * Optional method to translate an <OpenLayers.Filter> object into an object + * that can be serialized as request query string provided. If a custom + * method is not provided, the filter will be serialized using the + * <OpenLayers.Format.QueryStringFilter> class. + * + * Parameters: + * filter - {<OpenLayers.Filter>} filter to convert. + * params - {Object} The parameters object. + * + * Returns: + * {Object} The resulting parameters object. + */ + + /** + * APIMethod: read + * Construct a request for reading new features. + * + * Parameters: + * options - {Object} Optional object for configuring the request. + * This object is modified and should not be reused. + * + * Valid options: + * url - {String} Url for the request. + * params - {Object} Parameters to get serialized as a query string. + * headers - {Object} Headers to be set on the request. + * filter - {<OpenLayers.Filter>} Filter to get serialized as a + * query string. + * readWithPOST - {Boolean} If the request should be done with POST. + * + * Returns: + * {<OpenLayers.Protocol.Response>} A response object, whose "priv" property + * references the HTTP request, this object is also passed to the + * callback function when the request completes, its "features" property + * is then populated with the features received from the server. + */ + read: function(options) { + OpenLayers.Protocol.prototype.read.apply(this, arguments); + options = options || {}; + options.params = OpenLayers.Util.applyDefaults( + options.params, this.options.params); + options = OpenLayers.Util.applyDefaults(options, this.options); + if (options.filter && this.filterToParams) { + options.params = this.filterToParams( + options.filter, options.params + ); + } + var readWithPOST = (options.readWithPOST !== undefined) ? + options.readWithPOST : this.readWithPOST; + var resp = new OpenLayers.Protocol.Response({requestType: "read"}); + if(readWithPOST) { + var headers = options.headers || {}; + headers["Content-Type"] = "application/x-www-form-urlencoded"; + resp.priv = OpenLayers.Request.POST({ + url: options.url, + callback: this.createCallback(this.handleRead, resp, options), + data: OpenLayers.Util.getParameterString(options.params), + headers: headers + }); + } else { + resp.priv = OpenLayers.Request.GET({ + url: options.url, + callback: this.createCallback(this.handleRead, resp, options), + params: options.params, + headers: options.headers + }); + } + return resp; + }, + + /** + * Method: handleRead + * Individual callbacks are created for read, create and update, should + * a subclass need to override each one separately. + * + * Parameters: + * resp - {<OpenLayers.Protocol.Response>} The response object to pass to + * the user callback. + * options - {Object} The user options passed to the read call. + */ + handleRead: function(resp, options) { + this.handleResponse(resp, options); + }, + + /** + * APIMethod: create + * Construct a request for writing newly created features. + * + * Parameters: + * features - {Array({<OpenLayers.Feature.Vector>})} or + * {<OpenLayers.Feature.Vector>} + * options - {Object} Optional object for configuring the request. + * This object is modified and should not be reused. + * + * Returns: + * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response> + * object, whose "priv" property references the HTTP request, this + * object is also passed to the callback function when the request + * completes, its "features" property is then populated with the + * the features received from the server. + */ + create: function(features, options) { + options = OpenLayers.Util.applyDefaults(options, this.options); + + var resp = new OpenLayers.Protocol.Response({ + reqFeatures: features, + requestType: "create" + }); + + resp.priv = OpenLayers.Request.POST({ + url: options.url, + callback: this.createCallback(this.handleCreate, resp, options), + headers: options.headers, + data: this.format.write(features) + }); + + return resp; + }, + + /** + * Method: handleCreate + * Called the the request issued by <create> is complete. May be overridden + * by subclasses. + * + * Parameters: + * resp - {<OpenLayers.Protocol.Response>} The response object to pass to + * any user callback. + * options - {Object} The user options passed to the create call. + */ + handleCreate: function(resp, options) { + this.handleResponse(resp, options); + }, + + /** + * APIMethod: update + * Construct a request updating modified feature. + * + * Parameters: + * feature - {<OpenLayers.Feature.Vector>} + * options - {Object} Optional object for configuring the request. + * This object is modified and should not be reused. + * + * Returns: + * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response> + * object, whose "priv" property references the HTTP request, this + * object is also passed to the callback function when the request + * completes, its "features" property is then populated with the + * the feature received from the server. + */ + update: function(feature, options) { + options = options || {}; + var url = options.url || + feature.url || + this.options.url + "/" + feature.fid; + options = OpenLayers.Util.applyDefaults(options, this.options); + + var resp = new OpenLayers.Protocol.Response({ + reqFeatures: feature, + requestType: "update" + }); + + var method = this.updateWithPOST ? "POST" : "PUT"; + resp.priv = OpenLayers.Request[method]({ + url: url, + callback: this.createCallback(this.handleUpdate, resp, options), + headers: options.headers, + data: this.format.write(feature) + }); + + return resp; + }, + + /** + * Method: handleUpdate + * Called the the request issued by <update> is complete. May be overridden + * by subclasses. + * + * Parameters: + * resp - {<OpenLayers.Protocol.Response>} The response object to pass to + * any user callback. + * options - {Object} The user options passed to the update call. + */ + handleUpdate: function(resp, options) { + this.handleResponse(resp, options); + }, + + /** + * APIMethod: delete + * Construct a request deleting a removed feature. + * + * Parameters: + * feature - {<OpenLayers.Feature.Vector>} + * options - {Object} Optional object for configuring the request. + * This object is modified and should not be reused. + * + * Returns: + * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response> + * object, whose "priv" property references the HTTP request, this + * object is also passed to the callback function when the request + * completes. + */ + "delete": function(feature, options) { + options = options || {}; + var url = options.url || + feature.url || + this.options.url + "/" + feature.fid; + options = OpenLayers.Util.applyDefaults(options, this.options); + + var resp = new OpenLayers.Protocol.Response({ + reqFeatures: feature, + requestType: "delete" + }); + + var method = this.deleteWithPOST ? "POST" : "DELETE"; + var requestOptions = { + url: url, + callback: this.createCallback(this.handleDelete, resp, options), + headers: options.headers + }; + if (this.deleteWithPOST) { + requestOptions.data = this.format.write(feature); + } + resp.priv = OpenLayers.Request[method](requestOptions); + + return resp; + }, + + /** + * Method: handleDelete + * Called the the request issued by <delete> is complete. May be overridden + * by subclasses. + * + * Parameters: + * resp - {<OpenLayers.Protocol.Response>} The response object to pass to + * any user callback. + * options - {Object} The user options passed to the delete call. + */ + handleDelete: function(resp, options) { + this.handleResponse(resp, options); + }, + + /** + * Method: handleResponse + * Called by CRUD specific handlers. + * + * Parameters: + * resp - {<OpenLayers.Protocol.Response>} The response object to pass to + * any user callback. + * options - {Object} The user options passed to the create, read, update, + * or delete call. + */ + handleResponse: function(resp, options) { + var request = resp.priv; + if(options.callback) { + if(request.status >= 200 && request.status < 300) { + // success + if(resp.requestType != "delete") { + resp.features = this.parseFeatures(request); + } + resp.code = OpenLayers.Protocol.Response.SUCCESS; + } else { + // failure + resp.code = OpenLayers.Protocol.Response.FAILURE; + } + options.callback.call(options.scope, resp); + } + }, + + /** + * Method: parseFeatures + * Read HTTP response body and return features. + * + * Parameters: + * request - {XMLHttpRequest} The request object + * + * Returns: + * {Array({<OpenLayers.Feature.Vector>})} or + * {<OpenLayers.Feature.Vector>} Array of features or a single feature. + */ + parseFeatures: function(request) { + var doc = request.responseXML; + if (!doc || !doc.documentElement) { + doc = request.responseText; + } + if (!doc || doc.length <= 0) { + return null; + } + return this.format.read(doc); + }, + + /** + * APIMethod: commit + * Iterate over each feature and take action based on the feature state. + * Possible actions are create, update and delete. + * + * Parameters: + * features - {Array({<OpenLayers.Feature.Vector>})} + * options - {Object} Optional object for setting up intermediate commit + * callbacks. + * + * Valid options: + * create - {Object} Optional object to be passed to the <create> method. + * update - {Object} Optional object to be passed to the <update> method. + * delete - {Object} Optional object to be passed to the <delete> method. + * callback - {Function} Optional function to be called when the commit + * is complete. + * scope - {Object} Optional object to be set as the scope of the callback. + * + * Returns: + * {Array(<OpenLayers.Protocol.Response>)} An array of response objects, + * one per request made to the server, each object's "priv" property + * references the corresponding HTTP request. + */ + commit: function(features, options) { + options = OpenLayers.Util.applyDefaults(options, this.options); + var resp = [], nResponses = 0; + + // Divide up features before issuing any requests. This properly + // counts requests in the event that any responses come in before + // all requests have been issued. + var types = {}; + types[OpenLayers.State.INSERT] = []; + types[OpenLayers.State.UPDATE] = []; + types[OpenLayers.State.DELETE] = []; + var feature, list, requestFeatures = []; + for(var i=0, len=features.length; i<len; ++i) { + feature = features[i]; + list = types[feature.state]; + if(list) { + list.push(feature); + requestFeatures.push(feature); + } + } + // tally up number of requests + var nRequests = (types[OpenLayers.State.INSERT].length > 0 ? 1 : 0) + + types[OpenLayers.State.UPDATE].length + + types[OpenLayers.State.DELETE].length; + + // This response will be sent to the final callback after all the others + // have been fired. + var success = true; + var finalResponse = new OpenLayers.Protocol.Response({ + reqFeatures: requestFeatures + }); + + function insertCallback(response) { + var len = response.features ? response.features.length : 0; + var fids = new Array(len); + for(var i=0; i<len; ++i) { + fids[i] = response.features[i].fid; + } + finalResponse.insertIds = fids; + callback.apply(this, [response]); + } + + function callback(response) { + this.callUserCallback(response, options); + success = success && response.success(); + nResponses++; + if (nResponses >= nRequests) { + if (options.callback) { + finalResponse.code = success ? + OpenLayers.Protocol.Response.SUCCESS : + OpenLayers.Protocol.Response.FAILURE; + options.callback.apply(options.scope, [finalResponse]); + } + } + } + + // start issuing requests + var queue = types[OpenLayers.State.INSERT]; + if(queue.length > 0) { + resp.push(this.create( + queue, OpenLayers.Util.applyDefaults( + {callback: insertCallback, scope: this}, options.create + ) + )); + } + queue = types[OpenLayers.State.UPDATE]; + for(var i=queue.length-1; i>=0; --i) { + resp.push(this.update( + queue[i], OpenLayers.Util.applyDefaults( + {callback: callback, scope: this}, options.update + )) + ); + } + queue = types[OpenLayers.State.DELETE]; + for(var i=queue.length-1; i>=0; --i) { + resp.push(this["delete"]( + queue[i], OpenLayers.Util.applyDefaults( + {callback: callback, scope: this}, options["delete"] + )) + ); + } + return resp; + }, + + /** + * APIMethod: abort + * Abort an ongoing request, the response object passed to + * this method must come from this HTTP protocol (as a result + * of a create, read, update, delete or commit operation). + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} + */ + abort: function(response) { + if (response) { + response.priv.abort(); + } + }, + + /** + * Method: callUserCallback + * This method is used from within the commit method each time an + * an HTTP response is received from the server, it is responsible + * for calling the user-supplied callbacks. + * + * Parameters: + * resp - {<OpenLayers.Protocol.Response>} + * options - {Object} The map of options passed to the commit call. + */ + callUserCallback: function(resp, options) { + var opt = options[resp.requestType]; + if(opt && opt.callback) { + opt.callback.call(opt.scope, resp); + } + }, + + CLASS_NAME: "OpenLayers.Protocol.HTTP" +}); diff --git a/misc/openlayers/lib/OpenLayers/Protocol/SOS.js b/misc/openlayers/lib/OpenLayers/Protocol/SOS.js new file mode 100644 index 0000000..578f369 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/SOS.js @@ -0,0 +1,33 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol.js + */ + +/** + * Function: OpenLayers.Protocol.SOS + * Used to create a versioned SOS protocol. Default version is 1.0.0. + * + * Returns: + * {<OpenLayers.Protocol>} An SOS protocol for the given version. + */ +OpenLayers.Protocol.SOS = function(options) { + options = OpenLayers.Util.applyDefaults( + options, OpenLayers.Protocol.SOS.DEFAULTS + ); + var cls = OpenLayers.Protocol.SOS["v"+options.version.replace(/\./g, "_")]; + if(!cls) { + throw "Unsupported SOS version: " + options.version; + } + return new cls(options); +}; + +/** + * Constant: OpenLayers.Protocol.SOS.DEFAULTS + */ +OpenLayers.Protocol.SOS.DEFAULTS = { + "version": "1.0.0" +}; diff --git a/misc/openlayers/lib/OpenLayers/Protocol/SOS/v1_0_0.js b/misc/openlayers/lib/OpenLayers/Protocol/SOS/v1_0_0.js new file mode 100644 index 0000000..9cf87f5 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/SOS/v1_0_0.js @@ -0,0 +1,133 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol/SOS.js + * @requires OpenLayers/Format/SOSGetFeatureOfInterest.js + */ + +/** + * Class: OpenLayers.Protocol.SOS.v1_0_0 + * An SOS v1.0.0 Protocol for vector layers. Create a new instance with the + * <OpenLayers.Protocol.SOS.v1_0_0> constructor. + * + * Inherits from: + * - <OpenLayers.Protocol> + */ + OpenLayers.Protocol.SOS.v1_0_0 = OpenLayers.Class(OpenLayers.Protocol, { + + /** + * APIProperty: fois + * {Array(String)} Array of features of interest (foi) + */ + fois: null, + + /** + * Property: formatOptions + * {Object} Optional options for the format. If a format is not provided, + * this property can be used to extend the default format options. + */ + formatOptions: null, + + /** + * Constructor: OpenLayers.Protocol.SOS + * A class for giving layers an SOS protocol. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + * + * Valid options properties: + * url - {String} URL to send requests to (required). + * fois - {Array} The features of interest (required). + */ + initialize: function(options) { + OpenLayers.Protocol.prototype.initialize.apply(this, [options]); + if(!options.format) { + this.format = new OpenLayers.Format.SOSGetFeatureOfInterest( + this.formatOptions); + } + }, + + /** + * APIMethod: destroy + * Clean up the protocol. + */ + destroy: function() { + if(this.options && !this.options.format) { + this.format.destroy(); + } + this.format = null; + OpenLayers.Protocol.prototype.destroy.apply(this); + }, + + /** + * APIMethod: read + * Construct a request for reading new sensor positions. This is done by + * issuing one GetFeatureOfInterest request. + */ + read: function(options) { + options = OpenLayers.Util.extend({}, options); + OpenLayers.Util.applyDefaults(options, this.options || {}); + var response = new OpenLayers.Protocol.Response({requestType: "read"}); + var format = this.format; + var data = OpenLayers.Format.XML.prototype.write.apply(format, + [format.writeNode("sos:GetFeatureOfInterest", {fois: this.fois})] + ); + response.priv = OpenLayers.Request.POST({ + url: options.url, + callback: this.createCallback(this.handleRead, response, options), + data: data + }); + return response; + }, + + /** + * Method: handleRead + * Deal with response from the read request. + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} The response object to pass + * to the user callback. + * options - {Object} The user options passed to the read call. + */ + handleRead: function(response, options) { + if(options.callback) { + var request = response.priv; + if(request.status >= 200 && request.status < 300) { + // success + response.features = this.parseFeatures(request); + response.code = OpenLayers.Protocol.Response.SUCCESS; + } else { + // failure + response.code = OpenLayers.Protocol.Response.FAILURE; + } + options.callback.call(options.scope, response); + } + }, + + /** + * Method: parseFeatures + * Read HTTP response body and return features + * + * Parameters: + * request - {XMLHttpRequest} The request object + * + * Returns: + * {Array({<OpenLayers.Feature.Vector>})} Array of features + */ + parseFeatures: function(request) { + var doc = request.responseXML; + if(!doc || !doc.documentElement) { + doc = request.responseText; + } + if(!doc || doc.length <= 0) { + return null; + } + return this.format.read(doc); + }, + + CLASS_NAME: "OpenLayers.Protocol.SOS.v1_0_0" +}); diff --git a/misc/openlayers/lib/OpenLayers/Protocol/Script.js b/misc/openlayers/lib/OpenLayers/Protocol/Script.js new file mode 100644 index 0000000..93ab32a --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/Script.js @@ -0,0 +1,377 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol.js + * @requires OpenLayers/Feature/Vector.js + * @requires OpenLayers/Format/GeoJSON.js + */ + +/** + * if application uses the query string, for example, for BBOX parameters, + * OpenLayers/Format/QueryStringFilter.js should be included in the build config file + */ + +/** + * Class: OpenLayers.Protocol.Script + * A basic Script protocol for vector layers. Create a new instance with the + * <OpenLayers.Protocol.Script> constructor. A script protocol is used to + * get around the same origin policy. It works with services that return + * JSONP - that is, JSON wrapped in a client-specified callback. The + * protocol handles fetching and parsing of feature data and sends parsed + * features to the <callback> configured with the protocol. The protocol + * expects features serialized as GeoJSON by default, but can be configured + * to work with other formats by setting the <format> property. + * + * Inherits from: + * - <OpenLayers.Protocol> + */ +OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, { + + /** + * APIProperty: url + * {String} Service URL. The service is expected to return serialized + * features wrapped in a named callback (where the callback name is + * generated by this protocol). + * Read-only, set through the options passed to the constructor. + */ + url: null, + + /** + * APIProperty: params + * {Object} Query string parameters to be appended to the URL. + * Read-only, set through the options passed to the constructor. + * Example: {maxFeatures: 50} + */ + params: null, + + /** + * APIProperty: callback + * {Object} Function to be called when the <read> operation completes. + */ + callback: null, + + /** + * APIProperty: callbackTemplate + * {String} Template for creating a unique callback function name + * for the registry. Should include ${id}. The ${id} variable will be + * replaced with a string identifier prefixed with a "c" (e.g. c1, c2). + * Default is "OpenLayers.Protocol.Script.registry.${id}". + */ + callbackTemplate: "OpenLayers.Protocol.Script.registry.${id}", + + /** + * APIProperty: callbackKey + * {String} The name of the query string parameter that the service + * recognizes as the callback identifier. Default is "callback". + * This key is used to generate the URL for the script. For example + * setting <callbackKey> to "myCallback" would result in a URL like + * http://example.com/?myCallback=... + */ + callbackKey: "callback", + + /** + * APIProperty: callbackPrefix + * {String} Where a service requires that the callback query string + * parameter value is prefixed by some string, this value may be set. + * For example, setting <callbackPrefix> to "foo:" would result in a + * URL like http://example.com/?callback=foo:... Default is "". + */ + callbackPrefix: "", + + /** + * APIProperty: scope + * {Object} Optional ``this`` object for the callback. Read-only, set + * through the options passed to the constructor. + */ + scope: null, + + /** + * APIProperty: format + * {<OpenLayers.Format>} Format for parsing features. Default is an + * <OpenLayers.Format.GeoJSON> format. If an alternative is provided, + * the format's read method must take an object and return an array + * of features. + */ + format: null, + + /** + * Property: pendingRequests + * {Object} References all pending requests. Property names are script + * identifiers and property values are script elements. + */ + pendingRequests: null, + + /** + * APIProperty: srsInBBOX + * {Boolean} Include the SRS identifier in BBOX query string parameter. + * Setting this property has no effect if a custom filterToParams method + * is provided. Default is false. If true and the layer has a + * projection object set, any BBOX filter will be serialized with a + * fifth item identifying the projection. + * E.g. bbox=-1000,-1000,1000,1000,EPSG:900913 + */ + srsInBBOX: false, + + /** + * Constructor: OpenLayers.Protocol.Script + * A class for giving layers generic Script protocol. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + * + * Valid options include: + * url - {String} + * params - {Object} + * callback - {Function} + * scope - {Object} + */ + initialize: function(options) { + options = options || {}; + this.params = {}; + this.pendingRequests = {}; + OpenLayers.Protocol.prototype.initialize.apply(this, arguments); + if (!this.format) { + this.format = new OpenLayers.Format.GeoJSON(); + } + + if (!this.filterToParams && OpenLayers.Format.QueryStringFilter) { + var format = new OpenLayers.Format.QueryStringFilter({ + srsInBBOX: this.srsInBBOX + }); + this.filterToParams = function(filter, params) { + return format.write(filter, params); + }; + } + }, + + /** + * APIMethod: read + * Construct a request for reading new features. + * + * Parameters: + * options - {Object} Optional object for configuring the request. + * This object is modified and should not be reused. + * + * Valid options: + * url - {String} Url for the request. + * params - {Object} Parameters to get serialized as a query string. + * filter - {<OpenLayers.Filter>} Filter to get serialized as a + * query string. + * + * Returns: + * {<OpenLayers.Protocol.Response>} A response object, whose "priv" property + * references the injected script. This object is also passed to the + * callback function when the request completes, its "features" property + * is then populated with the features received from the server. + */ + read: function(options) { + OpenLayers.Protocol.prototype.read.apply(this, arguments); + options = OpenLayers.Util.applyDefaults(options, this.options); + options.params = OpenLayers.Util.applyDefaults( + options.params, this.options.params + ); + if (options.filter && this.filterToParams) { + options.params = this.filterToParams( + options.filter, options.params + ); + } + var response = new OpenLayers.Protocol.Response({requestType: "read"}); + var request = this.createRequest( + options.url, + options.params, + OpenLayers.Function.bind(function(data) { + response.data = data; + this.handleRead(response, options); + }, this) + ); + response.priv = request; + return response; + }, + + /** + * APIMethod: filterToParams + * Optional method to translate an <OpenLayers.Filter> object into an object + * that can be serialized as request query string provided. If a custom + * method is not provided, any filter will not be serialized. + * + * Parameters: + * filter - {<OpenLayers.Filter>} filter to convert. + * params - {Object} The parameters object. + * + * Returns: + * {Object} The resulting parameters object. + */ + + /** + * Method: createRequest + * Issues a request for features by creating injecting a script in the + * document head. + * + * Parameters: + * url - {String} Service URL. + * params - {Object} Query string parameters. + * callback - {Function} Callback to be called with resulting data. + * + * Returns: + * {HTMLScriptElement} The script pending execution. + */ + createRequest: function(url, params, callback) { + var id = OpenLayers.Protocol.Script.register(callback); + var name = OpenLayers.String.format(this.callbackTemplate, {id: id}); + params = OpenLayers.Util.extend({}, params); + params[this.callbackKey] = this.callbackPrefix + name; + url = OpenLayers.Util.urlAppend( + url, OpenLayers.Util.getParameterString(params) + ); + var script = document.createElement("script"); + script.type = "text/javascript"; + script.src = url; + script.id = "OpenLayers_Protocol_Script_" + id; + this.pendingRequests[script.id] = script; + var head = document.getElementsByTagName("head")[0]; + head.appendChild(script); + return script; + }, + + /** + * Method: destroyRequest + * Remove a script node associated with a response from the document. Also + * unregisters the callback and removes the script from the + * <pendingRequests> object. + * + * Parameters: + * script - {HTMLScriptElement} + */ + destroyRequest: function(script) { + OpenLayers.Protocol.Script.unregister(script.id.split("_").pop()); + delete this.pendingRequests[script.id]; + if (script.parentNode) { + script.parentNode.removeChild(script); + } + }, + + /** + * Method: handleRead + * Individual callbacks are created for read, create and update, should + * a subclass need to override each one separately. + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} The response object to pass to + * the user callback. + * options - {Object} The user options passed to the read call. + */ + handleRead: function(response, options) { + this.handleResponse(response, options); + }, + + /** + * Method: handleResponse + * Called by CRUD specific handlers. + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} The response object to pass to + * any user callback. + * options - {Object} The user options passed to the create, read, update, + * or delete call. + */ + handleResponse: function(response, options) { + if (options.callback) { + if (response.data) { + response.features = this.parseFeatures(response.data); + response.code = OpenLayers.Protocol.Response.SUCCESS; + } else { + response.code = OpenLayers.Protocol.Response.FAILURE; + } + this.destroyRequest(response.priv); + options.callback.call(options.scope, response); + } + }, + + /** + * Method: parseFeatures + * Read Script response body and return features. + * + * Parameters: + * data - {Object} The data sent to the callback function by the server. + * + * Returns: + * {Array({<OpenLayers.Feature.Vector>})} or + * {<OpenLayers.Feature.Vector>} Array of features or a single feature. + */ + parseFeatures: function(data) { + return this.format.read(data); + }, + + /** + * APIMethod: abort + * Abort an ongoing request. If no response is provided, all pending + * requests will be aborted. + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} The response object returned + * from a <read> request. + */ + abort: function(response) { + if (response) { + this.destroyRequest(response.priv); + } else { + for (var key in this.pendingRequests) { + this.destroyRequest(this.pendingRequests[key]); + } + } + }, + + /** + * APIMethod: destroy + * Clean up the protocol. + */ + destroy: function() { + this.abort(); + delete this.params; + delete this.format; + OpenLayers.Protocol.prototype.destroy.apply(this); + }, + + CLASS_NAME: "OpenLayers.Protocol.Script" +}); + +(function() { + var o = OpenLayers.Protocol.Script; + var counter = 0; + o.registry = {}; + + /** + * Function: OpenLayers.Protocol.Script.register + * Register a callback for a newly created script. + * + * Parameters: + * callback - {Function} The callback to be executed when the newly added + * script loads. This callback will be called with a single argument + * that is the JSON returned by the service. + * + * Returns: + * {Number} An identifier for retrieving the registered callback. + */ + o.register = function(callback) { + var id = "c"+(++counter); + o.registry[id] = function() { + callback.apply(this, arguments); + }; + return id; + }; + + /** + * Function: OpenLayers.Protocol.Script.unregister + * Unregister a callback previously registered with the register function. + * + * Parameters: + * id - {Number} The identifer returned by the register function. + */ + o.unregister = function(id) { + delete o.registry[id]; + }; +})(); diff --git a/misc/openlayers/lib/OpenLayers/Protocol/WFS.js b/misc/openlayers/lib/OpenLayers/Protocol/WFS.js new file mode 100644 index 0000000..66faf43 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/WFS.js @@ -0,0 +1,86 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol.js + */ + +/** + * Class: OpenLayers.Protocol.WFS + * Used to create a versioned WFS protocol. Default version is 1.0.0. + * + * Returns: + * {<OpenLayers.Protocol>} A WFS protocol of the given version. + * + * Example: + * (code) + * var protocol = new OpenLayers.Protocol.WFS({ + * version: "1.1.0", + * url: "http://demo.opengeo.org/geoserver/wfs", + * featureType: "tasmania_roads", + * featureNS: "http://www.openplans.org/topp", + * geometryName: "the_geom" + * }); + * (end) + * + * See the protocols for specific WFS versions for more detail. + */ +OpenLayers.Protocol.WFS = function(options) { + options = OpenLayers.Util.applyDefaults( + options, OpenLayers.Protocol.WFS.DEFAULTS + ); + var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")]; + if(!cls) { + throw "Unsupported WFS version: " + options.version; + } + return new cls(options); +}; + +/** + * Function: fromWMSLayer + * Convenience function to create a WFS protocol from a WMS layer. This makes + * the assumption that a WFS requests can be issued at the same URL as + * WMS requests and that a WFS featureType exists with the same name as the + * WMS layer. + * + * This function is designed to auto-configure <url>, <featureType>, + * <featurePrefix> and <srsName> for WFS <version> 1.1.0. Note that + * srsName matching with the WMS layer will not work with WFS 1.0.0. + * + * Parameters: + * layer - {<OpenLayers.Layer.WMS>} WMS layer that has a matching WFS + * FeatureType at the same server url with the same typename. + * options - {Object} Default properties to be set on the protocol. + * + * Returns: + * {<OpenLayers.Protocol.WFS>} + */ +OpenLayers.Protocol.WFS.fromWMSLayer = function(layer, options) { + var typeName, featurePrefix; + var param = layer.params["LAYERS"]; + var parts = (OpenLayers.Util.isArray(param) ? param[0] : param).split(":"); + if(parts.length > 1) { + featurePrefix = parts[0]; + } + typeName = parts.pop(); + var protocolOptions = { + url: layer.url, + featureType: typeName, + featurePrefix: featurePrefix, + srsName: layer.projection && layer.projection.getCode() || + layer.map && layer.map.getProjectionObject().getCode(), + version: "1.1.0" + }; + return new OpenLayers.Protocol.WFS(OpenLayers.Util.applyDefaults( + options, protocolOptions + )); +}; + +/** + * Constant: OpenLayers.Protocol.WFS.DEFAULTS + */ +OpenLayers.Protocol.WFS.DEFAULTS = { + "version": "1.0.0" +}; diff --git a/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1.js b/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1.js new file mode 100644 index 0000000..8a21d7e --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1.js @@ -0,0 +1,453 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol/WFS.js + */ + +/** + * Class: OpenLayers.Protocol.WFS.v1 + * Abstract class for for v1.0.0 and v1.1.0 protocol. + * + * Inherits from: + * - <OpenLayers.Protocol> + */ +OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, { + + /** + * Property: version + * {String} WFS version number. + */ + version: null, + + /** + * Property: srsName + * {String} Name of spatial reference system. Default is "EPSG:4326". + */ + srsName: "EPSG:4326", + + /** + * Property: featureType + * {String} Local feature typeName. + */ + featureType: null, + + /** + * Property: featureNS + * {String} Feature namespace. + */ + featureNS: null, + + /** + * Property: geometryName + * {String} Name of the geometry attribute for features. Default is + * "the_geom" for WFS <version> 1.0, and null for higher versions. + */ + geometryName: "the_geom", + + /** + * Property: maxFeatures + * {Integer} Optional maximum number of features to retrieve. + */ + + /** + * Property: schema + * {String} Optional schema location that will be included in the + * schemaLocation attribute value. Note that the feature type schema + * is required for a strict XML validator (on transactions with an + * insert for example), but is *not* required by the WFS specification + * (since the server is supposed to know about feature type schemas). + */ + schema: null, + + /** + * Property: featurePrefix + * {String} Namespace alias for feature type. Default is "feature". + */ + featurePrefix: "feature", + + /** + * Property: formatOptions + * {Object} Optional options for the format. If a format is not provided, + * this property can be used to extend the default format options. + */ + formatOptions: null, + + /** + * Property: readFormat + * {<OpenLayers.Format>} For WFS requests it is possible to get a + * different output format than GML. In that case, we cannot parse + * the response with the default format (WFST) and we need a different + * format for reading. + */ + readFormat: null, + + /** + * Property: readOptions + * {Object} Optional object to pass to format's read. + */ + readOptions: null, + + /** + * Constructor: OpenLayers.Protocol.WFS + * A class for giving layers WFS protocol. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + * + * Valid options properties: + * url - {String} URL to send requests to (required). + * featureType - {String} Local (without prefix) feature typeName (required). + * featureNS - {String} Feature namespace (required, but can be autodetected + * during the first query if GML is used as readFormat and + * featurePrefix is provided and matches the prefix used by the server + * for this featureType). + * featurePrefix - {String} Feature namespace alias (optional - only used + * for writing if featureNS is provided). Default is 'feature'. + * geometryName - {String} Name of geometry attribute. The default is + * 'the_geom' for WFS <version> 1.0, and null for higher versions. If + * null, it will be set to the name of the first geometry found in the + * first read operation. + * multi - {Boolean} If set to true, geometries will be casted to Multi + * geometries before they are written in a transaction. No casting will + * be done when reading features. + */ + initialize: function(options) { + OpenLayers.Protocol.prototype.initialize.apply(this, [options]); + if(!options.format) { + this.format = OpenLayers.Format.WFST(OpenLayers.Util.extend({ + version: this.version, + featureType: this.featureType, + featureNS: this.featureNS, + featurePrefix: this.featurePrefix, + geometryName: this.geometryName, + srsName: this.srsName, + schema: this.schema + }, this.formatOptions)); + } + if (!options.geometryName && parseFloat(this.format.version) > 1.0) { + this.setGeometryName(null); + } + }, + + /** + * APIMethod: destroy + * Clean up the protocol. + */ + destroy: function() { + if(this.options && !this.options.format) { + this.format.destroy(); + } + this.format = null; + OpenLayers.Protocol.prototype.destroy.apply(this); + }, + + /** + * APIMethod: read + * Construct a request for reading new features. Since WFS splits the + * basic CRUD operations into GetFeature requests (for read) and + * Transactions (for all others), this method does not make use of the + * format's read method (that is only about reading transaction + * responses). + * + * Parameters: + * options - {Object} Options for the read operation, in addition to the + * options set on the instance (options set here will take precedence). + * + * To use a configured protocol to get e.g. a WFS hit count, applications + * could do the following: + * + * (code) + * protocol.read({ + * readOptions: {output: "object"}, + * resultType: "hits", + * maxFeatures: null, + * callback: function(resp) { + * // process resp.numberOfFeatures here + * } + * }); + * (end) + * + * To use a configured protocol to use WFS paging (if supported by the + * server), applications could do the following: + * + * (code) + * protocol.read({ + * startIndex: 0, + * count: 50 + * }); + * (end) + * + * To limit the attributes returned by the GetFeature request, applications + * can use the propertyNames option to specify the properties to include in + * the response: + * + * (code) + * protocol.read({ + * propertyNames: ["DURATION", "INTENSITY"] + * }); + * (end) + */ + read: function(options) { + OpenLayers.Protocol.prototype.read.apply(this, arguments); + options = OpenLayers.Util.extend({}, options); + OpenLayers.Util.applyDefaults(options, this.options || {}); + var response = new OpenLayers.Protocol.Response({requestType: "read"}); + + var data = OpenLayers.Format.XML.prototype.write.apply( + this.format, [this.format.writeNode("wfs:GetFeature", options)] + ); + + response.priv = OpenLayers.Request.POST({ + url: options.url, + callback: this.createCallback(this.handleRead, response, options), + params: options.params, + headers: options.headers, + data: data + }); + + return response; + }, + + /** + * APIMethod: setFeatureType + * Change the feature type on the fly. + * + * Parameters: + * featureType - {String} Local (without prefix) feature typeName. + */ + setFeatureType: function(featureType) { + this.featureType = featureType; + this.format.featureType = featureType; + }, + + /** + * APIMethod: setGeometryName + * Sets the geometryName option after instantiation. + * + * Parameters: + * geometryName - {String} Name of geometry attribute. + */ + setGeometryName: function(geometryName) { + this.geometryName = geometryName; + this.format.geometryName = geometryName; + }, + + /** + * Method: handleRead + * Deal with response from the read request. + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} The response object to pass + * to the user callback. + * options - {Object} The user options passed to the read call. + */ + handleRead: function(response, options) { + options = OpenLayers.Util.extend({}, options); + OpenLayers.Util.applyDefaults(options, this.options); + + if(options.callback) { + var request = response.priv; + if(request.status >= 200 && request.status < 300) { + // success + var result = this.parseResponse(request, options.readOptions); + if (result && result.success !== false) { + if (options.readOptions && options.readOptions.output == "object") { + OpenLayers.Util.extend(response, result); + } else { + response.features = result; + } + response.code = OpenLayers.Protocol.Response.SUCCESS; + } else { + // failure (service exception) + response.code = OpenLayers.Protocol.Response.FAILURE; + response.error = result; + } + } else { + // failure + response.code = OpenLayers.Protocol.Response.FAILURE; + } + options.callback.call(options.scope, response); + } + }, + + /** + * Method: parseResponse + * Read HTTP response body and return features + * + * Parameters: + * request - {XMLHttpRequest} The request object + * options - {Object} Optional object to pass to format's read + * + * Returns: + * {Object} or {Array({<OpenLayers.Feature.Vector>})} or + * {<OpenLayers.Feature.Vector>} + * An object with a features property, an array of features or a single + * feature. + */ + parseResponse: function(request, options) { + var doc = request.responseXML; + if(!doc || !doc.documentElement) { + doc = request.responseText; + } + if(!doc || doc.length <= 0) { + return null; + } + var result = (this.readFormat !== null) ? this.readFormat.read(doc) : + this.format.read(doc, options); + if (!this.featureNS) { + var format = this.readFormat || this.format; + this.featureNS = format.featureNS; + // no need to auto-configure again on subsequent reads + format.autoConfig = false; + if (!this.geometryName) { + this.setGeometryName(format.geometryName); + } + } + return result; + }, + + /** + * Method: commit + * Given a list of feature, assemble a batch request for update, create, + * and delete transactions. A commit call on the prototype amounts + * to writing a WFS transaction - so the write method on the format + * is used. + * + * Parameters: + * features - {Array(<OpenLayers.Feature.Vector>)} + * options - {Object} + * + * Valid options properties: + * nativeElements - {Array({Object})} Array of objects with information for writing + * out <Native> elements, these objects have vendorId, safeToIgnore and + * value properties. The <Native> element is intended to allow access to + * vendor specific capabilities of any particular web feature server or + * datastore. + * + * Returns: + * {<OpenLayers.Protocol.Response>} A response object with a features + * property containing any insertIds and a priv property referencing + * the XMLHttpRequest object. + */ + commit: function(features, options) { + + options = OpenLayers.Util.extend({}, options); + OpenLayers.Util.applyDefaults(options, this.options); + + var response = new OpenLayers.Protocol.Response({ + requestType: "commit", + reqFeatures: features + }); + response.priv = OpenLayers.Request.POST({ + url: options.url, + headers: options.headers, + data: this.format.write(features, options), + callback: this.createCallback(this.handleCommit, response, options) + }); + + return response; + }, + + /** + * Method: handleCommit + * Called when the commit request returns. + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} The response object to pass + * to the user callback. + * options - {Object} The user options passed to the commit call. + */ + handleCommit: function(response, options) { + if(options.callback) { + var request = response.priv; + + // ensure that we have an xml doc + var data = request.responseXML; + if(!data || !data.documentElement) { + data = request.responseText; + } + + var obj = this.format.read(data) || {}; + + response.insertIds = obj.insertIds || []; + if (obj.success) { + response.code = OpenLayers.Protocol.Response.SUCCESS; + } else { + response.code = OpenLayers.Protocol.Response.FAILURE; + response.error = obj; + } + options.callback.call(options.scope, response); + } + }, + + /** + * Method: filterDelete + * Send a request that deletes all features by their filter. + * + * Parameters: + * filter - {<OpenLayers.Filter>} filter + */ + filterDelete: function(filter, options) { + options = OpenLayers.Util.extend({}, options); + OpenLayers.Util.applyDefaults(options, this.options); + + var response = new OpenLayers.Protocol.Response({ + requestType: "commit" + }); + + var root = this.format.createElementNSPlus("wfs:Transaction", { + attributes: { + service: "WFS", + version: this.version + } + }); + + var deleteNode = this.format.createElementNSPlus("wfs:Delete", { + attributes: { + typeName: (options.featureNS ? this.featurePrefix + ":" : "") + + options.featureType + } + }); + + if(options.featureNS) { + deleteNode.setAttribute("xmlns:" + this.featurePrefix, options.featureNS); + } + var filterNode = this.format.writeNode("ogc:Filter", filter); + + deleteNode.appendChild(filterNode); + + root.appendChild(deleteNode); + + var data = OpenLayers.Format.XML.prototype.write.apply( + this.format, [root] + ); + + return OpenLayers.Request.POST({ + url: this.url, + callback : options.callback || function(){}, + data: data + }); + + }, + + /** + * Method: abort + * Abort an ongoing request, the response object passed to + * this method must come from this protocol (as a result + * of a read, or commit operation). + * + * Parameters: + * response - {<OpenLayers.Protocol.Response>} + */ + abort: function(response) { + if (response) { + response.priv.abort(); + } + }, + + CLASS_NAME: "OpenLayers.Protocol.WFS.v1" +}); diff --git a/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1_0_0.js b/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1_0_0.js new file mode 100644 index 0000000..b1e2ca1 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1_0_0.js @@ -0,0 +1,44 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol/WFS/v1.js + * @requires OpenLayers/Format/WFST/v1_0_0.js + */ + +/** + * Class: OpenLayers.Protocol.WFS.v1_0_0 + * A WFS v1.0.0 protocol for vector layers. Create a new instance with the + * <OpenLayers.Protocol.WFS.v1_0_0> constructor. + * + * Inherits from: + * - <OpenLayers.Protocol.WFS.v1> + */ +OpenLayers.Protocol.WFS.v1_0_0 = OpenLayers.Class(OpenLayers.Protocol.WFS.v1, { + + /** + * Property: version + * {String} WFS version number. + */ + version: "1.0.0", + + /** + * Constructor: OpenLayers.Protocol.WFS.v1_0_0 + * A class for giving layers WFS v1.0.0 protocol. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + * + * Valid options properties: + * featureType - {String} Local (without prefix) feature typeName (required). + * featureNS - {String} Feature namespace (optional). + * featurePrefix - {String} Feature namespace alias (optional - only used + * if featureNS is provided). Default is 'feature'. + * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. + */ + + CLASS_NAME: "OpenLayers.Protocol.WFS.v1_0_0" +}); diff --git a/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1_1_0.js b/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1_1_0.js new file mode 100644 index 0000000..97991a6 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Protocol/WFS/v1_1_0.js @@ -0,0 +1,68 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol/WFS/v1.js + * @requires OpenLayers/Format/WFST/v1_1_0.js + */ + +/** + * Class: OpenLayers.Protocol.WFS.v1_1_0 + * A WFS v1.1.0 protocol for vector layers. Create a new instance with the + * <OpenLayers.Protocol.WFS.v1_1_0> constructor. + * + * Differences from the v1.0.0 protocol: + * - uses Filter Encoding 1.1.0 instead of 1.0.0 + * - uses GML 3 instead of 2 if no format is provided + * + * Inherits from: + * - <OpenLayers.Protocol.WFS.v1> + */ +OpenLayers.Protocol.WFS.v1_1_0 = OpenLayers.Class(OpenLayers.Protocol.WFS.v1, { + + /** + * Property: version + * {String} WFS version number. + */ + version: "1.1.0", + + /** + * Constructor: OpenLayers.Protocol.WFS.v1_1_0 + * A class for giving layers WFS v1.1.0 protocol. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + * + * Valid options properties: + * featureType - {String} Local (without prefix) feature typeName (required). + * featureNS - {String} Feature namespace (optional). + * featurePrefix - {String} Feature namespace alias (optional - only used + * if featureNS is provided). Default is 'feature'. + * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. + * outputFormat - {String} Optional output format to use for WFS GetFeature + * requests. This can be any format advertized by the WFS's + * GetCapabilities response. If set, an appropriate readFormat also + * has to be provided, unless outputFormat is GML3, GML2 or JSON. + * readFormat - {<OpenLayers.Format>} An appropriate format parser if + * outputFormat is none of GML3, GML2 or JSON. + */ + initialize: function(options) { + OpenLayers.Protocol.WFS.v1.prototype.initialize.apply(this, arguments); + if (this.outputFormat && !this.readFormat) { + if (this.outputFormat.toLowerCase() == "gml2") { + this.readFormat = new OpenLayers.Format.GML.v2({ + featureType: this.featureType, + featureNS: this.featureNS, + geometryName: this.geometryName + }); + } else if (this.outputFormat.toLowerCase() == "json") { + this.readFormat = new OpenLayers.Format.GeoJSON(); + } + } + }, + + CLASS_NAME: "OpenLayers.Protocol.WFS.v1_1_0" +}); |