adding a format to parsing OGC service exceptions (WMS 1.1 WMS 1.3 WFS 1.0 and OWSCommon 1.0 and 1.1) and hooking it up into the GetCapabilities parsers, r=tschaub (closes #2234)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@12074 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
110
lib/OpenLayers/Format/OGCExceptionReport.js
Normal file
110
lib/OpenLayers/Format/OGCExceptionReport.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
|
||||
* full list of contributors). 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
|
||||
* @requires OpenLayers/Format/OWSCommon/v1_0_0.js
|
||||
* @requires OpenLayers/Format/OWSCommon/v1_1_0.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.OGCExceptionReport
|
||||
* Class to read exception reports for various OGC services and versions.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
*/
|
||||
OpenLayers.Format.OGCExceptionReport = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
|
||||
/**
|
||||
* Property: namespaces
|
||||
* {Object} Mapping of namespace aliases to namespace URIs.
|
||||
*/
|
||||
namespaces: {
|
||||
ogc: "http://www.opengis.net/ogc"
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: regExes
|
||||
* Compiled regular expressions for manipulating strings.
|
||||
*/
|
||||
regExes: {
|
||||
trimSpace: (/^\s*|\s*$/g),
|
||||
removeSpace: (/\s*/g),
|
||||
splitSpace: (/\s+/),
|
||||
trimComma: (/\s*,\s*/g)
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: defaultPrefix
|
||||
*/
|
||||
defaultPrefix: "ogc",
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.OGCExceptionReport
|
||||
* Create a new parser for OGC exception reports.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
|
||||
/**
|
||||
* APIMethod: read
|
||||
* Read OGC exception report data from a string, and return an object with
|
||||
* information about the exceptions.
|
||||
*
|
||||
* Parameters:
|
||||
* data - {String} or {DOMElement} data to read/parse.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} Information about the exceptions that occurred.
|
||||
*/
|
||||
read: function(data) {
|
||||
var result;
|
||||
if(typeof data == "string") {
|
||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||
}
|
||||
var root = data.documentElement;
|
||||
var exceptionInfo = {exceptionReport: null};
|
||||
if (root) {
|
||||
this.readChildNodes(data, exceptionInfo);
|
||||
if (exceptionInfo.exceptionReport === null) {
|
||||
// fall-back to OWSCommon since this is a common output format for exceptions
|
||||
// we cannot easily use the ows readers directly since they differ for 1.0 and 1.1
|
||||
exceptionInfo = new OpenLayers.Format.OWSCommon().read(data);
|
||||
}
|
||||
}
|
||||
return exceptionInfo;
|
||||
},
|
||||
|
||||
/**
|
||||
* 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: {
|
||||
"ogc": {
|
||||
"ServiceExceptionReport": function(node, obj) {
|
||||
obj.exceptionReport = {exceptions: []};
|
||||
this.readChildNodes(node, obj.exceptionReport);
|
||||
},
|
||||
"ServiceException": function(node, exceptionReport) {
|
||||
var exception = {
|
||||
code: node.getAttribute("code"),
|
||||
locator: node.getAttribute("locator"),
|
||||
text: this.getChildValue(node)
|
||||
};
|
||||
exceptionReport.exceptions.push(exception);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.OGCExceptionReport"
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user