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
+4 -4
View File
@@ -269,6 +269,10 @@
"OpenLayers/Format/KML.js", "OpenLayers/Format/KML.js",
"OpenLayers/Format/GeoRSS.js", "OpenLayers/Format/GeoRSS.js",
"OpenLayers/Format/WFS.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.js",
"OpenLayers/Format/WFSCapabilities/v1.js", "OpenLayers/Format/WFSCapabilities/v1.js",
"OpenLayers/Format/WFSCapabilities/v1_0_0.js", "OpenLayers/Format/WFSCapabilities/v1_0_0.js",
@@ -287,10 +291,6 @@
"OpenLayers/Format/SLD.js", "OpenLayers/Format/SLD.js",
"OpenLayers/Format/SLD/v1.js", "OpenLayers/Format/SLD/v1.js",
"OpenLayers/Format/SLD/v1_0_0.js", "OpenLayers/Format/SLD/v1_0_0.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/CSWGetDomain.js", "OpenLayers/Format/CSWGetDomain.js",
"OpenLayers/Format/CSWGetDomain/v2_0_2.js", "OpenLayers/Format/CSWGetDomain/v2_0_2.js",
"OpenLayers/Format/CSWGetRecords.js", "OpenLayers/Format/CSWGetRecords.js",
+42 -49
View File
@@ -15,7 +15,23 @@
* - <OpenLayers.Format.XML> * - <OpenLayers.Format.XML>
*/ */
OpenLayers.Format.WFSCapabilities.v1 = OpenLayers.Class( 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 * 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 * options - {Object} An optional object whose properties will be set on
* this instance. * this instance.
*/ */
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
this.options = options;
},
/** /**
* APIMethod: read * APIMethod: read
@@ -44,53 +56,40 @@ OpenLayers.Format.WFSCapabilities.v1 = OpenLayers.Class(
if(typeof data == "string") { if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
} }
var raw = data;
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var capabilities = {}; var capabilities = {};
var root = data.documentElement; this.readNode(data, capabilities);
this.runChildNodes(capabilities, root);
return 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) { readers: {
var children = node.childNodes; "wfs": {
var childNode, processor; "WFS_Capabilities": function(node, obj) {
for(var i=0; i<children.length; ++i) { this.readChildNodes(node, obj);
childNode = children[i];
if(childNode.nodeType == 1) {
processor = this["read_cap_" + childNode.nodeName.replace(":", "_")];
if(processor) {
processor.apply(this, [obj, childNode]);
}
}
}
}, },
"FeatureTypeList": function(node, request) {
/** request.featureTypeList = {
* Method: read_cap_FeatureTypeList
*/
read_cap_FeatureTypeList: function(request, node) {
var featureTypeList = {
featureTypes: [] featureTypes: []
}; };
this.runChildNodes(featureTypeList, node); this.readChildNodes(node, request.featureTypeList);
request.featureTypeList = featureTypeList;
}, },
"FeatureType": function(node, featureTypeList) {
/**
* Method: read_cap_FeatureType
*/
read_cap_FeatureType: function(featureTypeList, node, parentLayer) {
var featureType = {}; var featureType = {};
this.runChildNodes(featureType, node); this.readChildNodes(node, featureType);
featureTypeList.featureTypes.push(featureType); featureTypeList.featureTypes.push(featureType);
}, },
"Name": function(node, obj) {
/**
* Method: read_cap_Name
*/
read_cap_Name: function(obj, node) {
var name = this.getChildValue(node); var name = this.getChildValue(node);
if(name) { if(name) {
var parts = name.split(":"); var parts = name.split(":");
@@ -100,25 +99,19 @@ OpenLayers.Format.WFSCapabilities.v1 = OpenLayers.Class(
} }
} }
}, },
"Title": function(node, obj) {
/**
* Method: read_cap_Title
*/
read_cap_Title: function(obj, node) {
var title = this.getChildValue(node); var title = this.getChildValue(node);
if(title) { if(title) {
obj.title = title; obj.title = title;
} }
}, },
"Abstract": function(node, obj) {
/**
* Method: read_cap_Abstract
*/
read_cap_Abstract: function(obj, node) {
var abst = this.getChildValue(node); var abst = this.getChildValue(node);
if(abst) { if(abst) {
obj["abstract"] = abst; obj["abstract"] = abst;
} }
}
}
}, },
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1" CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1"
+34 -81
View File
@@ -27,88 +27,59 @@ OpenLayers.Format.WFSCapabilities.v1_0_0 = OpenLayers.Class(
*/ */
/** /**
* Method: read_cap_Service * 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_Service: function(capabilities, node) { readers: {
var service = {}; "wfs": OpenLayers.Util.applyDefaults({
this.runChildNodes(service, node); "Service": function(node, capabilities) {
capabilities.service = service; capabilities.service = {};
this.readChildNodes(node, capabilities.service);
}, },
"Fees": function(node, service) {
/**
* Method: read_cap_Fees
*/
read_cap_Fees: function(service, node) {
var fees = this.getChildValue(node); var fees = this.getChildValue(node);
if (fees && fees.toLowerCase() != "none") { if (fees && fees.toLowerCase() != "none") {
service.fees = fees; service.fees = fees;
} }
}, },
"AccessConstraints": function(node, service) {
/**
* Method: read_cap_AccessConstraints
*/
read_cap_AccessConstraints: function(service, node) {
var constraints = this.getChildValue(node); var constraints = this.getChildValue(node);
if (constraints && constraints.toLowerCase() != "none") { if (constraints && constraints.toLowerCase() != "none") {
service.accessConstraints = constraints; service.accessConstraints = constraints;
} }
}, },
"OnlineResource": function(node, service) {
/**
* Method: read_cap_OnlineResource
*/
read_cap_OnlineResource: function(service, node) {
var onlineResource = this.getChildValue(node); var onlineResource = this.getChildValue(node);
if (onlineResource && onlineResource.toLowerCase() != "none") { if (onlineResource && onlineResource.toLowerCase() != "none") {
service.onlineResource = onlineResource; service.onlineResource = onlineResource;
} }
}, },
"Keywords": function(node, service) {
/**
* Method: read_cap_Keywords
*/
read_cap_Keywords: function(service, node) {
var keywords = this.getChildValue(node); var keywords = this.getChildValue(node);
if (keywords && keywords.toLowerCase() != "none") { if (keywords && keywords.toLowerCase() != "none") {
service.keywords = keywords.split(', '); service.keywords = keywords.split(', ');
} }
}, },
"Capability": function(node, capabilities) {
/** capabilities.capability = {};
* Method: read_cap_Capability this.readChildNodes(node, capabilities.capability);
*/
read_cap_Capability: function(capabilities, node) {
var capability = {};
this.runChildNodes(capability, node);
capabilities.capability = capability;
}, },
"Request": function(node, obj) {
/** obj.request = {};
* Method: read_cap_Request this.readChildNodes(node, obj.request);
*/
read_cap_Request: function(obj, node) {
var request = {};
this.runChildNodes(request, node);
obj.request = request;
}, },
"GetFeature": function(node, request) {
/** request.getfeature = {
* Method: read_cap_GetFeature
*/
read_cap_GetFeature: function(request, node) {
var getfeature = {
href: {}, // DCPType href: {}, // DCPType
formats: [] // ResultFormat formats: [] // ResultFormat
}; };
this.runChildNodes(getfeature, node); this.readChildNodes(node, request.getfeature);
request.getfeature = getfeature;
}, },
"ResultFormat": function(node, obj) {
/**
* Method: read_cap_ResultFormat
*/
read_cap_ResultFormat: function(obj, node) {
var children = node.childNodes; var children = node.childNodes;
var childNode; var childNode;
for(var i=0; i<children.length; i++) { for(var i=0; i<children.length; i++) {
@@ -118,43 +89,25 @@ OpenLayers.Format.WFSCapabilities.v1_0_0 = OpenLayers.Class(
} }
} }
}, },
"DCPType": function(node, obj) {
/** this.readChildNodes(node, obj);
* Method: read_cap_DCPType
*/
read_cap_DCPType: function(obj, node) {
this.runChildNodes(obj, node);
}, },
"HTTP": function(node, obj) {
/** this.readChildNodes(node, obj.href);
* Method: read_cap_HTTP
*/
read_cap_HTTP: function(obj, node) {
this.runChildNodes(obj.href, node);
}, },
"Get": function(node, obj) {
/**
* Method: read_cap_Get
*/
read_cap_Get: function(obj, node) {
obj.get = node.getAttribute("onlineResource"); obj.get = node.getAttribute("onlineResource");
}, },
"Post": function(node, obj) {
/**
* Method: read_cap_Post
*/
read_cap_Post: function(obj, node) {
obj.post = node.getAttribute("onlineResource"); obj.post = node.getAttribute("onlineResource");
}, },
"SRS": function(node, obj) {
/**
* Method: read_cap_SRS
*/
read_cap_SRS: function(obj, node) {
var srs = this.getChildValue(node); var srs = this.getChildValue(node);
if (srs) { if (srs) {
obj.srs = srs; obj.srs = srs;
} }
}
}, OpenLayers.Format.WFSCapabilities.v1.prototype.readers["wfs"])
}, },
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_0_0" CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_0_0"
+24 -52
View File
@@ -5,6 +5,7 @@
/** /**
* @requires OpenLayers/Format/WFSCapabilities/v1.js * @requires OpenLayers/Format/WFSCapabilities/v1.js
* @requires OpenLayers/Format/OWSCommon/v1.js
*/ */
/** /**
@@ -17,6 +18,17 @@
OpenLayers.Format.WFSCapabilities.v1_1_0 = OpenLayers.Class( OpenLayers.Format.WFSCapabilities.v1_1_0 = OpenLayers.Class(
OpenLayers.Format.WFSCapabilities.v1, { 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 * Constructor: OpenLayers.Format.WFSCapabilities.v1_1_0
* Create a new parser for WFS capabilities version 1.1.0. * Create a new parser for WFS capabilities version 1.1.0.
@@ -27,63 +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) { readers: {
"wfs": OpenLayers.Util.applyDefaults({
"DefaultSRS": function(node, obj) {
var defaultSRS = this.getChildValue(node); var defaultSRS = this.getChildValue(node);
if (defaultSRS) { if (defaultSRS) {
obj.srs = defaultSRS; obj.srs = defaultSRS;
} }
}, }
}, OpenLayers.Format.WFSCapabilities.v1.prototype.readers["wfs"]),
/** "ows": OpenLayers.Format.OWSCommon.v1.prototype.readers.ows
* Method: read_cap_ows_OperationsMetadata
*/
read_cap_ows_OperationsMetadata: function(capabilities, node) {
var capability = {
request: {}
};
this.runChildNodes(capability.request, node);
capabilities.capability = capability;
},
/**
* Method: read_cap_ows_Operation
*/
read_cap_ows_Operation: function(request, node) {
var operation = {
href: {}
};
this.runChildNodes(operation.href, node);
request[node.getAttribute("name").toLowerCase()] = operation;
},
/**
* Method: read_cap_ows_DCP
*/
read_cap_ows_DCP: function(href, node) {
this.runChildNodes(href, node);
},
/**
* Method: read_cap_ows_HTTP
*/
read_cap_ows_HTTP: function(href, node) {
this.runChildNodes(href, node);
},
/**
* Method: read_cap_ows_Get
*/
read_cap_ows_Get: function(href, node) {
href["get"] = node.getAttribute("xlink:href");
},
/**
* Method: read_cap_ows_Post
*/
read_cap_ows_Post: function(href, node) {
href["post"] = node.getAttribute("xlink:href");
}, },
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_1_0" CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_1_0"
File diff suppressed because one or more lines are too long