start with the patch from OL Trac ticket 2133
This commit is contained in:
@@ -242,6 +242,8 @@
|
|||||||
"OpenLayers/Protocol/WFS/v1.js",
|
"OpenLayers/Protocol/WFS/v1.js",
|
||||||
"OpenLayers/Protocol/WFS/v1_0_0.js",
|
"OpenLayers/Protocol/WFS/v1_0_0.js",
|
||||||
"OpenLayers/Protocol/WFS/v1_1_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/Script.js",
|
||||||
"OpenLayers/Protocol/SOS.js",
|
"OpenLayers/Protocol/SOS.js",
|
||||||
"OpenLayers/Protocol/SOS/v1_0_0.js",
|
"OpenLayers/Protocol/SOS/v1_0_0.js",
|
||||||
|
|||||||
@@ -235,6 +235,14 @@ OpenLayers.Protocol.Response = OpenLayers.Class({
|
|||||||
*/
|
*/
|
||||||
features: null,
|
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
|
* Property: reqFeatures
|
||||||
* {Array({<OpenLayers.Feature.Vector>})} or {<OpenLayers.Feature.Vector>}
|
* {Array({<OpenLayers.Feature.Vector>})} or {<OpenLayers.Feature.Vector>}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
*/
|
||||||
|
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"
|
||||||
|
};
|
||||||
@@ -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>
|
||||||
|
*/
|
||||||
|
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 - {<OpenLayers.Protocol.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 - {<OpenLayers.Protocol.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"
|
||||||
|
|
||||||
|
});
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function test_initialize(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
var protocol = new OpenLayers.Protocol.CSW({});
|
||||||
|
t.ok(protocol instanceof OpenLayers.Protocol.CSW.v2_0_2,
|
||||||
|
"initialize returns instance of default versioned protocol");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_read(t) {
|
||||||
|
t.plan(6);
|
||||||
|
|
||||||
|
var protocol = new OpenLayers.Protocol.CSW({
|
||||||
|
url: "http://some.url.org",
|
||||||
|
parseData: function(request) {
|
||||||
|
t.eq(request.responseText, "foo", "parseData called properly");
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var _POST = OpenLayers.Request.POST;
|
||||||
|
|
||||||
|
var expected, status;
|
||||||
|
OpenLayers.Request.POST = function(obj) {
|
||||||
|
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetRecords request is correct");
|
||||||
|
obj.status = status;
|
||||||
|
obj.responseText = "foo";
|
||||||
|
obj.options = {};
|
||||||
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
expected = readXML("GetRecords");
|
||||||
|
status = 200;
|
||||||
|
var data = {
|
||||||
|
"resultType": "results",
|
||||||
|
"maxRecords": 100,
|
||||||
|
"Query": {
|
||||||
|
"ElementSetName": {
|
||||||
|
"value": "full"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var response = protocol.read({
|
||||||
|
params: data,
|
||||||
|
callback: function(response) {
|
||||||
|
t.eq(response.data, "foo", "user callback properly called with data");
|
||||||
|
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly to user callback");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
params: data,
|
||||||
|
callback: function(response) {
|
||||||
|
t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, "failure reported properly to user callback");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
status = 400;
|
||||||
|
var response = protocol.read(options);
|
||||||
|
|
||||||
|
OpenLayers.Request.POST = _POST;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readXML(id) {
|
||||||
|
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||||
|
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="map" style="width:512px; height:256px"> </div>
|
||||||
|
<div id="GetRecords"><!--
|
||||||
|
<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" resultType="results" maxRecords="100">
|
||||||
|
<csw:Query typeNames="gmd:MD_Metadata">
|
||||||
|
<csw:ElementSetName>full</csw:ElementSetName>
|
||||||
|
</csw:Query>
|
||||||
|
</csw:GetRecords>
|
||||||
|
--></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -185,6 +185,7 @@
|
|||||||
<li>Protocol/HTTP.html</li>
|
<li>Protocol/HTTP.html</li>
|
||||||
<li>Protocol/Script.html</li>
|
<li>Protocol/Script.html</li>
|
||||||
<li>Protocol/WFS.html</li>
|
<li>Protocol/WFS.html</li>
|
||||||
|
<li>Protocol/CSW.html</li>
|
||||||
<li>Protocol/SOS.html</li>
|
<li>Protocol/SOS.html</li>
|
||||||
<li>Renderer.html</li>
|
<li>Renderer.html</li>
|
||||||
<li>Renderer/Canvas.html</li>
|
<li>Renderer/Canvas.html</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user