add formats for CSW GetRecords and GetDomain requests, p=bbinet, r=me (closes #2132)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9699 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2009-10-05 08:15:48 +00:00
parent 3fa2971816
commit 5fad952e8a
12 changed files with 1011 additions and 0 deletions

View File

@@ -238,6 +238,10 @@
"OpenLayers/Format/SLD/v1.js",
"OpenLayers/Format/SLD/v1_0_0.js",
"OpenLayers/Format/SLD/v1.js",
"OpenLayers/Format/CSWGetDomain.js",
"OpenLayers/Format/CSWGetDomain/v2_0_2.js",
"OpenLayers/Format/CSWGetRecords.js",
"OpenLayers/Format/CSWGetRecords/v2_0_2.js",
"OpenLayers/Format/WFST.js",
"OpenLayers/Format/WFST/v1.js",
"OpenLayers/Format/WFST/v1_0_0.js",

View File

@@ -0,0 +1,33 @@
/* 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/Format.js
*/
/**
* Function: OpenLayers.Format.CSWGetDomain.
* Default version is 2.0.2.
*
* Returns:
* {<OpenLayers.Format>} A CSWGetDomain format of the given version.
*/
OpenLayers.Format.CSWGetDomain = function(options) {
options = OpenLayers.Util.applyDefaults(
options, OpenLayers.Format.CSWGetDomain.DEFAULTS
);
var cls = OpenLayers.Format.CSWGetDomain["v"+options.version.replace(/\./g, "_")];
if(!cls) {
throw "Unsupported CSWGetDomain version: " + options.version;
}
return new cls(options);
};
/**
* Constant: OpenLayers.Format.CSWGetDomain.DEFAULTS
* {Object} Default properties for the CSWGetDomain format.
*/
OpenLayers.Format.CSWGetDomain.DEFAULTS = {
"version": "2.0.2"
};

View File

@@ -0,0 +1,242 @@
/* 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/Format/XML.js
* @requires OpenLayers/Format/CSWGetDomain.js
*/
/**
* Class: OpenLayers.Format.CSWGetDomain.v2_0_2
* A format for creating CSWGetDomain v2.0.2 transactions.
* Create a new instance with the
* <OpenLayers.Format.CSWGetDomain.v2_0_2> constructor.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.CSWGetDomain.v2_0_2 = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
xlink: "http://www.w3.org/1999/xlink",
xsi: "http://www.w3.org/2001/XMLSchema-instance",
csw: "http://www.opengis.net/cat/csw/2.0.2"
},
/**
* Property: defaultPrefix
* {String} The default prefix (used by Format.XML).
*/
defaultPrefix: "csw",
/**
* Property: version
* {String} CSW version number.
*/
version: "2.0.2",
/**
* Property: schemaLocation
* {String} http://www.opengis.net/cat/csw/2.0.2
* http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd
*/
schemaLocation: "http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd",
/**
* APIProperty: PropertyName
* {String} Value of the csw:PropertyName element, used when
* writing a GetDomain document.
*/
PropertyName: null,
/**
* APIProperty: ParameterName
* {String} Value of the csw:ParameterName element, used when
* writing a GetDomain document.
*/
ParameterName: null,
/**
* Constructor: OpenLayers.Format.CSWGetDomain.v2_0_2
* A class for parsing and generating CSWGetDomain v2.0.2 transactions.
*
* Parameters:
* options - {Object} Optional object whose properties will be set on the
* instance.
*
* Valid options properties:
* - PropertyName
* - ParameterName
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: read
* Parse the response from a GetDomain request.
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var obj = {};
this.readNode(data, obj);
return obj;
},
/**
* Property: readers
* Contains public functions, grouped by namespace prefix, that will
* be applied when a namespaced node is found matching the function
* name. The function will be applied in the scope of this parser
* with two arguments: the node being read and a context object passed
* from the parent.
*/
readers: {
"csw": {
"GetDomainResponse": function(node, obj) {
this.readChildNodes(node, obj);
},
"DomainValues": function(node, obj) {
if (!(obj.DomainValues instanceof Array)) {
obj.DomainValues = [];
}
var attrs = node.attributes;
var domainValue = {};
for(var i=0, len=attrs.length; i<len; ++i) {
domainValue[attrs[i].name] = attrs[i].nodeValue;
}
this.readChildNodes(node, domainValue);
obj.DomainValues.push(domainValue);
},
"PropertyName": function(node, obj) {
obj.PropertyName = this.getChildValue(node);
},
"ParameterName": function(node, obj) {
obj.ParameterName = this.getChildValue(node);
},
"ListOfValues": function(node, obj) {
if (!(obj.ListOfValues instanceof Array)) {
obj.ListOfValues = [];
}
this.readChildNodes(node, obj.ListOfValues);
},
"Value": function(node, obj) {
var attrs = node.attributes;
var value = {}
for(var i=0, len=attrs.length; i<len; ++i) {
value[attrs[i].name] = attrs[i].nodeValue;
}
value.value = this.getChildValue(node);
obj.push({Value: value});
},
"ConceptualScheme": function(node, obj) {
obj.ConceptualScheme = {};
this.readChildNodes(node, obj.ConceptualScheme);
},
"Name": function(node, obj) {
obj.Name = this.getChildValue(node);
},
"Document": function(node, obj) {
obj.Document = this.getChildValue(node);
},
"Authority": function(node, obj) {
obj.Authority = this.getChildValue(node);
},
"RangeOfValues": function(node, obj) {
obj.RangeOfValues = {};
this.readChildNodes(node, obj.RangeOfValues);
},
"MinValue": function(node, obj) {
var attrs = node.attributes;
var value = {}
for(var i=0, len=attrs.length; i<len; ++i) {
value[attrs[i].name] = attrs[i].nodeValue;
}
value.value = this.getChildValue(node);
obj.MinValue = value;
},
"MaxValue": function(node, obj) {
var attrs = node.attributes;
var value = {}
for(var i=0, len=attrs.length; i<len; ++i) {
value[attrs[i].name] = attrs[i].nodeValue;
}
value.value = this.getChildValue(node);
obj.MaxValue = value;
}
}
},
/**
* APIMethod: write
* Given an configuration js object, write a CSWGetDomain request.
*
* Parameters:
* options - {Object} A object mapping the request.
*
* Returns:
* {String} A serialized CSWGetDomain request.
*/
write: function(options) {
var node = this.writeNode("csw:GetDomain", options);
return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
},
/**
* Property: writers
* As a compliment to the readers property, this structure contains public
* writing functions grouped by namespace alias and named like the
* node names they produce.
*/
writers: {
"csw": {
"GetDomain": function(options) {
var node = this.createElementNSPlus("csw:GetDomain", {
attributes: {
service: "CSW",
version: this.version
}
});
if (options.PropertyName || this.PropertyName) {
this.writeNode(
"csw:PropertyName",
options.PropertyName || this.PropertyName,
node
);
} else if (options.ParameterName || this.ParameterName) {
this.writeNode(
"csw:ParameterName",
options.ParameterName || this.ParameterName,
node
);
}
this.readChildNodes(node, options);
return node;
},
"PropertyName": function(value) {
var node = this.createElementNSPlus("csw:PropertyName", {
value: value
});
return node;
},
"ParameterName": function(value) {
var node = this.createElementNSPlus("csw:ParameterName", {
value: value
});
return node;
}
}
},
CLASS_NAME: "OpenLayers.Format.CSWGetDomain.v2_0_2"
});

View File

@@ -0,0 +1,33 @@
/* 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/Format.js
*/
/**
* Function: OpenLayers.Format.CSWGetRecords.
* Default version is 2.0.2.
*
* Returns:
* {<OpenLayers.Format>} A CSWGetRecords format of the given version.
*/
OpenLayers.Format.CSWGetRecords = function(options) {
options = OpenLayers.Util.applyDefaults(
options, OpenLayers.Format.CSWGetRecords.DEFAULTS
);
var cls = OpenLayers.Format.CSWGetRecords["v"+options.version.replace(/\./g, "_")];
if(!cls) {
throw "Unsupported CSWGetRecords version: " + options.version;
}
return new cls(options);
};
/**
* Constant: OpenLayers.Format.CSWGetRecords.DEFAULTS
* {Object} Default properties for the CSWGetRecords format.
*/
OpenLayers.Format.CSWGetRecords.DEFAULTS = {
"version": "2.0.2"
};

View File

@@ -0,0 +1,454 @@
/* 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/Format/XML.js
* @requires OpenLayers/Format/CSWGetRecords.js
* @requires OpenLayers/Format/Filter/v1_0_0.js
* @requires OpenLayers/Format/Filter/v1_1_0.js
*/
/**
* Class: OpenLayers.Format.CSWGetRecords.v2_0_2
* A format for creating CSWGetRecords v2.0.2 transactions.
* Create a new instance with the
* <OpenLayers.Format.CSWGetRecords.v2_0_2> constructor.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.CSWGetRecords.v2_0_2 = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
xlink: "http://www.w3.org/1999/xlink",
xsi: "http://www.w3.org/2001/XMLSchema-instance",
csw: "http://www.opengis.net/cat/csw/2.0.2",
dc: "http://purl.org/dc/elements/1.1/",
dct: "http://purl.org/dc/terms/",
ows: "http://www.opengis.net/ows"
},
/**
* Property: defaultPrefix
* {String} The default prefix (used by Format.XML).
*/
defaultPrefix: "csw",
/**
* Property: version
* {String} CSW version number.
*/
version: "2.0.2",
/**
* Property: schemaLocation
* {String} http://www.opengis.net/cat/csw/2.0.2
* http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd
*/
schemaLocation: "http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd",
/**
* APIProperty: requestId
* {String} Value of the requestId attribute of the GetRecords element.
*/
requestId: null,
/**
* APIProperty: resultType
* {String} Value of the resultType attribute of the GetRecords element,
* specifies the result type in the GetRecords response, "hits" is
* the default.
*/
resultType: null,
/**
* APIProperty: outputFormat
* {String} Value of the outputFormat attribute of the GetRecords element,
* specifies the format of the GetRecords response,
* "application/xml" is the default.
*/
outputFormat: null,
/**
* APIProperty: outputSchema
* {String} Value of the outputSchema attribute of the GetRecords element,
* specifies the schema of the GetRecords response.
*/
outputSchema: null,
/**
* APIProperty: startPosition
* {String} Value of the startPosition attribute of the GetRecords element,
* specifies the start position (offset+1) for the GetRecords response,
* 1 is the default.
*/
startPosition: null,
/**
* APIProperty: maxRecords
* {String} Value of the maxRecords attribute of the GetRecords element,
* specifies the maximum number of records in the GetRecords response,
* 10 is the default.
*/
maxRecords: null,
/**
* APIProperty: DistributedSearch
* {String} Value of the csw:DistributedSearch element, used when writing
* a csw:GetRecords document.
*/
DistributedSearch: null,
/**
* APIProperty: ResponseHandler
* {Array({String})} Values of the csw:ResponseHandler elements, used when
* writting a csw:GetRecords document.
*/
ResponseHandler: null,
/**
* APIProperty: Query
* {String} Value of the csw:Query element, used when writing a csw:GetRecords
* document.
*/
Query: null,
/**
* Constructor: OpenLayers.Format.CSWGetRecords.v2_0_2
* A class for parsing and generating CSWGetRecords v2.0.2 transactions.
*
* Parameters:
* options - {Object} Optional object whose properties will be set on the
* instance.
*
* Valid options properties (documented as class properties):
* - requestId
* - resultType
* - outputFormat
* - outputSchema
* - startPosition
* - maxRecords
* - DistributedSearch
* - ResponseHandler
* - Query
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: read
* Parse the response from a GetRecords request.
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var obj = {};
this.readNode(data, obj);
return obj;
},
/**
* Property: readers
* Contains public functions, grouped by namespace prefix, that will
* be applied when a namespaced node is found matching the function
* name. The function will be applied in the scope of this parser
* with two arguments: the node being read and a context object passed
* from the parent.
*/
readers: {
"csw": {
"GetRecordsResponse": function(node, obj) {
obj.records = [];
this.readChildNodes(node, obj);
var version = this.getAttributeNS(node, "", 'version');
if (version != "") {
obj.version = version;
}
},
"RequestId": function(node, obj) {
obj.RequestId = this.getChildValue(node);
},
"SearchStatus": function(node, obj) {
obj.SearchStatus = {};
var timestamp = this.getAttributeNS(node, "", 'timestamp');
if (timestamp != "") {
obj.SearchStatus.timestamp = timestamp;
}
},
"SearchResults": function(node, obj) {
this.readChildNodes(node, obj);
var attrs = node.attributes;
var SearchResults = {};
for(var i=0, len=attrs.length; i<len; ++i) {
if ((attrs[i].name == "numberOfRecordsMatched") ||
(attrs[i].name == "numberOfRecordsReturned") ||
(attrs[i].name == "nextRecord")) {
SearchResults[attrs[i].name] = parseInt(attrs[i].nodeValue);
} else {
SearchResults[attrs[i].name] = attrs[i].nodeValue;
}
}
obj.SearchResults = SearchResults;
},
"SummaryRecord": function(node, obj) {
var record = {type: "SummaryRecord"};
this.readChildNodes(node, record);
obj.records.push(record);
},
"BriefRecord": function(node, obj) {
var record = {type: "BriefRecord"};
this.readChildNodes(node, record);
obj.records.push(record);
},
"DCMIRecord": function(node, obj) {
var record = {type: "DCMIRecord"};
this.readChildNodes(node, record);
obj.records.push(record);
},
"Record": function(node, obj) {
var record = {type: "Record"};
this.readChildNodes(node, record);
obj.records.push(record);
}
},
"dc": {
// audience, contributor, coverage, creator, date, description, format,
// identifier, language, provenance, publisher, relation, rights,
// rightsHolder, source, subject, title, type, URI
"*": function(node, obj) {
if (!(obj[node.localName] instanceof Array)) {
obj[node.localName] = new Array();
}
var dc_element = {};
var attrs = node.attributes;
for(var i=0, len=attrs.length; i<len; ++i) {
dc_element[attrs[i].name] = attrs[i].nodeValue;
}
dc_element.value = this.getChildValue(node);
obj[node.localName].push(dc_element);
}
},
"dct": {
// abstract, modified, spatial
"*": function(node, obj) {
if (!(obj[node.localName] instanceof Array)) {
obj[node.localName] = new Array();
}
obj[node.localName].push(this.getChildValue(node));
}
},
"ows": {
"WGS84BoundingBox": function(node, obj) {
// LowerCorner = "min_x min_y"
// UpperCorner = "max_x max_y"
if (!(obj.BoundingBox instanceof Array)) {
obj.BoundingBox = new Array();
}
//this.readChildNodes(node, bbox);
var lc = this.getChildValue(
this.getElementsByTagNameNS(
node,
this.namespaces["ows"],
"LowerCorner"
)[0]
).split(' ', 2);
var uc = this.getChildValue(
this.getElementsByTagNameNS(
node,
this.namespaces["ows"],
"UpperCorner"
)[0]
).split(' ', 2);
var boundingBox = {
value: [
parseFloat(lc[0]),
parseFloat(lc[1]),
parseFloat(uc[0]),
parseFloat(uc[1])
]
};
// store boundingBox attributes
var attrs = node.attributes;
for(var i=0, len=attrs.length; i<len; ++i) {
boundingBox[attrs[i].name] = attrs[i].nodeValue;
}
obj.BoundingBox.push(boundingBox);
},
"BoundingBox": function(node, obj) {
// FIXME: We consider that BoundingBox is the same as WGS84BoundingBox
// LowerCorner = "min_x min_y"
// UpperCorner = "max_x max_y"
// It should normally depend on the projection
this.readers['ows']['WGS84BoundingBox'].apply(this, [node, obj]);
}
}
},
/**
* Method: write
* Given an configuration js object, write a CSWGetRecords request.
*
* Parameters:
* options - {Object} A object mapping the request.
*
* Returns:
* {String} A serialized CSWGetRecords request.
*/
write: function(options) {
var node = this.writeNode("csw:GetRecords", options);
return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
},
/**
* Property: writers
* As a compliment to the readers property, this structure contains public
* writing functions grouped by namespace alias and named like the
* node names they produce.
*/
writers: {
"csw": {
"GetRecords": function(options) {
if (!options) {
options = {};
}
var node = this.createElementNSPlus("csw:GetRecords", {
attributes: {
service: "CSW",
version: this.version,
requestId: options.requestId || this.requestId,
resultType: options.resultType || this.resultType,
outputFormat: options.outputFormat || this.outputFormat,
outputSchema: options.outputSchema || this.outputSchema,
startPosition: options.startPosition || this.startPosition,
maxRecords: options.maxRecords || this.maxRecords
}
});
if (options.DistributedSearch || this.DistributedSearch) {
this.writeNode(
"csw:DistributedSearch",
options.DistributedSearch || this.DistributedSearch,
node
);
}
var ResponseHandler = options.ResponseHandler || this.ResponseHandler;
if (ResponseHandler instanceof Array && ResponseHandler.length > 0) {
// ResponseHandler must be a non-empty array
for(var i=0, len=ResponseHandler.length; i<len; i++) {
this.writeNode(
"csw:ResponseHandler",
ResponseHandler[i],
node
);
}
}
this.writeNode("Query", options.Query || this.Query, node);
return node;
},
"DistributedSearch": function(options) {
var node = this.createElementNSPlus("csw:DistributedSearch", {
attributes: {
hopCount: options.hopCount
}
});
return node;
},
"ResponseHandler": function(options) {
var node = this.createElementNSPlus("csw:ResponseHandler", {
value: options.value
});
return node;
},
"Query": function(options) {
if (!options) {
options = {};
}
var node = this.createElementNSPlus("csw:Query", {
attributes: {
typeNames: options.typeNames || "csw:Record"
}
});
var ElementName = options.ElementName;
if (ElementName instanceof Array && ElementName.length > 0) {
// ElementName must be a non-empty array
for(var i=0, len=ElementName.length; i<len; i++) {
this.writeNode(
"csw:ElementName",
ElementName[i],
node
);
}
} else {
this.writeNode(
"csw:ElementSetName",
options.ElementSetName || {value: 'summary'},
node
);
}
if (options.Constraint) {
this.writeNode(
"csw:Constraint",
options.Constraint,
node
);
}
//TODO: not implemented in ogc filters?
//if (options.SortBy) {
//this.writeNode(
//"ogc:SortBy",
//options.SortBy,
//node
//);
//}
return node;
},
"ElementName": function(options) {
var node = this.createElementNSPlus("csw:ElementName", {
value: options.value
});
return node;
},
"ElementSetName": function(options) {
var node = this.createElementNSPlus("csw:ElementSetName", {
attributes: {
typeNames: options.typeNames
},
value: options.value
});
return node;
},
"Constraint": function(options) {
var node = this.createElementNSPlus("csw:Constraint", {
attributes: {
version: options.version
}
});
if (options.Filter) {
var format = new OpenLayers.Format.Filter({
version: options.version
});
node.appendChild(format.write(options.Filter));
} else if (options.CqlText) {
var child = this.createElementNSPlus("CqlText", {
value: options.CqlText.value
});
node.appendChild(child);
}
return node;
}
}
},
CLASS_NAME: "OpenLayers.Format.CSWGetRecords.v2_0_2"
});

View File

@@ -0,0 +1,23 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_initialize(t) {
t.plan(2);
var format = new OpenLayers.Format.CSWGetDomain();
t.ok(format instanceof OpenLayers.Format.CSWGetDomain.v2_0_2, "constructor returns instance with default versioned format");
format = new OpenLayers.Format.CSWGetDomain({
version: "2.0.2"
});
t.ok(format instanceof OpenLayers.Format.CSWGetDomain.v2_0_2, "constructor returns instance with custom versioned format");
}
</script>
</head>
<body>
<div id="map" style="width:512px; height:256px"> </div>
</body>
</html>

View File

@@ -0,0 +1,56 @@
<html>
<head>
<script src="../../../lib/OpenLayers.js"></script>
<script src="v2_0_2.js"></script>
<script type="text/javascript">
var format = new OpenLayers.Format.CSWGetDomain();
function test_write(t) {
t.plan(1);
var options = {
PropertyName: "type"
};
var result = format.write(options);
t.eq(result, csw_request, "check value returned by format " +
"CSWGetDomain: write method");
}
function test_read(t) {
t.plan(9);
var obj = format.read(csw_response);
var domainValues = obj.DomainValues;
// test getRecordsResponse object
t.ok(domainValues, "object contains DomainValues property");
// test DomainValues
t.eq(domainValues.length, 1, "object contains 1 object in DomainValues");
var domainValue = domainValues[0];
t.eq(domainValue.type, "csw:Record", "check value for attribute type");
t.eq(domainValue.PropertyName, "type", "check value for element PropertyName");
t.ok(domainValue.ListOfValues, "object contains ListOfValues property");
// test ListOfValues
t.eq(domainValue.ListOfValues.length, 2, "object contains 2 objects " +
"in ListOfValues");
var val = domainValue.ListOfValues[0];
t.ok(val.Value, "object contains Value property");
t.eq(val.Value.my_attr, "my_value", "check value for attribute my_attr");
t.eq(val.Value.value, "dataset", "check value for element Value");
}
</script>
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,18 @@
var csw_request =
'<csw:GetDomain xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2">' +
'<csw:PropertyName>type</csw:PropertyName>' +
'</csw:GetDomain>';
var csw_response =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<csw:GetDomainResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">' +
'<csw:DomainValues type="csw:Record">' +
'<csw:PropertyName>type</csw:PropertyName>' +
'<csw:ListOfValues>' +
'<csw:Value my_attr="my_value">dataset</csw:Value>' +
'<csw:Value>service</csw:Value>' +
'</csw:ListOfValues>' +
'</csw:DomainValues>' +
'</csw:GetDomainResponse>'
;

View File

@@ -0,0 +1,23 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_initialize(t) {
t.plan(2);
var format = new OpenLayers.Format.CSWGetRecords();
t.ok(format instanceof OpenLayers.Format.CSWGetRecords.v2_0_2, "constructor returns instance with default versioned format");
format = new OpenLayers.Format.CSWGetRecords({
version: "2.0.2"
});
t.ok(format instanceof OpenLayers.Format.CSWGetRecords.v2_0_2, "constructor returns instance with custom versioned format");
}
</script>
</head>
<body>
<div id="map" style="width:512px; height:256px"> </div>
</body>
</html>

View File

@@ -0,0 +1,81 @@
<html>
<head>
<script src="../../../lib/OpenLayers.js"></script>
<script src="v2_0_2.js"></script>
<script type="text/javascript">
var format = new OpenLayers.Format.CSWGetRecords();
function test_write(t) {
t.plan(1);
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.LIKE,
property: "my_prop",
value: "my_prop_value"
});
var options = {
"resultType": "results",
"startPosition": "10",
"maxRecords": "20",
"Query": {
"ElementSetName": {
"value": "brief"
},
"Constraint": {
"version": "1.1.0",
"Filter": filter
}
}
};
var result = format.write(options);
t.eq(result, csw_request, "check value returned by format " +
"CSWGetRecords: write method");
}
function test_read(t) {
t.plan(14);
var obj = format.read(csw_response);
var searchStatus = obj.SearchStatus;
var searchResults = obj.SearchResults;
var records = obj.records;
// test getRecordsResponse object
t.ok(searchStatus, "object contains SearchStatus property");
t.ok(searchResults, "object contains SearchResults property");
t.ok(records, "object contains records property");
// test SearchResults attributes
t.eq(searchResults.numberOfRecordsMatched, 10, "check value for SearchResults.numberOfRecordsMatched");
t.eq(searchResults.numberOfRecordsReturned, 2, "check value for SearchResults.numberOfRecordsReturned");
t.eq(searchResults.elementSet, "brief", "check value for SearchResults.elementSet");
t.eq(searchResults.nextRecord, 3, "check value for SearchResults.nextRecord");
// test records
t.eq(records.length, 2, "object contains 10 records");
var testRecord = records[0];
t.eq(testRecord.type, "BriefRecord", "check value for record.type");
t.eq(testRecord.title, [{value:"Sample title"}], "check value for record.title");
//test bbox
t.eq(testRecord.BoundingBox.length, 1, "object contains 1 BoundingBox");
var bbox = testRecord.BoundingBox[0];
t.ok(bbox, "object contains BoundingBox properties");
t.eq(bbox.crs, "::Lambert Azimuthal Projection", "check value for BoundingBox.crs");
t.eq(bbox.value, [156, -3, 37, 83], "check value for record.BoundingBox");
}
</script>
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,40 @@
var csw_request =
'<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" resultType="results" startPosition="10" maxRecords="20">' +
'<csw:Query typeNames="csw:Record">' +
'<csw:ElementSetName>brief</csw:ElementSetName>' +
'<csw:Constraint version="1.1.0">' +
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
'<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">' +
'<ogc:PropertyName>my_prop</ogc:PropertyName>' +
'<ogc:Literal>my_prop_value</ogc:Literal>' +
'</ogc:PropertyIsLike>' +
'</ogc:Filter>' +
'</csw:Constraint>' +
'</csw:Query>' +
'</csw:GetRecords>';
var csw_response =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">' +
'<csw:SearchStatus timestamp="2009-06-08T12:03:34" />' +
'<csw:SearchResults numberOfRecordsMatched="10" numberOfRecordsReturned="2" elementSet="brief" nextRecord="3">' +
'<csw:BriefRecord xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/">' +
'<dc:identifier>895ac38b-7aef-4a21-b593-b35a6fc7bba9</dc:identifier>' +
'<dc:title>Sample title</dc:title>' +
'<ows:BoundingBox crs="::Lambert Azimuthal Projection">' +
'<ows:LowerCorner>156 -3</ows:LowerCorner>' +
'<ows:UpperCorner>37 83</ows:UpperCorner>' +
'</ows:BoundingBox>' +
'</csw:BriefRecord>' +
'<csw:BriefRecord xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/">' +
'<dc:identifier>8a7245c3-8546-42de-8e6f-8fb8b5fd1bc3</dc:identifier>' +
'<dc:title>Second record : sample title</dc:title>' +
'<ows:BoundingBox crs="::WGS 1984">' +
'<ows:LowerCorner>51.1 -34.6</ows:LowerCorner>' +
'<ows:UpperCorner>-17.3 38.2</ows:UpperCorner>' +
'</ows:BoundingBox>' +
'</csw:BriefRecord>' +
'</csw:SearchResults>' +
'</csw:GetRecordsResponse>'
;

View File

@@ -79,6 +79,10 @@
<li>Format/WMSCapabilities/v1_1_1.html</li>
<li>Format/WMSDescribeLayer.html</li>
<li>Format/WMSGetFeatureInfo.html</li>
<li>Format/CSWGetDomain.html</li>
<li>Format/CSWGetDomain/v2_0_2.html</li>
<li>Format/CSWGetRecords.html</li>
<li>Format/CSWGetRecords/v2_0_2.html</li>
<li>Format/XML.html</li>
<li>Geometry.html</li>
<li>Geometry/Collection.html</li>