rewrite WFSCapabilities parser to the new readers structure, and use OWSCommon readers. This will mean that the return structure will differ for WFS 1.0 and WFS 1.1, but I think it's better to adhere to OWSCommon structures here since this will allow similar structures over different OGC Web Services

This commit is contained in:
Bart van den Eijnden
2012-02-10 10:12:55 +01:00
parent 707e6406d9
commit 6bbcb20fac
5 changed files with 178 additions and 260 deletions

View File

@@ -15,7 +15,23 @@
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.WFSCapabilities.v1 = OpenLayers.Class(
OpenLayers.Format.WFSCapabilities, {
OpenLayers.Format.XML, {
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
wfs: "http://www.opengis.net/wfs",
xlink: "http://www.w3.org/1999/xlink",
xsi: "http://www.w3.org/2001/XMLSchema-instance",
ows: "http://www.opengis.net/ows"
},
/**
* Property: defaultPrefix
*/
defaultPrefix: "wfs",
/**
* Constructor: OpenLayers.Format.WFSCapabilities.v1_1
@@ -25,10 +41,6 @@ OpenLayers.Format.WFSCapabilities.v1 = OpenLayers.Class(
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
this.options = options;
},
/**
* APIMethod: read
@@ -44,83 +56,64 @@ OpenLayers.Format.WFSCapabilities.v1 = OpenLayers.Class(
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
var raw = data;
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var capabilities = {};
var root = data.documentElement;
this.runChildNodes(capabilities, root);
this.readNode(data, capabilities);
return capabilities;
},
/**
* Method: runChildNodes
* 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.
*/
runChildNodes: function(obj, node) {
var children = node.childNodes;
var childNode, processor;
for(var i=0; i<children.length; ++i) {
childNode = children[i];
if(childNode.nodeType == 1) {
processor = this["read_cap_" + childNode.nodeName.replace(":", "_")];
if(processor) {
processor.apply(this, [obj, childNode]);
readers: {
"wfs": {
"WFS_Capabilities": function(node, obj) {
this.readChildNodes(node, obj);
},
"FeatureTypeList": function(node, request) {
request.featureTypeList = {
featureTypes: []
};
this.readChildNodes(node, request.featureTypeList);
},
"FeatureType": function(node, featureTypeList) {
var featureType = {};
this.readChildNodes(node, featureType);
featureTypeList.featureTypes.push(featureType);
},
"Name": function(node, obj) {
var name = this.getChildValue(node);
if(name) {
var parts = name.split(":");
obj.name = parts.pop();
if(parts.length > 0) {
obj.featureNS = this.lookupNamespaceURI(node, parts[0]);
}
}
},
"Title": function(node, obj) {
var title = this.getChildValue(node);
if(title) {
obj.title = title;
}
},
"Abstract": function(node, obj) {
var abst = this.getChildValue(node);
if(abst) {
obj["abstract"] = abst;
}
}
}
},
/**
* Method: read_cap_FeatureTypeList
*/
read_cap_FeatureTypeList: function(request, node) {
var featureTypeList = {
featureTypes: []
};
this.runChildNodes(featureTypeList, node);
request.featureTypeList = featureTypeList;
},
/**
* Method: read_cap_FeatureType
*/
read_cap_FeatureType: function(featureTypeList, node, parentLayer) {
var featureType = {};
this.runChildNodes(featureType, node);
featureTypeList.featureTypes.push(featureType);
},
/**
* Method: read_cap_Name
*/
read_cap_Name: function(obj, node) {
var name = this.getChildValue(node);
if(name) {
var parts = name.split(":");
obj.name = parts.pop();
if(parts.length > 0) {
obj.featureNS = this.lookupNamespaceURI(node, parts[0]);
}
}
},
/**
* Method: read_cap_Title
*/
read_cap_Title: function(obj, node) {
var title = this.getChildValue(node);
if(title) {
obj.title = title;
}
},
/**
* Method: read_cap_Abstract
*/
read_cap_Abstract: function(obj, node) {
var abst = this.getChildValue(node);
if(abst) {
obj["abstract"] = abst;
}
},
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1"
});