Adding more extensive parsing of WFS capabilities documents. Thanks fvanderbiest for the great patch. r=me (closes #2245)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9658 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-09-11 19:17:10 +00:00
parent bdabaa86f9
commit f8c2889947
2 changed files with 145 additions and 1 deletions

View File

@@ -25,7 +25,128 @@ OpenLayers.Format.WFSCapabilities.v1_0_0 = OpenLayers.Class(
this, [options]
);
},
/**
* Method: read_cap_Service
*/
read_cap_Service: function(capabilities, node) {
var service = {};
this.runChildNodes(service, node);
capabilities.service = service;
},
/**
* Method: read_cap_Fees
*/
read_cap_Fees: function(service, node) {
var fees = this.getChildValue(node);
if (fees && fees.toLowerCase() != "none") {
service.fees = fees;
}
},
/**
* Method: read_cap_AccessConstraints
*/
read_cap_AccessConstraints: function(service, node) {
var constraints = this.getChildValue(node);
if (constraints && constraints.toLowerCase() != "none") {
service.accessConstraints = constraints;
}
},
/**
* Method: read_cap_OnlineResource
*/
read_cap_OnlineResource: function(service, node) {
var onlineResource = this.getChildValue(node);
if (onlineResource && onlineResource.toLowerCase() != "none") {
service.onlineResource = onlineResource;
}
},
/**
* Method: read_cap_Keywords
*/
read_cap_Keywords: function(service, node) {
var keywords = this.getChildValue(node);
if (keywords && keywords.toLowerCase() != "none") {
service.keywords = keywords.split(', ');
}
},
/**
* Method: read_cap_Capability
*/
read_cap_Capability: function(capabilities, node) {
var capability = {};
this.runChildNodes(capability, node);
capabilities.capability = capability;
},
/**
* Method: read_cap_Request
*/
read_cap_Request: function(obj, node) {
var request = {};
this.runChildNodes(request, node);
obj.request = request;
},
/**
* Method: read_cap_GetFeature
*/
read_cap_GetFeature: function(request, node) {
var getfeature = {
href: {}, // DCPType
formats: [] // ResultFormat
};
this.runChildNodes(getfeature, node);
request.getfeature = getfeature;
},
/**
* Method: read_cap_ResultFormat
*/
read_cap_ResultFormat: function(obj, node) {
var children = node.childNodes;
var childNode;
for(var i=0; i<children.length; i++) {
childNode = children[i];
if(childNode.nodeType == 1) {
obj.formats.push(childNode.nodeName);
}
}
},
/**
* Method: read_cap_DCPType
*/
read_cap_DCPType: function(obj, node) {
this.runChildNodes(obj, node);
},
/**
* Method: read_cap_HTTP
*/
read_cap_HTTP: function(obj, node) {
this.runChildNodes(obj.href, node);
},
/**
* Method: read_cap_Get
*/
read_cap_Get: function(obj, node) {
obj.get = node.getAttribute("onlineResource");
},
/**
* Method: read_cap_Post
*/
read_cap_Post: function(obj, node) {
obj.post = node.getAttribute("onlineResource");
},
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_0_0"
});

View File

@@ -4,7 +4,7 @@
<script type="text/javascript">
function test_read(t) {
t.plan(11);
t.plan(28);
var parser = new OpenLayers.Format.WFSCapabilities();
@@ -26,6 +26,22 @@
t.eq(ft[0]["title"], "Manhattan (NY) landmarks", "title of first feature type correct");
t.eq(ft[0]["name"], "tiger:poly_landmarks", "name of first feature type correct");
var service = res.service;
t.eq(service.name, 'WFS', "service name correct");
t.eq(service.title, 'GeoServer Web Feature Service', "service title correct");
t.eq(service.abstract, 'This is the reference implementation of WFS 1.0.0 and WFS 1.1.0, supports all WFS operations including Transaction.', "service title correct");
t.eq(service.keywords[0], 'WFS', "service keyword [0] correct");
t.eq(service.keywords[2], 'GEOSERVER', "service keyword [2] correct");
t.eq(service.onlineResource, 'http://localhost:80/geoserver/wfs', "service onlineresource correct");
t.ok(typeof service.fees == 'undefined', "service fees correct");
t.ok(typeof service.accessConstraints == 'undefined', "service accessconstraints correct");
t.eq(res.capability.request.getfeature.href.post, "http://localhost:80/geoserver/wfs?", "getfeature request post href correct");
t.eq(res.capability.request.getfeature.href.get, "http://localhost:80/geoserver/wfs?request=GetFeature", "getfeature request get href correct");
t.eq(res.capability.request.getfeature.formats[0], "GML2", "getfeature response format [0] correct");
t.eq(res.capability.request.getfeature.formats[4], "GML3", "getfeature response format [4] correct");
// UMN Mapserer, v1.0.0
text =
'<?xml version="1.0" encoding="ISO-8859-1" ?>' +
@@ -119,6 +135,13 @@
t.eq(ft.length, 2, "number of feature types correct");
t.eq(ft[0]["title"], "Parks", "title of first feature type correct");
t.eq(ft[0]["name"], "park", "name of first feature type correct");
var service = res.service;
t.eq(service.name, 'MapServer WFS', "service name correct");
t.eq(service.title, 'GMap WMS Demo Server', "service title correct");
t.eq(service.onlineResource, 'http://127.0.0.1/cgi-bin/mapserv_40?map=/msroot/apache/htdocs/gmap/htdocs/gmap75_wfs.map&service=WFS&', "service onlineresource correct");
t.eq(res.capability.request.getfeature.href.get, "http://127.0.0.1/cgi-bin/mapserv_40?map=/msroot/apache/htdocs/gmap/htdocs/gmap75_wfs.map&service=WFS&", "getfeature request get href correct");
t.eq(res.capability.request.getfeature.formats[0], "GML2", "getfeature response format [0] correct");
}
</script>