[OpenLayers-Commits] r12060 - in
sandbox/bartvde/exception/openlayers: lib
lib/OpenLayers/Format tests tests/Format
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Tue Jun 7 15:45:55 EDT 2011
Author: bartvde
Date: 2011-06-07 12:45:54 -0700 (Tue, 07 Jun 2011)
New Revision: 12060
Added:
sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OGCExceptionReport.js
sandbox/bartvde/exception/openlayers/tests/Format/OGCExceptionReport.html
Modified:
sandbox/bartvde/exception/openlayers/lib/OpenLayers.js
sandbox/bartvde/exception/openlayers/tests/list-tests.html
Log:
more work on OGC exception formats, now adding WMS 1.3 support
Added: sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OGCExceptionReport.js
===================================================================
--- sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OGCExceptionReport.js (rev 0)
+++ sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OGCExceptionReport.js 2011-06-07 19:45:54 UTC (rev 12060)
@@ -0,0 +1,108 @@
+/* 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
+ 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"),
+ text: this.getChildValue(node)
+ };
+ exceptionReport.exceptions.push(exception);
+ }
+ }
+ },
+
+ CLASS_NAME: "OpenLayers.Format.OGCExceptionReport"
+
+});
Modified: sandbox/bartvde/exception/openlayers/lib/OpenLayers.js
===================================================================
--- sandbox/bartvde/exception/openlayers/lib/OpenLayers.js 2011-06-07 18:14:59 UTC (rev 12059)
+++ sandbox/bartvde/exception/openlayers/lib/OpenLayers.js 2011-06-07 19:45:54 UTC (rev 12060)
@@ -335,6 +335,7 @@
"OpenLayers/Format/XLS.js",
"OpenLayers/Format/XLS/v1.js",
"OpenLayers/Format/XLS/v1_1_0.js",
+ "OpenLayers/Format/OGCExceptionReport.js",
"OpenLayers/Layer/WFS.js",
"OpenLayers/Control/GetFeature.js",
"OpenLayers/Control/MouseToolbar.js",
Added: sandbox/bartvde/exception/openlayers/tests/Format/OGCExceptionReport.html
===================================================================
--- sandbox/bartvde/exception/openlayers/tests/Format/OGCExceptionReport.html (rev 0)
+++ sandbox/bartvde/exception/openlayers/tests/Format/OGCExceptionReport.html 2011-06-07 19:45:54 UTC (rev 12060)
@@ -0,0 +1,63 @@
+<html>
+<head>
+ <script src="../OLLoader.js"></script>
+ <script type="text/javascript">
+
+ function test_read_exception(t) {
+ t.plan(12);
+ // OCG WMS 1.3.0 exceptions
+ var text = '<?xml version="1.0" encoding="UTF-8"?> ' +
+'<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc"' +
+' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
+' xsi:schemaLocation="http://www.opengis.net/ogc' +
+' http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">' +
+' <ServiceException> Plain text message about an error. </ServiceException>' +
+' <ServiceException code="InvalidUpdateSequence"> Another error message, this one with a service exception code supplied. </ServiceException>' +
+' <ServiceException>' +
+' <![CDATA[ Error in module <foo.c>, line 42' +
+'A message that includes angle brackets in text must be enclosed in a Character Data Section as in this example. All XML-like markup is ignored except for this sequence of three closing characters:' +
+']]>' +
+' </ServiceException>' +
+' <ServiceException>' +
+' <![CDATA[ <Module>foo.c</Module> <Error>An error occurred</Error> <Explanation>Similarly, actual XML can be enclosed in a CDATA section. A generic parser will ignore that XML, but application-specific software may choose to process it.</Explanation> ]]>' +
+' </ServiceException>' +
+'</ServiceExceptionReport>';
+
+ var parser = new OpenLayers.Format.OGCExceptionReport();
+ var result = parser.read(text);
+
+ var exceptions = result.exceptionReport.exceptions;
+ t.eq(exceptions.length, 4, "We expect 4 exception messages");
+ t.eq(exceptions[0].text, " Plain text message about an error. ", "First error message correctly parsed");
+ t.eq(exceptions[1].code, "InvalidUpdateSequence", "Code of second error message correctly parsed");
+ t.eq(exceptions[1].text, " Another error message, this one with a service exception code supplied. ");
+ t.eq(OpenLayers.String.trim(exceptions[2].text), "Error in module <foo.c>, line 42A message that includes angle brackets in text must be enclosed in a Character Data Section as in this example. All XML-like markup is ignored except for this sequence of three closing characters:", "Third message correctly parsed");
+ t.eq(OpenLayers.String.trim(exceptions[3].text), "<Module>foo.c</Module> <Error>An error occurred</Error> <Explanation>Similarly, actual XML can be enclosed in a CDATA section. A generic parser will ignore that XML, but application-specific software may choose to process it.</Explanation>", "Fourth message correctly parsed");
+
+ // OGC WFS 1.1.0 exceptions that use OWSCommon 1.0
+ text = '<?xml version="1.0" encoding="UTF-8"?>' +
+'<ows:ExceptionReport language="en" version="1.0.0"' +
+' xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd"' +
+' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows">' +
+' <ows:Exception locator="foo" exceptionCode="InvalidParameterValue">' +
+' <ows:ExceptionText>Update error: Error occured updating features</ows:ExceptionText>' +
+' <ows:ExceptionText>Second exception line</ows:ExceptionText>' +
+' </ows:Exception>' +
+'</ows:ExceptionReport>';
+
+ var result = parser.read(text);
+ var report = result.exceptionReport;
+ t.eq(report.version, "1.0.0", "Version parsed correctly");
+ t.eq(report.language, "en", "Language parsed correctly");
+ var exception = report.exceptions[0];
+ t.eq(exception.code, "InvalidParameterValue", "exceptionCode properly parsed");
+ t.eq(exception.locator, "foo", "locator properly parsed");
+ t.eq(exception.texts[0], "Update error: Error occured updating features", "ExceptionText correctly parsed");
+ t.eq(exception.texts[1], "Second exception line", "Second ExceptionText correctly parsed");
+ }
+
+ </script>
+</head>
+<body>
+</body>
+</html>
Modified: sandbox/bartvde/exception/openlayers/tests/list-tests.html
===================================================================
--- sandbox/bartvde/exception/openlayers/tests/list-tests.html 2011-06-07 18:14:59 UTC (rev 12059)
+++ sandbox/bartvde/exception/openlayers/tests/list-tests.html 2011-06-07 19:45:54 UTC (rev 12060)
@@ -106,6 +106,7 @@
<li>Format/OWSContext/v0_3_1.html</li>
<li>Format/OWSCommon/v1_0_0.html</li>
<li>Format/OWSCommon/v1_1_0.html</li>
+ <li>Format/OGCExceptionReport.html</li>
<li>Format/XLS/v1_1_0.html</li>
<li>Format/XML.html</li>
<li>Geometry.html</li>
More information about the Commits
mailing list