Author: hqm
Date: 2008-01-25 20:35:02 -0800 (Fri, 25 Jan 2008)
New Revision: 7894
Added:
openlaszlo/branches/devildog/test/swf9/testxml.lzx
Modified:
openlaszlo/branches/devildog/WEB-INF/lps/lfc/core/dummyclasses.js
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzHTTPLoader.as
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzXMLTranslator.as
Log:
Change 20080125-hqm-0 by [EMAIL PROTECTED] on 2008-01-25 23:31:41 EST
in /cygdrive/c/users/hqm/openlaszlo/devildog
for http://svn.openlaszlo.org/openlaszlo/branches/devildog
Summary: use E4X API for kernel data routines
New Features:
Bugs Fixed:
Technical Reviewer: max
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
Flex docs recommend using the E4X APIs to handle XML data.
Converted swf8 XML DOM API code to use E4X APi
Tests:
Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/core/dummyclasses.js
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/core/dummyclasses.js
2008-01-25 20:56:35 UTC (rev 7893)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/core/dummyclasses.js
2008-01-26 04:35:02 UTC (rev 7894)
@@ -49,16 +49,20 @@
public class LzDataNode {
public function LzDataNode (...rest) { }
- public static function trim (...rest) {
+ public static function trim (val) {
+ return val;
}
}
class LzDataElement extends LzDataNode {
+ public var children = [];
public function LzDataElement (name , cattrs) {
}
public function setChildNodes(l) {
+ children.push(l);
+ trace("setChildNodes", l);
}
}
Modified:
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzHTTPLoader.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzHTTPLoader.as
2008-01-25 20:56:35 UTC (rev 7893)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzHTTPLoader.as
2008-01-26 04:35:02 UTC (rev 7894)
@@ -315,9 +315,9 @@
private function completeHandler(event:Event):void {
if (event.target is URLLoader) {
- trace("completeHandler: " , this, loader);
- trace("completeHandler: bytesLoaded" , loader.bytesLoaded,
'bytesTotal', loader.bytesTotal);
- trace('typeof data:', typeof(loader.data), loader.data.length,
'parsexml=', options.parsexml);
+ // trace("completeHandler: " , this, loader);
+ //trace("completeHandler: bytesLoaded" , loader.bytesLoaded,
'bytesTotal', loader.bytesTotal);
+ //trace('typeof data:', typeof(loader.data), loader.data.length,
'parsexml=', options.parsexml);
responseText = loader.data;
var elt = null;
@@ -325,25 +325,20 @@
removeTimeout(this);
// Parse data into flash native XML and then convert to LFC
LzDataElement tree
- if (responseText != null && options.parsexml) {
- //TODO [hqm 2008-01] we should wrap this in a try-catch,
- // give a good error message if we get an error parsing the
XML,
- // and then signal an onerror event.
- this.responseXML = new XML(responseText);
- var nodes = this.responseXML.childNodes;
- // find first content (type == 1) child node
- for (var i = 0; i < nodes.length; i++) {
- var child:XMLNode = nodes[i];
- if (child.nodeType == XMLNodeType.ELEMENT_NODE) {
- elt = child;
- break;
- }
+ try {
+ if (responseText != null && options.parsexml) {
+ this.responseXML = new XML(responseText);
+ lzxdata = LzXMLTranslator.copyXML(this.responseXML,
+ options.trimwhitespace,
+ options.nsprefix);
}
- lzxdata = LzXMLTranslator.copyXML(elt,
- options.trimwhitespace,
- options.nsprefix);
+ } catch (err) {
+ trace("caught error parsing xml", err);
+ loadError(this, null);
+ return;
}
- loadSuccess(this, responseText);
+
+ loadSuccess(this, lzxdata);
}
}
Modified:
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzXMLTranslator.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzXMLTranslator.as
2008-01-25 20:56:35 UTC (rev 7893)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzXMLTranslator.as
2008-01-26 04:35:02 UTC (rev 7894)
@@ -16,7 +16,10 @@
static function copyXML (xmlobj, trimwhitespace, nsprefix) {
var lfcnode = copyFlashXML(xmlobj, trimwhitespace, nsprefix);
- var fc = lfcnode.childNodes[0];
+ if (lfcnode == null) {
+ trace('LzXMLTranslator.copyXML: lfcnode.children is null', lfcnode);
+ }
+ var fc = lfcnode.children[0];
if ( fc is LzDataText ) {
return null;
}
@@ -31,43 +34,33 @@
* @access private
*/
static function copyFlashXML (node, trimwhitespace, nsprefix) {
- var nv = node.nodeValue;
var lfcnode = null;
// text node?
if (node.nodeKind() == 'text') {
+ var nv = node.toString();
if (trimwhitespace == true) {
nv = LzDataNode.trim(nv);
}
lfcnode = new LzDataText(nv);
- } else if (node.nodeKind == 'element') {
- // slow but sure way to copy attributes
- var nattrs = node.attributes;
+ } else if (node.nodeKind() == 'element') {
+ var nattrs = node.attributes();
var cattrs = {};
- for (var key in nattrs) {
- var nkey = key;
- if (!nsprefix) {
- // strip namespace prefixes
- var colpos = key.indexOf(':');
- if (colpos >= 0) {
- nkey = key.substring(colpos+1);
- }
- }
- cattrs[nkey] = nattrs[key];
+ for (var i:int = 0; i < nattrs.length(); i++) {
+ var key = nsprefix ? nattrs[i].name() : nattrs[i].localName();
+ cattrs[key] = nattrs[i];
}
- var nname = node.nodeName;
- if (nname && !nsprefix) {
- // strip namespace prefix
- var npos = nname.indexOf(':');
- if (npos >= 0) {
- nname = nname.substring(npos+1);
- }
+ var nname;
+ if (nsprefix) {
+ var nname = node.name();
+ } else {
+ nname = node.localName();
}
lfcnode = new LzDataElement(nname, cattrs);
- var children = node.childNodes;
+ var children = node.children();
var newchildren = [];
- for (var i = 0; i < children.length; i++ ) {
+ for (var i = 0; i < children.length(); i++ ) {
var child = children[i];
var lfcchild = copyFlashXML(child, trimwhitespace, nsprefix);
newchildren[i] = lfcchild;
Added: openlaszlo/branches/devildog/test/swf9/testxml.lzx
Property changes on: openlaszlo/branches/devildog/test/swf9/testxml.lzx
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins