[Laszlo-checkins] r12523 - in openlaszlo/trunk: WEB-INF/lps/lfc/data WEB-INF/lps/lfc/kernel/dhtml WEB-INF/lps/lfc/kernel/swf test/lfc/data

bargull@openlaszlo.org bargull at openlaszlo.org
Sat Jan 17 14:56:50 PST 2009


Author: bargull
Date: 2009-01-17 14:56:44 -0800 (Sat, 17 Jan 2009)
New Revision: 12523

Added:
   openlaszlo/trunk/test/lfc/data/xmlparser.lzx
Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/data/LzDataElement.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzXMLParser.js
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzXMLParser.as
   openlaszlo/trunk/test/lfc/data/alldata.lzx
Log:
Change 20090117-bargull-B0d by bargull at dell--p4--2-53 on 2009-01-17 21:05:54
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: xml parser improvements

New Features:

Bugs Fixed: LPP-7539

Technical Reviewer: hminsky
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
LzXMLParser (swf8):
throw error for xml parse-errors (error description copied over from flash docs)

LzXMLParser (dhtml):
Check document returned from DOMParser for any parse-errors and throw an error if one was found.
Removed passthrough-pragmas, they're no longer necessary
Align code for DOMParser to four leading spaces (it was three space aligned!?)

LzDataElement: mark internal object "whitespaceChars" as doc-private

xmlparser,alldata: add new test for xml parse-errors
    

Tests:
alldata with swf8, swf9 and dhtml (IE, FF, Opera, Safari)
(ignoring the known issues from LPP-7461)



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/data/LzDataElement.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/data/LzDataElement.lzs	2009-01-17 22:08:20 UTC (rev 12522)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/data/LzDataElement.lzs	2009-01-17 22:56:44 UTC (rev 12523)
@@ -843,7 +843,8 @@
 }
 
 /** @type Dictionary 
-  * @keywords read-only */
+  * @keywords read-only 
+  * @access private */
 static const whitespaceChars :Object = {' ': true, '\r': true, '\n': true, '\t': true};
 
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzXMLParser.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzXMLParser.js	2009-01-17 22:08:20 UTC (rev 12522)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzXMLParser.js	2009-01-17 22:56:44 UTC (rev 12523)
@@ -1,7 +1,7 @@
 /**
   * LzXMLParser.js
   *
-  * @copyright Copyright 2006, 2008 Laszlo Systems, Inc.  All Rights Reserved.
+  * @copyright Copyright 2006, 2008-2009 Laszlo Systems, Inc.  All Rights Reserved.
   *            Use is subject to license terms.
   *
   * @topic Kernel
@@ -11,40 +11,80 @@
 /**
   * @shortdesc Utility for parsing text into native XML DOM object
   */
-
 var LzXMLParser = {
-parseXML: function (str, trimwhitespace, nsprefix) {
-    #pragma "passThrough=true" 
-    // TODO [hqm 05-2006] need to add third arg, NSPREFIX, to
-    // this method, and to the node copy routine , see the SWF
-    // version below. Eventually the copyXML routine should be common
-    // to both swf and DHTML, with a conditionalized version for IE probably.
-    var parser = new DOMParser();
-    var doc = parser.parseFromString(str, "text/xml");
-    return doc.childNodes[0];
-}
+    parseXML: function (str, trimwhitespace, nsprefix) {
+        // TODO [hqm 05-2006] need to add third arg, NSPREFIX, to
+        // this method, and to the node copy routine , see the SWF
+        // version below. Eventually the copyXML routine should be common
+        // to both swf and DHTML, with a conditionalized version for IE probably.
+        var parser = new DOMParser();
+        var doc = parser.parseFromString(str, "text/xml");
+        // check for parser-errors
+        var browser = lz.embed.browser;
+        if (browser.isIE) {
+            this.__checkIE(doc);
+        } else if (browser.isFirefox || browser.isOpera) {
+            this.__checkFirefox(doc);
+        } else if (browser.isSafari) {
+            this.__checkSafari(doc);
+        }
+        return doc.firstChild;
+    },
+    __checkIE: function (doc) {
+        var perr = doc.parseError;
+        if (perr.errorCode != 0) {
+            throw new Error(perr.reason);
+        }
+    },
+    __checkFirefox: function (doc) {
+        var c = doc.firstChild;
+        if (c && c.nodeName == "parsererror") {
+            // get error information from textnode
+            var msg = c.firstChild.nodeValue;
+            // remove file and line information (does not provide useful info here)
+            throw new Error(msg.match(".*")[0]);
+        }
+    },
+    __checkSafari: function (doc) {
+        var c = doc.firstChild;
+        if (c instanceof HTMLElement) {
+            // Safari returns a HTMLElement for a plain string
+            // html > body > parsererror > div (with error information)
+            var msg = c.firstChild.firstChild.childNodes[1].textContent;
+            // remove file and line information (does not provide useful info here)
+            throw new Error(msg.match("[^:]*: (.*)")[1]);
+        } else {
+            c = c.firstChild;
+            if (c && c.nodeName == "parsererror") {
+                // second childNodes provides error information
+                var msg = c.childNodes[1].textContent;
+                // remove file and line information (does not provide useful info here)
+                throw new Error(msg.match("[^:]*: (.*)")[1]);
+            }
+        }
+    }
 } // end of LzXMLParser
 
-// DOMparser for IE and safari
+// DOMParser for IE and Safari2
 // http://erik.eae.net/archives/2005/07/03/20.19.18/
 if (typeof DOMParser == "undefined") {
-    #pragma "passThrough=true" 
-   var DOMParser = function () {}
-    
-   DOMParser.prototype.parseFromString = function (str, contentType) {
-      if (typeof window.ActiveXObject != "undefined") {
-         var d = new ActiveXObject("MSXML.DomDocument");
-         d.loadXML(str);
-         return d;
-      } else if (typeof XMLHttpRequest != "undefined") {
-         var req = new XMLHttpRequest;
-         req.open("GET", "data:" + (contentType || "application/xml") +
-                         ";charset=utf-8," + encodeURIComponent(str), false);
-         if (req.overrideMimeType) {
-            req.overrideMimeType(contentType);
-         }
-         req.send(null);
-         return req.responseXML;
-      }
-   }
+    var DOMParser = function () {}
+
+    DOMParser.prototype.parseFromString = function (str, contentType) {
+        if (typeof window.ActiveXObject != "undefined") {
+            var d = new ActiveXObject("MSXML.DomDocument");
+            d.loadXML(str);
+            return d;
+        } else if (typeof XMLHttpRequest != "undefined") {
+            contentType = (contentType || "application/xml");
+            var req = new XMLHttpRequest;
+            req.open("GET", "data:" + contentType + ";charset=utf-8,"
+                             + encodeURIComponent(str), false);
+            if (req.overrideMimeType) {
+                req.overrideMimeType(contentType);
+            }
+            req.send(null);
+            return req.responseXML;
+        }
+    }
 }

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzXMLParser.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzXMLParser.as	2009-01-17 22:08:20 UTC (rev 12522)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzXMLParser.as	2009-01-17 22:56:44 UTC (rev 12523)
@@ -1,7 +1,7 @@
 /**
   * LzXMLParser.as
   *
-  * @copyright Copyright 2001-2006 Laszlo Systems, Inc.  All Rights Reserved.
+  * @copyright Copyright 2001-2006, 2009 Laszlo Systems, Inc.  All Rights Reserved.
   *            Use is subject to license terms.
   *
   * @topic Kernel
@@ -11,7 +11,6 @@
 /**
   * @shortdesc Utility for parsing text into native XML DOM object
   */
-
 var LzXMLParser = new Object;
 
 /**
@@ -27,6 +26,20 @@
         var xmlobj = new XML();
         xmlobj.ignoreWhite = true;
         xmlobj.parseXML( str );
-        return xmlobj;
+        if (xmlobj.status == 0) {
+            return xmlobj;
+        } else {
+            // error descriptions from flash docs
+            var errors = ["A CDATA section was not properly terminated.", 
+             "The XML declaration was not properly terminated.",
+             "The DOCTYPE declaration was not properly terminated.",
+             "A comment was not properly terminated.",
+             "An XML element was malformed.",
+             "Out of memory.",
+             "An attribute value was not properly terminated.",
+             "A start-tag was not matched with an end-tag.",
+             "An end-tag was encountered without a matching start-tag."
+            ];
+            throw new Error(errors[xmlobj.status*(-1) - 2]);
+        }
 }
-

Modified: openlaszlo/trunk/test/lfc/data/alldata.lzx
===================================================================
--- openlaszlo/trunk/test/lfc/data/alldata.lzx	2009-01-17 22:08:20 UTC (rev 12522)
+++ openlaszlo/trunk/test/lfc/data/alldata.lzx	2009-01-17 22:56:44 UTC (rev 12523)
@@ -29,9 +29,11 @@
     <include href="testheaderresponse.lzx"/>
     <include href="sendheaders.lzx"/>
     <include href="testclientcachebreaker.lzx"/>
+    <include href="xmlparser.lzx"/>
 
     <TestSuite>
         <TestDatanode/>
+        <TestXmlParser/>
         <TestDatapointer/>
         <TestDatapointerServerless/>
         <TestDPDepend/>
@@ -65,6 +67,6 @@
     </TestSuite>
 </canvas>
 <!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
-* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2009 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * X_LZ_COPYRIGHT_END ****************************************************** -->

Added: openlaszlo/trunk/test/lfc/data/xmlparser.lzx


Property changes on: openlaszlo/trunk/test/lfc/data/xmlparser.lzx
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native



More information about the Laszlo-checkins mailing list