Merge pull request #208 from bartvde/wfs11

implement readers for URL endpoints in WFS 1.1, this meant restructuring the WFS Capabilities format to use the new readers and writers structures (r=@ahocevar)
This commit is contained in:
Bart van den Eijnden
2012-02-28 04:32:59 -08:00
5 changed files with 179 additions and 205 deletions

View File

@@ -269,6 +269,10 @@
"OpenLayers/Format/KML.js",
"OpenLayers/Format/GeoRSS.js",
"OpenLayers/Format/WFS.js",
"OpenLayers/Format/OWSCommon.js",
"OpenLayers/Format/OWSCommon/v1.js",
"OpenLayers/Format/OWSCommon/v1_0_0.js",
"OpenLayers/Format/OWSCommon/v1_1_0.js",
"OpenLayers/Format/WFSCapabilities.js",
"OpenLayers/Format/WFSCapabilities/v1.js",
"OpenLayers/Format/WFSCapabilities/v1_0_0.js",

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];
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"
});

View File

@@ -25,136 +25,89 @@ OpenLayers.Format.WFSCapabilities.v1_0_0 = OpenLayers.Class(
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
/**
* Method: read_cap_Service
*/
read_cap_Service: function(capabilities, node) {
var service = {};
this.runChildNodes(service, node);
capabilities.service = service;
},
/**
* Method: read_cap_Fees
* 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.
*/
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);
readers: {
"wfs": OpenLayers.Util.applyDefaults({
"Service": function(node, capabilities) {
capabilities.service = {};
this.readChildNodes(node, capabilities.service);
},
"Fees": function(node, service) {
var fees = this.getChildValue(node);
if (fees && fees.toLowerCase() != "none") {
service.fees = fees;
}
},
"AccessConstraints": function(node, service) {
var constraints = this.getChildValue(node);
if (constraints && constraints.toLowerCase() != "none") {
service.accessConstraints = constraints;
}
},
"OnlineResource": function(node, service) {
var onlineResource = this.getChildValue(node);
if (onlineResource && onlineResource.toLowerCase() != "none") {
service.onlineResource = onlineResource;
}
},
"Keywords": function(node, service) {
var keywords = this.getChildValue(node);
if (keywords && keywords.toLowerCase() != "none") {
service.keywords = keywords.split(', ');
}
},
"Capability": function(node, capabilities) {
capabilities.capability = {};
this.readChildNodes(node, capabilities.capability);
},
"Request": function(node, obj) {
obj.request = {};
this.readChildNodes(node, obj.request);
},
"GetFeature": function(node, request) {
request.getfeature = {
href: {}, // DCPType
formats: [] // ResultFormat
};
this.readChildNodes(node, request.getfeature);
},
"ResultFormat": function(node, obj) {
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);
}
}
},
"DCPType": function(node, obj) {
this.readChildNodes(node, obj);
},
"HTTP": function(node, obj) {
this.readChildNodes(node, obj.href);
},
"Get": function(node, obj) {
obj.get = node.getAttribute("onlineResource");
},
"Post": function(node, obj) {
obj.post = node.getAttribute("onlineResource");
},
"SRS": function(node, obj) {
var srs = this.getChildValue(node);
if (srs) {
obj.srs = srs;
}
}
}
},
/**
* 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");
},
/**
* Method: read_cap_SRS
*/
read_cap_SRS: function(obj, node) {
var srs = this.getChildValue(node);
if (srs) {
obj.srs = srs;
}
}, OpenLayers.Format.WFSCapabilities.v1.prototype.readers["wfs"])
},
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_0_0"

View File

@@ -5,6 +5,7 @@
/**
* @requires OpenLayers/Format/WFSCapabilities/v1.js
* @requires OpenLayers/Format/OWSCommon/v1.js
*/
/**
@@ -16,6 +17,17 @@
*/
OpenLayers.Format.WFSCapabilities.v1_1_0 = OpenLayers.Class(
OpenLayers.Format.WFSCapabilities.v1, {
/**
* Property: regExes
* Compiled regular expressions for manipulating strings.
*/
regExes: {
trimSpace: (/^\s*|\s*$/g),
removeSpace: (/\s*/g),
splitSpace: (/\s+/),
trimComma: (/\s*,\s*/g)
},
/**
* Constructor: OpenLayers.Format.WFSCapabilities.v1_1_0
@@ -27,13 +39,23 @@ OpenLayers.Format.WFSCapabilities.v1_1_0 = OpenLayers.Class(
*/
/**
* Method: read_cap_DefaultSRS
* 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.
*/
read_cap_DefaultSRS: function(obj, node) {
var defaultSRS = this.getChildValue(node);
if (defaultSRS) {
obj.srs = defaultSRS;
}
readers: {
"wfs": OpenLayers.Util.applyDefaults({
"DefaultSRS": function(node, obj) {
var defaultSRS = this.getChildValue(node);
if (defaultSRS) {
obj.srs = defaultSRS;
}
}
}, OpenLayers.Format.WFSCapabilities.v1.prototype.readers["wfs"]),
"ows": OpenLayers.Format.OWSCommon.v1.prototype.readers.ows
},
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_1_0"

File diff suppressed because one or more lines are too long