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",
+65 -72
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,83 +56,64 @@ 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) { "FeatureTypeList": function(node, request) {
processor = this["read_cap_" + childNode.nodeName.replace(":", "_")]; request.featureTypeList = {
if(processor) { featureTypes: []
processor.apply(this, [obj, childNode]); };
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" CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1"
}); });
+79 -126
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 * options - {Object} An optional object whose properties will be set on
* this instance. * 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) { readers: {
var fees = this.getChildValue(node); "wfs": OpenLayers.Util.applyDefaults({
if (fees && fees.toLowerCase() != "none") { "Service": function(node, capabilities) {
service.fees = fees; capabilities.service = {};
} this.readChildNodes(node, capabilities.service);
}, },
"Fees": function(node, service) {
/** var fees = this.getChildValue(node);
* Method: read_cap_AccessConstraints if (fees && fees.toLowerCase() != "none") {
*/ service.fees = fees;
read_cap_AccessConstraints: function(service, node) { }
var constraints = this.getChildValue(node); },
if (constraints && constraints.toLowerCase() != "none") { "AccessConstraints": function(node, service) {
service.accessConstraints = constraints; var constraints = this.getChildValue(node);
} if (constraints && constraints.toLowerCase() != "none") {
}, service.accessConstraints = constraints;
}
/** },
* Method: read_cap_OnlineResource "OnlineResource": function(node, service) {
*/ var onlineResource = this.getChildValue(node);
read_cap_OnlineResource: function(service, node) { if (onlineResource && onlineResource.toLowerCase() != "none") {
var onlineResource = this.getChildValue(node); service.onlineResource = onlineResource;
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(', ');
* Method: read_cap_Keywords }
*/ },
read_cap_Keywords: function(service, node) { "Capability": function(node, capabilities) {
var keywords = this.getChildValue(node); capabilities.capability = {};
if (keywords && keywords.toLowerCase() != "none") { this.readChildNodes(node, capabilities.capability);
service.keywords = keywords.split(', '); },
} "Request": function(node, obj) {
}, obj.request = {};
this.readChildNodes(node, obj.request);
/** },
* Method: read_cap_Capability "GetFeature": function(node, request) {
*/ request.getfeature = {
read_cap_Capability: function(capabilities, node) { href: {}, // DCPType
var capability = {}; formats: [] // ResultFormat
this.runChildNodes(capability, node); };
capabilities.capability = capability; this.readChildNodes(node, request.getfeature);
}, },
"ResultFormat": function(node, obj) {
/** var children = node.childNodes;
* Method: read_cap_Request var childNode;
*/ for(var i=0; i<children.length; i++) {
read_cap_Request: function(obj, node) { childNode = children[i];
var request = {}; if(childNode.nodeType == 1) {
this.runChildNodes(request, node); obj.formats.push(childNode.nodeName);
obj.request = request; }
}, }
},
/** "DCPType": function(node, obj) {
* Method: read_cap_GetFeature this.readChildNodes(node, obj);
*/ },
read_cap_GetFeature: function(request, node) { "HTTP": function(node, obj) {
var getfeature = { this.readChildNodes(node, obj.href);
href: {}, // DCPType },
formats: [] // ResultFormat "Get": function(node, obj) {
}; obj.get = node.getAttribute("onlineResource");
this.runChildNodes(getfeature, node); },
request.getfeature = getfeature; "Post": function(node, obj) {
}, obj.post = node.getAttribute("onlineResource");
},
/** "SRS": function(node, obj) {
* Method: read_cap_ResultFormat var srs = this.getChildValue(node);
*/ if (srs) {
read_cap_ResultFormat: function(obj, node) { obj.srs = srs;
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);
} }
} }, OpenLayers.Format.WFSCapabilities.v1.prototype.readers["wfs"])
},
/**
* 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;
}
}, },
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_0_0" CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_0_0"
+28 -56
View File
@@ -5,6 +5,7 @@
/** /**
* @requires OpenLayers/Format/WFSCapabilities/v1.js * @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_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
@@ -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: {
var defaultSRS = this.getChildValue(node); "wfs": OpenLayers.Util.applyDefaults({
if (defaultSRS) { "DefaultSRS": function(node, obj) {
obj.srs = defaultSRS; var defaultSRS = this.getChildValue(node);
} if (defaultSRS) {
}, obj.srs = defaultSRS;
}
/** }
* Method: read_cap_ows_OperationsMetadata }, OpenLayers.Format.WFSCapabilities.v1.prototype.readers["wfs"]),
*/ "ows": OpenLayers.Format.OWSCommon.v1.prototype.readers.ows
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