[Laszlo-checkins] r9412 - openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9

bargull@openlaszlo.org bargull at openlaszlo.org
Sat May 31 16:58:16 PDT 2008


Author: bargull
Date: 2008-05-31 16:58:13 -0700 (Sat, 31 May 2008)
New Revision: 9412

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzXMLTranslator.as
Log:
Change 20080601-bargull-Vzq by bargull at dell--p4--2-53 on 2008-06-01 00:56:07
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Add nsprefix support to swf9 

New Features:

Bugs Fixed: LPP-6078

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

Documentation:

Release Notes:

Details:
Added support for nsprefix to the xml-translator. 
    

Tests:



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzXMLTranslator.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzXMLTranslator.as	2008-05-31 23:32:18 UTC (rev 9411)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzXMLTranslator.as	2008-05-31 23:58:13 UTC (rev 9412)
@@ -14,16 +14,17 @@
 
 public class LzXMLTranslator {
 
-static function copyXML (xmlobj, trimwhitespace, nsprefix) {
-    var lfcnode = copyFlashXML(xmlobj, trimwhitespace, nsprefix);
+static function copyXML (xmlobj:XML, trimwhitespace:Boolean, nsprefix:Boolean) :LzDataElementMixin {
+    var lfcnode:LzDataNodeMixin = copyFlashXML(xmlobj, trimwhitespace, nsprefix);
     if (lfcnode == null) {
         trace('LzXMLTranslator.copyXML: lfcnode.children is null', lfcnode);
     }
-    var fc = lfcnode;
-    if ( fc is LzDataText ) {
+    
+    if ( lfcnode is LzDataText ) {
         return null;
     }
-    return fc;
+    
+    return (lfcnode cast LzDataElementMixin);
 }
 
 
@@ -34,12 +35,12 @@
   * trim whitespace from start and end of string
   * @access private
   */
-static function trim( str ) {
-    var whitech = whitespaceChars;
-    var len = str.length;
-    var sindex = 0;
-    var eindex = str.length -1;
-    var ch;
+static function trim( str:String ) :String {
+    var whitech:Object = whitespaceChars;
+    var len:int = str.length;
+    var sindex:int = 0;
+    var eindex:int = str.length -1;
+    var ch:String;
     while (sindex < len) {
         ch = str.charAt(sindex);
         if (whitech[ch] != true) break;
@@ -63,11 +64,11 @@
   * @param boolean nsprefix: preserve namespace prefixes on node names and attribute names
   * @access private
   */
-static function copyFlashXML (node, trimwhitespace, nsprefix) {
-    var lfcnode = null;
+static function copyFlashXML (node:XML, trimwhitespace:Boolean, nsprefix:Boolean) :LzDataNodeMixin {
+    var lfcnode:LzDataNodeMixin = null;
     // text node?
     if (node.nodeKind() == 'text') {
-        var nv = node.toString();
+        var nv:String = node.toString();
         if (trimwhitespace == true) {
             nv = trim(nv);
         }
@@ -75,31 +76,48 @@
 //PBR Changed to match swf kernel
 //    } else if (node.nodeKind() == 'element') {
       } else {
-        var nattrs = node.attributes();
-        var cattrs = {};
+        
+        var nattrs:XMLList = node.attributes();
+        var cattrs:Object = {};
         for (var i:int = 0; i < nattrs.length(); i++) {
-            var key = nsprefix ? nattrs[i].name() : nattrs[i].localName();
-            cattrs[key] = nattrs[i];
+            var attr:XML = nattrs[i];
+            var qattr:QName = attr.name();
+            if (nsprefix) {
+                var ns:Namespace = attr.namespace();
+                var key:String;
+                if (ns != null && ns.prefix != "") {
+                    key = ns.prefix + ":" + qattr.localName;
+                } else {
+                    key = qattr.localName;
+                }
+                cattrs[key] = attr.toString();
+            } else {
+                cattrs[qattr.localName] = attr.toString();
+            }
         }
 
-        var nname = node.localName();
-        if (nname && !nsprefix) {
-            // strip namespace prefix
-            var npos = nname.indexOf(':');
-            if (npos >= 0) {
-                nname = nname.substring(npos+1);
+        var nname:String;
+        var qname:QName = node.name();
+        if (nsprefix) {
+            var ns:Namespace = node.namespace();
+            if (ns != null && ns.prefix != "") {
+                nname = ns.prefix + ":" + qname.localName;
+            } else {
+                nname = qname.localName;
             }
+        } else {
+            nname = qname.localName;
         }
 
         lfcnode = new LzDataElement(nname, cattrs);
-        var children = node.children();
-        var newchildren = [];
-        for (var i  = 0; i < children.length(); i++ ) {
-            var child = children[i];
-            var lfcchild = copyFlashXML(child, trimwhitespace, nsprefix);
+        var children:XMLList = node.children();
+        var newchildren:Array = [];
+        for (var i:int  = 0; i < children.length(); i++ ) {
+            var child:XML = children[i];
+            var lfcchild:LzDataNodeMixin = copyFlashXML(child, trimwhitespace, nsprefix);
             newchildren[i] = lfcchild;
         }
-        lfcnode.setChildNodes(newchildren);
+        (lfcnode cast LzDataElement).setChildNodes(newchildren);
     }
     return lfcnode;
 }



More information about the Laszlo-checkins mailing list