adding parser for Sensor Observation Service (SOS) GetCapabilities interface, r=ahocevar (closes #2337)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9897 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2009-12-16 14:25:08 +00:00
parent f5ff990898
commit b948eb163b
7 changed files with 993 additions and 0 deletions

View File

@@ -0,0 +1,187 @@
/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/XML.js
*/
OpenLayers.Format.OWSCommon = {};
/**
* Class: OpenLayers.Format.OWSCommon.v1_1_0
* Parser for OWS Common version 1.1.0 which can be used by other parsers.
* It is not intended to be used on its own.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.OWSCommon.v1_1_0 = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
ows: "http://www.opengis.net/ows/1.1",
xlink: "http://www.w3.org/1999/xlink"
},
/**
* 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.
*/
readers: {
"ows": {
"ServiceIdentification": function(node, obj) {
obj.serviceIdentification = {};
this.readChildNodes(node, obj.serviceIdentification);
},
"Title": function(node, serviceIdentification) {
serviceIdentification.title = this.getChildValue(node);
},
"Abstract": function(node, serviceIdentification) {
serviceIdentification.abstract = this.getChildValue(node);
},
"Keywords": function(node, serviceIdentification) {
serviceIdentification.keywords = {};
this.readChildNodes(node, serviceIdentification.keywords);
},
"Keyword": function(node, keywords) {
keywords[this.getChildValue(node)] = true;
},
"ServiceType": function(node, serviceIdentification) {
serviceIdentification.serviceType = {
codeSpace: node.getAttribute('codeSpace'),
value: this.getChildValue(node)};
},
"ServiceTypeVersion": function(node, serviceIdentification) {
serviceIdentification.serviceTypeVersion = this.getChildValue(node);
},
"Fees": function(node, serviceIdentification) {
serviceIdentification.fees = this.getChildValue(node);
},
"AccessConstraints": function(node, serviceIdentification) {
serviceIdentification.accessConstraints =
this.getChildValue(node);
},
"ServiceProvider": function(node, obj) {
obj.serviceProvider = {};
this.readChildNodes(node, obj.serviceProvider);
},
"ProviderName": function(node, serviceProvider) {
serviceProvider.providerName = this.getChildValue(node);
},
"ProviderSite": function(node, serviceProvider) {
serviceProvider.providerSite = this.getAttributeNS(node,
this.namespaces.xlink, "href");
},
"ServiceContact": function(node, serviceProvider) {
serviceProvider.serviceContact = {};
this.readChildNodes(node, serviceProvider.serviceContact);
},
"IndividualName": function(node, serviceContact) {
serviceContact.individualName = this.getChildValue(node);
},
"PositionName": function(node, serviceContact) {
serviceContact.positionName = this.getChildValue(node);
},
"ContactInfo": function(node, serviceContact) {
serviceContact.contactInfo = {};
this.readChildNodes(node, serviceContact.contactInfo);
},
"Phone": function(node, contactInfo) {
contactInfo.phone = {};
this.readChildNodes(node, contactInfo.phone);
},
"Voice": function(node, phone) {
phone.voice = this.getChildValue(node);
},
"Address": function(node, contactInfo) {
contactInfo.address = {};
this.readChildNodes(node, contactInfo.address);
},
"DeliveryPoint": function(node, address) {
address.deliveryPoint = this.getChildValue(node);
},
"City": function(node, address) {
address.city = this.getChildValue(node);
},
"AdministrativeArea": function(node, address) {
address.administrativeArea = this.getChildValue(node);
},
"PostalCode": function(node, address) {
address.postalCode = this.getChildValue(node);
},
"Country": function(node, address) {
address.country = this.getChildValue(node);
},
"ElectronicMailAddress": function(node, address) {
address.electronicMailAddress = this.getChildValue(node);
},
"Role": function(node, serviceContact) {
serviceContact.role = this.getChildValue(node);
},
"OperationsMetadata": function(node, obj) {
obj.operationsMetadata = {};
this.readChildNodes(node, obj.operationsMetadata);
},
"Operation": function(node, operationsMetadata) {
var name = node.getAttribute("name");
operationsMetadata[name] = {};
this.readChildNodes(node, operationsMetadata[name]);
},
"DCP": function(node, operation) {
operation.dcp = {};
this.readChildNodes(node, operation.dcp);
},
"HTTP": function(node, dcp) {
dcp.http = {};
this.readChildNodes(node, dcp.http);
},
"Get": function(node, http) {
http.get = this.getAttributeNS(node,
this.namespaces.xlink, "href");
},
"Post": function(node, http) {
http.post = this.getAttributeNS(node,
this.namespaces.xlink, "href");
},
"Parameter": function(node, operation) {
if (!operation.parameters) {
operation.parameters = {};
}
var name = node.getAttribute("name");
operation.parameters[name] = {};
this.readChildNodes(node, operation.parameters[name]);
},
"AllowedValues": function(node, parameter) {
parameter.allowedValues = {};
this.readChildNodes(node, parameter.allowedValues);
},
"AnyValue": function(node, parameter) {
parameter.anyValue = true;
},
"Value": function(node, allowedValues) {
allowedValues[this.getChildValue(node)] = true;
},
"Range": function(node, allowedValues) {
allowedValues.range = {};
this.readChildNodes(node, allowedValues.range);
},
"MinimumValue": function(node, range) {
range.minValue = this.getChildValue(node);
},
"MaximumValue": function(node, range) {
range.maxValue = this.getChildValue(node);
}
}
},
CLASS_NAME: "OpenLayers.Format.OWSCommon.v1_1_0"
});

View File

@@ -0,0 +1,82 @@
/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/XML.js
*/
/**
* Class: OpenLayers.Format.SOSCapabilities
* Read SOS Capabilities.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.SOSCapabilities = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* APIProperty: defaultVersion
* {String} Version number to assume if none found. Default is "1.0.0".
*/
defaultVersion: "1.0.0",
/**
* APIProperty: version
* {String} Specify a version string if one is known.
*/
version: null,
/**
* Property: parser
* {<OpenLayers.Format>} A cached versioned format used for reading.
*/
parser: null,
/**
* Constructor: OpenLayers.Format.SOSCapabilities
* Create a new parser for SOS capabilities.
*
* Parameters:
* 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
* Read capabilities data from a string, and return information about
* the service (offering and observedProperty mostly).
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object} Info about the SOS
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
var root = data.documentElement;
var version = this.version || root.getAttribute("version") || this.defaultVersion;
if(!this.parser || this.parser.version !== version) {
var constr = OpenLayers.Format.SOSCapabilities[
"v" + version.replace(/\./g, "_")
];
if(!constr) {
throw "Can't find a SOS capabilities parser for version " + version;
}
var parser = new constr(this.options);
}
var capabilities = parser.read(data);
capabilities.version = version;
return capabilities;
},
CLASS_NAME: "OpenLayers.Format.SOSCapabilities"
});

View File

@@ -0,0 +1,156 @@
/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/SOSCapabilities.js
* @requires OpenLayers/Format/OWSCommon/v1_1_0.js
* @requires OpenLayers/Format/GML/v3.js
*/
/**
* Class: OpenLayers.Format.SOSCapabilities.v1_0_0
* Read SOS Capabilities version 1.0.0.
*
* Inherits from:
* - <OpenLayers.Format.SOSCapabilities>
*/
OpenLayers.Format.SOSCapabilities.v1_0_0 = OpenLayers.Class(
OpenLayers.Format.SOSCapabilities, {
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
ows: "http://www.opengis.net/ows/1.1",
sos: "http://www.opengis.net/sos/1.0",
gml: "http://www.opengis.net/gml",
xlink: "http://www.w3.org/1999/xlink"
},
/**
* 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.SOSCapabilities.v1_0_0
* Create a new parser for SOS capabilities version 1.0.0.
*
* Parameters:
* 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
* Read capabilities data from a string, and return info about the SOS.
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object} Information about the SOS service.
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var capabilities = {};
this.readNode(data, capabilities);
return capabilities;
},
/**
* 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.
*/
readers: {
"gml": OpenLayers.Util.applyDefaults({
"name": function(node, obj) {
obj.name = this.getChildValue(node);
},
"TimePeriod": function(node, obj) {
obj.timePeriod = {};
this.readChildNodes(node, obj.timePeriod);
},
"beginPosition": function(node, timePeriod) {
timePeriod.beginPosition = this.getChildValue(node);
},
"endPosition": function(node, timePeriod) {
timePeriod.endPosition = this.getChildValue(node);
}
}, OpenLayers.Format.GML.v3.prototype.readers["gml"]),
"sos": {
"Capabilities": function(node, obj) {
this.readChildNodes(node, obj);
},
"Contents": function(node, obj) {
obj.contents = {};
this.readChildNodes(node, obj.contents);
},
"ObservationOfferingList": function(node, contents) {
contents.offeringList = {};
this.readChildNodes(node, contents.offeringList);
},
"ObservationOffering": function(node, offeringList) {
var id = this.getAttributeNS(node, this.namespaces.gml, "id");
offeringList[id] = {
procedures: [],
featureOfInterestIds: [],
responseFormats: [],
resultModels: [],
responseModes: []
};
this.readChildNodes(node, offeringList[id]);
},
"time": function(node, offering) {
offering.time = {};
this.readChildNodes(node, offering.time);
},
"procedure": function(node, offering) {
offering.procedures.push(this.getAttributeNS(node,
this.namespaces.xlink, "href"));
},
"observedProperty": function(node, offering) {
offering.observedProperty = this.getAttributeNS(node,
this.namespaces.xlink, "href");
},
"featureOfInterest": function(node, offering) {
offering.featureOfInterestIds.push(this.getAttributeNS(node,
this.namespaces.xlink, "href"));
},
"responseFormat": function(node, offering) {
offering.responseFormats.push(this.getChildValue(node));
},
"resultModel": function(node, offering) {
offering.resultModels.push(this.getChildValue(node));
},
"responseMode": function(node, offering) {
offering.responseModes.push(this.getChildValue(node));;
}
},
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
},
CLASS_NAME: "OpenLayers.Format.SOSCapabilities.v1_0_0"
});