1
|
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
|
2
|
* full list of contributors). Published under the 2-clause BSD license.
|
3
|
* See license.txt in the OpenLayers distribution or repository for the
|
4
|
* full text of the license. */
|
5
|
|
6
|
/**
|
7
|
* @requires OpenLayers/Format/XML.js
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Class: OpenLayers.Format.OGCExceptionReport
|
12
|
* Class to read exception reports for various OGC services and versions.
|
13
|
*
|
14
|
* Inherits from:
|
15
|
* - <OpenLayers.Format.XML>
|
16
|
*/
|
17
|
OpenLayers.Format.OGCExceptionReport = OpenLayers.Class(OpenLayers.Format.XML, {
|
18
|
|
19
|
/**
|
20
|
* Property: namespaces
|
21
|
* {Object} Mapping of namespace aliases to namespace URIs.
|
22
|
*/
|
23
|
namespaces: {
|
24
|
ogc: "http://www.opengis.net/ogc"
|
25
|
},
|
26
|
|
27
|
/**
|
28
|
* Property: regExes
|
29
|
* Compiled regular expressions for manipulating strings.
|
30
|
*/
|
31
|
regExes: {
|
32
|
trimSpace: (/^\s*|\s*$/g),
|
33
|
removeSpace: (/\s*/g),
|
34
|
splitSpace: (/\s+/),
|
35
|
trimComma: (/\s*,\s*/g)
|
36
|
},
|
37
|
|
38
|
/**
|
39
|
* Property: defaultPrefix
|
40
|
*/
|
41
|
defaultPrefix: "ogc",
|
42
|
|
43
|
/**
|
44
|
* Constructor: OpenLayers.Format.OGCExceptionReport
|
45
|
* Create a new parser for OGC exception reports.
|
46
|
*
|
47
|
* Parameters:
|
48
|
* options - {Object} An optional object whose properties will be set on
|
49
|
* this instance.
|
50
|
*/
|
51
|
|
52
|
/**
|
53
|
* APIMethod: read
|
54
|
* Read OGC exception report data from a string, and return an object with
|
55
|
* information about the exceptions.
|
56
|
*
|
57
|
* Parameters:
|
58
|
* data - {String} or {DOMElement} data to read/parse.
|
59
|
*
|
60
|
* Returns:
|
61
|
* {Object} Information about the exceptions that occurred.
|
62
|
*/
|
63
|
read: function(data) {
|
64
|
var result;
|
65
|
if(typeof data == "string") {
|
66
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
67
|
}
|
68
|
var root = data.documentElement;
|
69
|
var exceptionInfo = {exceptionReport: null};
|
70
|
if (root) {
|
71
|
this.readChildNodes(data, exceptionInfo);
|
72
|
if (exceptionInfo.exceptionReport === null) {
|
73
|
// fall-back to OWSCommon since this is a common output format for exceptions
|
74
|
// we cannot easily use the ows readers directly since they differ for 1.0 and 1.1
|
75
|
exceptionInfo = new OpenLayers.Format.OWSCommon().read(data);
|
76
|
}
|
77
|
}
|
78
|
return exceptionInfo;
|
79
|
},
|
80
|
|
81
|
/**
|
82
|
* Property: readers
|
83
|
* Contains public functions, grouped by namespace prefix, that will
|
84
|
* be applied when a namespaced node is found matching the function
|
85
|
* name. The function will be applied in the scope of this parser
|
86
|
* with two arguments: the node being read and a context object passed
|
87
|
* from the parent.
|
88
|
*/
|
89
|
readers: {
|
90
|
"ogc": {
|
91
|
"ServiceExceptionReport": function(node, obj) {
|
92
|
obj.exceptionReport = {exceptions: []};
|
93
|
this.readChildNodes(node, obj.exceptionReport);
|
94
|
},
|
95
|
"ServiceException": function(node, exceptionReport) {
|
96
|
var exception = {
|
97
|
code: node.getAttribute("code"),
|
98
|
locator: node.getAttribute("locator"),
|
99
|
text: this.getChildValue(node)
|
100
|
};
|
101
|
exceptionReport.exceptions.push(exception);
|
102
|
}
|
103
|
}
|
104
|
},
|
105
|
|
106
|
CLASS_NAME: "OpenLayers.Format.OGCExceptionReport"
|
107
|
|
108
|
});
|