[OpenLayers-Commits] r12057 - in sandbox/bartvde/exception/openlayers: lib lib/OpenLayers/Format lib/OpenLayers/Format/OWSCommon tests tests/Format tests/Format/OWSCommon

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Jun 7 12:49:55 EDT 2011


Author: bartvde
Date: 2011-06-07 09:49:54 -0700 (Tue, 07 Jun 2011)
New Revision: 12057

Added:
   sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon.js
   sandbox/bartvde/exception/openlayers/tests/Format/OWSCommon/
   sandbox/bartvde/exception/openlayers/tests/Format/OWSCommon/v1_0_0.html
Modified:
   sandbox/bartvde/exception/openlayers/lib/OpenLayers.js
   sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1.js
   sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1_0_0.js
   sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1_1_0.js
   sandbox/bartvde/exception/openlayers/tests/list-tests.html
Log:
OWSCommon 1.0.0 exception report parsing

Modified: sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1.js
===================================================================
--- sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1.js	2011-06-07 14:51:22 UTC (rev 12056)
+++ sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1.js	2011-06-07 16:49:54 UTC (rev 12057)
@@ -4,13 +4,9 @@
  * full text of the license. */
 
 /**
- * @requires OpenLayers/Format/XML.js
+ * @requires OpenLayers/Format/OWSCommon.js
  */
 
-if (!OpenLayers.Format.OWSCommon) {
-    OpenLayers.Format.OWSCommon = {};
-}
-
 /**
  * Class: OpenLayers.Format.OWSCommon.v1
  * Common readers and writers for OWSCommon v1.X formats
@@ -29,6 +25,23 @@
     },
 
     /**
+     * Method: read
+     *
+     * Parameters:
+     * data - {DOMElement} An OWSCommon document element.
+     * options - {Object} Options for the reader.
+     *
+     * Returns:
+     * {Object} An object representing the OWSCommon document.
+     */
+    read: function(data, options) {
+        options = OpenLayers.Util.applyDefaults(options, this.options);
+        var ows = {};
+        this.readChildNodes(data, ows);
+        return ows;
+    },
+
+    /**
      * Property: readers
      * Contains public functions, grouped by namespace prefix, that will
      *     be applied when a namespaced node is found matching the function
@@ -38,6 +51,19 @@
      */
     readers: {
         "ows": {
+            "ExceptionReport": function(node, obj) {
+                obj.exceptionReport = {};
+                this.readChildNodes(node, obj.exceptionReport);
+            },
+            "Exception": function(node, exceptionReport) {
+                exceptionReport.exception = {
+                    code: node.getAttribute('exceptionCode')
+                };
+                this.readChildNodes(node, exceptionReport.exception);
+            },
+            "ExceptionText": function(node, exception) {
+                exception.text = this.getChildValue(node);
+            },
             "ServiceIdentification": function(node, obj) {
                 obj.serviceIdentification = {};
                 this.readChildNodes(node, obj.serviceIdentification);

Modified: sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1_0_0.js
===================================================================
--- sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1_0_0.js	2011-06-07 14:51:22 UTC (rev 12056)
+++ sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1_0_0.js	2011-06-07 16:49:54 UTC (rev 12057)
@@ -9,8 +9,7 @@
 
 /**
  * Class: OpenLayers.Format.OWSCommon.v1_0_0
- * Parser for OWS Common version 1.0.0 which can be used by other parsers.
- * It is not intended to be used on its own.
+ * Parser for OWS Common version 1.0.0.
  */
 OpenLayers.Format.OWSCommon.v1_0_0 = OpenLayers.Class(OpenLayers.Format.OWSCommon.v1, {
     
@@ -19,7 +18,7 @@
      * {Object} Mapping of namespace aliases to namespace URIs.
      */
     namespaces: {
-        ows: "http://www.opengis.net/ows/1.0",
+        ows: "http://www.opengis.net/ows",
         xlink: "http://www.w3.org/1999/xlink"
     },    
     
@@ -45,6 +44,6 @@
         "ows": OpenLayers.Format.OWSCommon.v1.prototype.writers["ows"]
     },
     
-    CLASS_NAME: "OpenLayers.Format.OWSCommon.v1_1_0"
+    CLASS_NAME: "OpenLayers.Format.OWSCommon.v1_0_0"
 
 });

Modified: sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1_1_0.js
===================================================================
--- sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1_1_0.js	2011-06-07 14:51:22 UTC (rev 12056)
+++ sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon/v1_1_0.js	2011-06-07 16:49:54 UTC (rev 12057)
@@ -9,8 +9,7 @@
 
 /**
  * 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.
+ * Parser for OWS Common version 1.1.0.
  */
 OpenLayers.Format.OWSCommon.v1_1_0 = OpenLayers.Class(OpenLayers.Format.OWSCommon.v1, {
 

Added: sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon.js
===================================================================
--- sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon.js	                        (rev 0)
+++ sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/OWSCommon.js	2011-06-07 16:49:54 UTC (rev 12057)
@@ -0,0 +1,86 @@
+/* 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
+ */
+
+/**
+ * Class: OpenLayers.Format.OWSCommon
+ * Read OWSCommon. Create a new instance with the <OpenLayers.Format.OWSCommon>
+ *     constructor.
+ * 
+ * Inherits from:
+ *  - <OpenLayers.Format.XML>
+ */
+OpenLayers.Format.OWSCommon = 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
+     * {Object} Instance of the versioned parser.  Cached for multiple read and
+     *     write calls of the same version.
+     */
+    parser: null,
+
+    /**
+     * Constructor: OpenLayers.Format.OWSCommon
+     * Create a new parser for OWSCommon.
+     *
+     * Parameters:
+     * options - {Object} An optional object whose properties will be set on
+     *     this instance.
+     */
+
+    /**
+     * APIMethod: read
+     * Read an OWSCommon document and return an object.
+     *
+     * Parameters:
+     * data - {String | DOMElement} Data to read.
+     * options - {Object} Options for the reader.
+     *
+     * Returns:
+     * {Object} An object representing the structure of the document.
+     */
+    read: function(data, options) {
+        if(typeof data == "string") {
+            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
+        }
+        var root = data.documentElement;
+        var version = this.version;
+        if(!version) {
+            version = root.getAttribute("version");
+            if(!version) {
+                version = this.defaultVersion;
+            }
+        }
+        if(!this.parser || this.parser.VERSION != version) {
+            var format = OpenLayers.Format.OWSCommon[
+                "v" + version.replace(/\./g, "_")
+            ];
+            if(!format) {
+                throw "Can't find a OWSCommon parser for version " +
+                      version;
+            }
+            this.parser = new format(this.options);
+        }
+        var ows = this.parser.read(data, options);
+        return ows;
+    },
+
+    CLASS_NAME: "OpenLayers.Format.OWSCommon" 
+});

Modified: sandbox/bartvde/exception/openlayers/lib/OpenLayers.js
===================================================================
--- sandbox/bartvde/exception/openlayers/lib/OpenLayers.js	2011-06-07 14:51:22 UTC (rev 12056)
+++ sandbox/bartvde/exception/openlayers/lib/OpenLayers.js	2011-06-07 16:49:54 UTC (rev 12057)
@@ -296,6 +296,7 @@
                 "OpenLayers/Format/SLD.js",
                 "OpenLayers/Format/SLD/v1.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",

Added: sandbox/bartvde/exception/openlayers/tests/Format/OWSCommon/v1_0_0.html
===================================================================
--- sandbox/bartvde/exception/openlayers/tests/Format/OWSCommon/v1_0_0.html	                        (rev 0)
+++ sandbox/bartvde/exception/openlayers/tests/Format/OWSCommon/v1_0_0.html	2011-06-07 16:49:54 UTC (rev 12057)
@@ -0,0 +1,28 @@
+<html>
+<head> 
+    <script src="../../OLLoader.js"></script>
+    <script type="text/javascript">
+
+    function test_read_exception(t) {
+        t.plan(2);
+        var text = '<?xml version="1.0" encoding="UTF-8"?>' +
+'<ows:ExceptionReport 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 exceptionCode="InvalidParameterValue">' +
+'        <ows:ExceptionText>Update error: Error occured updating features</ows:ExceptionText>' +
+'    </ows:Exception>' +
+'</ows:ExceptionReport>';
+
+        var format = new OpenLayers.Format.OWSCommon();
+        var result = format.read(text);
+        var exception = result.exceptionReport.exception;
+        t.eq(exception.code, "InvalidParameterValue", "exceptionCode properly parsed");
+        t.eq(exception.text, "Update error: Error occured updating features", "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 14:51:22 UTC (rev 12056)
+++ sandbox/bartvde/exception/openlayers/tests/list-tests.html	2011-06-07 16:49:54 UTC (rev 12057)
@@ -104,6 +104,7 @@
     <li>Format/SOSGetObservation.html</li>
     <li>Format/SOSGetFeatureOfInterest.html</li>
     <li>Format/OWSContext/v0_3_1.html</li>
+    <li>Format/OWSCommon/v1_0_0.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