Skip to content

Commit

Permalink
Merge pull request #40 from elemoine/wmtscaps
Browse files Browse the repository at this point in the history
Make OWSCommon v1 support constraints in Get and Post nodes, and respect the 1..* cardinality.
  • Loading branch information
ahocevar committed Nov 7, 2011
2 parents 9836337 + eac8bb5 commit f3a0a73
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
28 changes: 24 additions & 4 deletions lib/OpenLayers/Format/OWSCommon/v1.js
Expand Up @@ -171,12 +171,24 @@ OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
this.readChildNodes(node, dcp.http);
},
"Get": function(node, http) {
http.get = this.getAttributeNS(node,
this.namespaces.xlink, "href");
if (!http.get) {
http.get = [];
}
var obj = {
url: this.getAttributeNS(node, this.namespaces.xlink, "href")
};
this.readChildNodes(node, obj);
http.get.push(obj);
},
"Post": function(node, http) {
http.post = this.getAttributeNS(node,
this.namespaces.xlink, "href");
if (!http.post) {
http.post = [];
}
var obj = {
url: this.getAttributeNS(node, this.namespaces.xlink, "href")
};
this.readChildNodes(node, obj);
http.post.push(obj);
},
"Parameter": function(node, operation) {
if (!operation.parameters) {
Expand All @@ -186,6 +198,14 @@ OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
operation.parameters[name] = {};
this.readChildNodes(node, operation.parameters[name]);
},
"Constraint": function(node, obj) {
if (!obj.constraints) {
obj.constraints = {};
}
var name = node.getAttribute("name");
obj.constraints[name] = {};
this.readChildNodes(node, obj.constraints[name]);
},
"Value": function(node, allowedValues) {
allowedValues[this.getChildValue(node)] = true;
},
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenLayers/Format/WMTSCapabilities.js
Expand Up @@ -116,7 +116,7 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers
OpenLayers.Util.applyDefaults(config, {
url: config.requestEncoding === "REST" && layerDef.resourceUrl ?
layerDef.resourceUrl.tile.template :
capabilities.operationsMetadata.GetTile.dcp.http.get,
capabilities.operationsMetadata.GetTile.dcp.http.get[0].url,
name: layerDef.title,
style: style.identifier,
matrixIds: matrixSet.matrixIds,
Expand Down
4 changes: 2 additions & 2 deletions tests/Format/OWSCommon/v1_1_0.html
Expand Up @@ -6,7 +6,7 @@
function test_read_exception(t) {
t.plan(6);
var text = '<?xml version="1.0" encoding="UTF-8"?>' +
'<ows:ExceptionReport xml:lang="en" version="1.0.0"' +
'<ows:ExceptionReport xml:lang="en" version="1.1.0"' +
' xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows/1.1">' +
' <ows:Exception locator="foo" exceptionCode="InvalidParameterValue">' +
Expand All @@ -18,7 +18,7 @@
var format = new OpenLayers.Format.OWSCommon();
var result = format.read(text);
var report = result.exceptionReport;
t.eq(report.version, "1.0.0", "Version parsed correctly");
t.eq(report.version, "1.1.0", "Version parsed correctly");
t.eq(report.language, "en", "Language parsed correctly");
var exception = report.exceptions[0];
t.eq(exception.code, "InvalidParameterValue", "exceptionCode properly parsed");
Expand Down
2 changes: 1 addition & 1 deletion tests/Format/SOSCapabilities/v1_0_0.html
Expand Up @@ -40,7 +40,7 @@
t.eq(obj.serviceProvider.serviceContact.contactInfo.phone.voice, "+49-251-83-30088", "Voice phone correctly parsed");

// operationsMetadata (from OWSCommon)
t.eq(obj.operationsMetadata.DescribeSensor.dcp.http.post, "http://v-swe.uni-muenster.de:8080/WeatherSOS/sos", "POST url for DescribeSensor correctly parsed");
t.eq(obj.operationsMetadata.DescribeSensor.dcp.http.post[0].url, "http://v-swe.uni-muenster.de:8080/WeatherSOS/sos", "POST url for DescribeSensor correctly parsed");
var counter = 0;
for (var key in obj.operationsMetadata.DescribeSensor.parameters.procedure.allowedValues) {
if (counter == 0) {
Expand Down
15 changes: 12 additions & 3 deletions tests/Format/WMTSCapabilities/v1_0_0.html
Expand Up @@ -4,7 +4,7 @@
<script type="text/javascript">

function test_ows(t) {
t.plan(17);
t.plan(20);
var xml = document.getElementById("ogcsample").firstChild.nodeValue;
var doc = new OpenLayers.Format.XML().read(xml);
var obj = new OpenLayers.Format.WMTSCapabilities().read(doc);
Expand All @@ -31,8 +31,17 @@
// ows:OperationsMetadata
var operationsMetadata = obj.operationsMetadata;
t.eq(operationsMetadata.GetCapabilities.dcp.http.get, "http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?", "ows:OperationsMetadata GetCapabilities url is correct");
t.eq(operationsMetadata.GetCapabilities.dcp.http.constraints.get.GetEncoding.allowedValues,
{'KVP': true},
"ows:OperationsMetadata GetCapabilities Constraints Get is correct");
t.eq(operationsMetadata.GetFeatureInfo.dcp.http.get, "http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?", "ows:OperationsMetadata GetFeatureInfo url is correct");
t.eq(operationsMetadata.GetFeatureInfo.dcp.http.constraints.get,
undefined,
"ows:OperationsMetadata GetFeatureInfo Constraints Get is correct");
t.eq(operationsMetadata.GetTile.dcp.http.get, "http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?", "ows:OperationsMetadata GetTile url is correct");
t.eq(operationsMetadata.GetTile.dcp.http.constraints.get,
undefined,
"ows:OperationsMetadata GetTile Constraints Get is correct");
}

function test_layers(t) {
Expand All @@ -47,7 +56,7 @@
t.eq(numOfLayers, 1, "correct count of layers");

var layer = contents.layers[0];
t.eq(layer.abstract, "Coastline/shorelines (BA010)", "layer abstract is correct");
t.eq(layer['abstract'], "Coastline/shorelines (BA010)", "layer abstract is correct");
t.eq(layer.identifier, "coastlines", "layer identifier is correct");
t.eq(layer.title, "Coastlines", "layer title is correct");

Expand Down Expand Up @@ -90,7 +99,7 @@
var dimensions = layer.dimensions;
t.eq(dimensions.length, 1, "correct count of dimensions");
t.eq(dimensions[0].title, "Time", "first dimension title is correct");
t.eq(dimensions[0].abstract, "Monthly datasets", "first dimension abstract is correct");
t.eq(dimensions[0]['abstract'], "Monthly datasets", "first dimension abstract is correct");
t.eq(dimensions[0].identifier, "TIME", "first dimension identifier is correct");
t.eq(dimensions[0]['default'], "default", "first dimension default is correct");
t.eq(dimensions[0].values.length, 3, "first dimension has correct count of values");
Expand Down

0 comments on commit f3a0a73

Please sign in to comment.