Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / examples / ux / XmlTreeLoader.js
similarity index 86%
rename from examples/tree/XmlTreeLoader.js
rename to examples/ux/XmlTreeLoader.js
index 63b17b1..8bc7072 100644 (file)
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.ux.XmlTreeLoader\r
- * @extends Ext.tree.TreeLoader\r
- * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.\r
- * Any text value included as a text node in the XML will be added to the parent node as an attribute\r
- * called <tt>innerText</tt>.  Also, the tag name of each XML node will be added to the tree node as\r
- * an attribute called <tt>tagName</tt>.</p>\r
- * <p>By default, this class expects that your source XML will provide the necessary attributes on each \r
- * node as expected by the {@link Ext.tree.TreePanel} to display and load properly.  However, you can\r
- * provide your own custom processing of node attributes by overriding the {@link #processNode} method\r
- * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>\r
- * @constructor\r
- * Creates a new XmlTreeloader.\r
- * @param {Object} config A config object containing config properties.\r
- */\r
-Ext.ux.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {\r
-    /**\r
-     * @property  XML_NODE_ELEMENT\r
-     * XML element node (value 1, read-only)\r
-     * @type Number\r
-     */\r
-    XML_NODE_ELEMENT : 1,\r
-    /**\r
-     * @property  XML_NODE_TEXT\r
-     * XML text node (value 3, read-only)\r
-     * @type Number\r
-     */\r
-    XML_NODE_TEXT : 3,\r
-    \r
-    // private override\r
-    processResponse : function(response, node, callback){\r
-        var xmlData = response.responseXML;\r
-        var root = xmlData.documentElement || xmlData;\r
-        \r
-        try{\r
-            node.beginUpdate();\r
-            node.appendChild(this.parseXml(root));\r
-            node.endUpdate();\r
-            \r
-            if(typeof callback == "function"){\r
-                callback(this, node);\r
-            }\r
-        }catch(e){\r
-            this.handleFailure(response);\r
-        }\r
-    },\r
-    \r
-    // private\r
-    parseXml : function(node) {\r
-        var nodes = [];\r
-        Ext.each(node.childNodes, function(n){\r
-            if(n.nodeType == this.XML_NODE_ELEMENT){\r
-                var treeNode = this.createNode(n);\r
-                if(n.childNodes.length > 0){\r
-                    var child = this.parseXml(n);\r
-                    if(typeof child == 'string'){\r
-                        treeNode.attributes.innerText = child;\r
-                    }else{\r
-                        treeNode.appendChild(child);\r
-                    }\r
-                }\r
-                nodes.push(treeNode);\r
-            }\r
-            else if(n.nodeType == this.XML_NODE_TEXT){\r
-                var text = n.nodeValue.trim();\r
-                if(text.length > 0){\r
-                    return nodes = text;\r
-                }\r
-            }\r
-        }, this);\r
-        \r
-        return nodes;\r
-    },\r
-    \r
-    // private override\r
-    createNode : function(node){\r
-        var attr = {\r
-            tagName: node.tagName\r
-        };\r
-        \r
-        Ext.each(node.attributes, function(a){\r
-            attr[a.nodeName] = a.nodeValue;\r
-        });\r
-        \r
-        this.processAttributes(attr);\r
-        \r
-        return Ext.ux.XmlTreeLoader.superclass.createNode.call(this, attr);\r
-    },\r
-    \r
-    /*\r
-     * Template method intended to be overridden by subclasses that need to provide\r
-     * custom attribute processing prior to the creation of each TreeNode.  This method\r
-     * will be passed a config object containing existing TreeNode attribute name/value\r
-     * pairs which can be modified as needed directly (no need to return the object).\r
-     */\r
-    processAttributes: Ext.emptyFn\r
-});\r
+/*!
+ * Ext JS Library 3.0.0
+ * Copyright(c) 2006-2009 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+Ext.ns('Ext.ux.tree');
+
+/**
+ * @class Ext.ux.tree.XmlTreeLoader
+ * @extends Ext.tree.TreeLoader
+ * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
+ * Any text value included as a text node in the XML will be added to the parent node as an attribute
+ * called <tt>innerText</tt>.  Also, the tag name of each XML node will be added to the tree node as
+ * an attribute called <tt>tagName</tt>.</p>
+ * <p>By default, this class expects that your source XML will provide the necessary attributes on each
+ * node as expected by the {@link Ext.tree.TreePanel} to display and load properly.  However, you can
+ * provide your own custom processing of node attributes by overriding the {@link #processNode} method
+ * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
+ * @constructor
+ * Creates a new XmlTreeloader.
+ * @param {Object} config A config object containing config properties.
+ */
+Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
+    /**
+     * @property  XML_NODE_ELEMENT
+     * XML element node (value 1, read-only)
+     * @type Number
+     */
+    XML_NODE_ELEMENT : 1,
+    /**
+     * @property  XML_NODE_TEXT
+     * XML text node (value 3, read-only)
+     * @type Number
+     */
+    XML_NODE_TEXT : 3,
+
+    // private override
+    processResponse : function(response, node, callback){
+        var xmlData = response.responseXML;
+        var root = xmlData.documentElement || xmlData;
+
+        try{
+            node.beginUpdate();
+            node.appendChild(this.parseXml(root));
+            node.endUpdate();
+
+            if(typeof callback == "function"){
+                callback(this, node);
+            }
+        }catch(e){
+            this.handleFailure(response);
+        }
+    },
+
+    // private
+    parseXml : function(node) {
+        var nodes = [];
+        Ext.each(node.childNodes, function(n){
+            if(n.nodeType == this.XML_NODE_ELEMENT){
+                var treeNode = this.createNode(n);
+                if(n.childNodes.length > 0){
+                    var child = this.parseXml(n);
+                    if(typeof child == 'string'){
+                        treeNode.attributes.innerText = child;
+                    }else{
+                        treeNode.appendChild(child);
+                    }
+                }
+                nodes.push(treeNode);
+            }
+            else if(n.nodeType == this.XML_NODE_TEXT){
+                var text = n.nodeValue.trim();
+                if(text.length > 0){
+                    return nodes = text;
+                }
+            }
+        }, this);
+
+        return nodes;
+    },
+
+    // private override
+    createNode : function(node){
+        var attr = {
+            tagName: node.tagName
+        };
+
+        Ext.each(node.attributes, function(a){
+            attr[a.nodeName] = a.nodeValue;
+        });
+
+        this.processAttributes(attr);
+
+        return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
+    },
+
+    /*
+     * Template method intended to be overridden by subclasses that need to provide
+     * custom attribute processing prior to the creation of each TreeNode.  This method
+     * will be passed a config object containing existing TreeNode attribute name/value
+     * pairs which can be modified as needed directly (no need to return the object).
+     */
+    processAttributes: Ext.emptyFn
+});
+
+//backwards compat
+Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;