From a6be4a4b6c549a9dfa4e7e9c6712d240252c66ae Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 9 Jan 2012 09:29:15 +0100 Subject: [PATCH 1/6] start with the patch from OL Trac ticket 2133 --- lib/OpenLayers.js | 2 + lib/OpenLayers/Protocol.js | 8 ++ lib/OpenLayers/Protocol/CSW.js | 32 ++++++ lib/OpenLayers/Protocol/CSW/v2_0_2.js | 145 ++++++++++++++++++++++++++ tests/Protocol/CSW.html | 85 +++++++++++++++ tests/list-tests.html | 1 + 6 files changed, 273 insertions(+) create mode 100644 lib/OpenLayers/Protocol/CSW.js create mode 100644 lib/OpenLayers/Protocol/CSW/v2_0_2.js create mode 100644 tests/Protocol/CSW.html diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index aaf8a51104..571bee67f7 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -242,6 +242,8 @@ "OpenLayers/Protocol/WFS/v1.js", "OpenLayers/Protocol/WFS/v1_0_0.js", "OpenLayers/Protocol/WFS/v1_1_0.js", + "OpenLayers/Protocol/CSW.js", + "OpenLayers/Protocol/CSW/v2_0_2.js", "OpenLayers/Protocol/Script.js", "OpenLayers/Protocol/SOS.js", "OpenLayers/Protocol/SOS/v1_0_0.js", diff --git a/lib/OpenLayers/Protocol.js b/lib/OpenLayers/Protocol.js index 601e59548c..0f359a874b 100644 --- a/lib/OpenLayers/Protocol.js +++ b/lib/OpenLayers/Protocol.js @@ -235,6 +235,14 @@ OpenLayers.Protocol.Response = OpenLayers.Class({ */ features: null, + /** + * Property: data + * The data returned in the response by the server. + * FIXME : as far as the response doesn't necessary transport features + * it may be helpful to store some non-specific data. + */ + data: null, + /** * Property: reqFeatures * {Array({})} or {} diff --git a/lib/OpenLayers/Protocol/CSW.js b/lib/OpenLayers/Protocol/CSW.js new file mode 100644 index 0000000000..2361fd6bbf --- /dev/null +++ b/lib/OpenLayers/Protocol/CSW.js @@ -0,0 +1,32 @@ +/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD + * license. See http://svn.openlayers.org/trunk/openlayers/license.txt 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. + * + * Inherits from: + * - + */ +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" +}; \ No newline at end of file diff --git a/lib/OpenLayers/Protocol/CSW/v2_0_2.js b/lib/OpenLayers/Protocol/CSW/v2_0_2.js new file mode 100644 index 0000000000..6c6c2643ca --- /dev/null +++ b/lib/OpenLayers/Protocol/CSW/v2_0_2.js @@ -0,0 +1,145 @@ +/** + * @requires OpenLayers/Protocol/CSW.js + */ + +/** + * Class: OpenLayers.Protocol.CSW.v2_0_2 + * Abstract class for for v2_0_2 protocol. + * + * Inherits from: + * - + */ +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 + * A class for CSW 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) { + /* not tested */ + 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: createCallback + * Returns a function that applies the given public method with resp and + * options arguments. + * + * Parameters: + * method - {Function} The method to be applied by the callback. + * response - {} The protocol response object. + * options - {Object} Options sent to the protocol method (read, create, + * update, or delete). + */ + createCallback: function(method, response, options) { + return OpenLayers.Function.bind(function() { + method.apply(this, [response, options]); + }, this); + }, + + /** + * Method: 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). + */ + 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); + + 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 - {} The response object to pass + * to the user callback. + * This response is given a code property, and optionally a records one. + * 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" + +}); \ No newline at end of file diff --git a/tests/Protocol/CSW.html b/tests/Protocol/CSW.html new file mode 100644 index 0000000000..96a673da6b --- /dev/null +++ b/tests/Protocol/CSW.html @@ -0,0 +1,85 @@ + + + + + + +
+
+ + \ No newline at end of file diff --git a/tests/list-tests.html b/tests/list-tests.html index db4a56faaf..24f0f36199 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -185,6 +185,7 @@
  • Protocol/HTTP.html
  • Protocol/Script.html
  • Protocol/WFS.html
  • +
  • Protocol/CSW.html
  • Protocol/SOS.html
  • Renderer.html
  • Renderer/Canvas.html
  • From 41370b3eb72ea2f3b4e45d172980149698db3bc5 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 9 Jan 2012 09:57:32 +0100 Subject: [PATCH 2/6] fix up broken test --- tests/Protocol/CSW.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Protocol/CSW.html b/tests/Protocol/CSW.html index 96a673da6b..cd2926c9f3 100644 --- a/tests/Protocol/CSW.html +++ b/tests/Protocol/CSW.html @@ -40,6 +40,7 @@ "resultType": "results", "maxRecords": 100, "Query": { + "typeNames": "gmd:MD_Metadata", "ElementSetName": { "value": "full" } @@ -82,4 +83,4 @@ --> - \ No newline at end of file + From ab49a195e39105fe9577a4b58f8061abf73df973 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 9 Jan 2012 10:07:26 +0100 Subject: [PATCH 3/6] update copyright --- lib/OpenLayers/Protocol/CSW.js | 7 ++++--- lib/OpenLayers/Protocol/CSW/v2_0_2.js | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/Protocol/CSW.js b/lib/OpenLayers/Protocol/CSW.js index 2361fd6bbf..5c7e215883 100644 --- a/lib/OpenLayers/Protocol/CSW.js +++ b/lib/OpenLayers/Protocol/CSW.js @@ -1,5 +1,6 @@ -/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD - * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the +/* Copyright (c) 2006-2012 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the Clear BSD license. + * See http://svn.openlayers.org/trunk/openlayers/license.txt for the * full text of the license. */ /** @@ -29,4 +30,4 @@ OpenLayers.Protocol.CSW = function(options) { */ OpenLayers.Protocol.CSW.DEFAULTS = { "version": "2.0.2" -}; \ No newline at end of file +}; diff --git a/lib/OpenLayers/Protocol/CSW/v2_0_2.js b/lib/OpenLayers/Protocol/CSW/v2_0_2.js index 6c6c2643ca..31295fea70 100644 --- a/lib/OpenLayers/Protocol/CSW/v2_0_2.js +++ b/lib/OpenLayers/Protocol/CSW/v2_0_2.js @@ -1,3 +1,8 @@ +/* Copyright (c) 2006-2012 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the Clear BSD license. + * See http://svn.openlayers.org/trunk/openlayers/license.txt for the + * full text of the license. */ + /** * @requires OpenLayers/Protocol/CSW.js */ @@ -115,7 +120,7 @@ OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { } options.callback.call(options.scope, response); - }; + } }, /** @@ -142,4 +147,4 @@ OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { CLASS_NAME: "OpenLayers.Protocol.CSW.v2_0_2" -}); \ No newline at end of file +}); From 476d43857839ed7d5a20c033f11ff5b4bb6be6d2 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 9 Jan 2012 10:27:44 +0100 Subject: [PATCH 4/6] minor doc adjustments and a bit more test coverage --- lib/OpenLayers/Protocol/CSW.js | 5 +---- lib/OpenLayers/Protocol/CSW/v2_0_2.js | 18 ++++++------------ tests/Protocol/CSW.html | 8 ++++++-- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/lib/OpenLayers/Protocol/CSW.js b/lib/OpenLayers/Protocol/CSW.js index 5c7e215883..11703d9ffb 100644 --- a/lib/OpenLayers/Protocol/CSW.js +++ b/lib/OpenLayers/Protocol/CSW.js @@ -9,10 +9,7 @@ /** * Class: OpenLayers.Protocol.CSW - * Used to create a versioned CSW protocol. Default version is 2.0.2. - * - * Inherits from: - * - + * Used to create a versioned CSW protocol. Default version is 2.0.2. */ OpenLayers.Protocol.CSW = function(options) { options = OpenLayers.Util.applyDefaults( diff --git a/lib/OpenLayers/Protocol/CSW/v2_0_2.js b/lib/OpenLayers/Protocol/CSW/v2_0_2.js index 31295fea70..74418f3acd 100644 --- a/lib/OpenLayers/Protocol/CSW/v2_0_2.js +++ b/lib/OpenLayers/Protocol/CSW/v2_0_2.js @@ -5,11 +5,12 @@ /** * @requires OpenLayers/Protocol/CSW.js + * @requires OpenLayers/Format/CSWGetRecords/v2_0_2.js */ /** * Class: OpenLayers.Protocol.CSW.v2_0_2 - * Abstract class for for v2_0_2 protocol. + * CS-W (Catalogue services for the Web) version 2.0.2 protocol. * * Inherits from: * - @@ -24,8 +25,8 @@ OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { formatOptions: null, /** - * Constructor: OpenLayers.Protocol.CSW - * A class for CSW protocol management. + * 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 @@ -34,7 +35,6 @@ OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { initialize: function(options) { OpenLayers.Protocol.prototype.initialize.apply(this, [options]); if(!options.format) { - /* not tested */ this.format = new OpenLayers.Format.CSWGetRecords.v2_0_2(OpenLayers.Util.extend({ }, this.formatOptions)); } @@ -71,11 +71,7 @@ OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { /** * Method: 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). + * Construct a request for reading new records from the Catalogue. */ read: function(options) { options = OpenLayers.Util.extend({}, options); @@ -102,7 +98,7 @@ OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { * Parameters: * response - {} The response object to pass * to the user callback. - * This response is given a code property, and optionally a records one. + * 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. @@ -118,7 +114,6 @@ OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { // failure response.code = OpenLayers.Protocol.Response.FAILURE; } - options.callback.call(options.scope, response); } }, @@ -141,7 +136,6 @@ OpenLayers.Protocol.CSW.v2_0_2 = OpenLayers.Class(OpenLayers.Protocol, { if(!doc || doc.length <= 0) { return null; } - return this.format.read(doc); }, diff --git a/tests/Protocol/CSW.html b/tests/Protocol/CSW.html index cd2926c9f3..11b4b5e997 100644 --- a/tests/Protocol/CSW.html +++ b/tests/Protocol/CSW.html @@ -4,11 +4,15 @@