[rhmessaging-commits] rhmessaging commits: r2811 - in mgmt/trunk: cumin/python/cumin and 4 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Sun Nov 16 10:34:26 EST 2008


Author: justi9
Date: 2008-11-16 10:34:25 -0500 (Sun, 16 Nov 2008)
New Revision: 2811

Added:
   mgmt/trunk/cumin-test-0/resources-wooly
   mgmt/trunk/wooly/resources/
   mgmt/trunk/wooly/resources/wooly.js
Removed:
   mgmt/trunk/cumin/resources/wooly.js
Modified:
   mgmt/trunk/cumin/Makefile
   mgmt/trunk/cumin/python/cumin/__init__.py
   mgmt/trunk/wooly/Makefile
Log:
Move the wooly resources into the wooly project; fix up makefiles; add another resource dir, the wooly one, to the Cumin resource finder

Modified: mgmt/trunk/cumin/Makefile
===================================================================
--- mgmt/trunk/cumin/Makefile	2008-11-16 15:16:32 UTC (rev 2810)
+++ mgmt/trunk/cumin/Makefile	2008-11-16 15:34:25 UTC (rev 2811)
@@ -3,7 +3,6 @@
 include ../etc/Makefile.common
 
 name := cumin
-
 lib := ${PYTHON_LIB_DIR}/${name}
 etc := ${ETC_DIR}/${name}
 doc := ${DOC_DIR}/${name}
@@ -14,16 +13,15 @@
 	../bin/python-compile python
 
 install: build
-	install -d ${PYTHON_LIB_DIR}/wooly
-	install -pm 0644 python/wooly/*.py python/wooly/*.pyc python/wooly/*.strings ${PYTHON_LIB_DIR}/wooly
 	install -d ${lib}
 	install -pm 0644 python/cumin/*.py python/cumin/*.pyc python/cumin/*.strings ${lib}
 	install -d ${BIN_DIR}
 	install -pm 0755 bin/* ${BIN_DIR}
 	install -d ${doc}
-	install -pm 0644 LICENSE* COPYING* ${doc}
+	install -pm 0644 LICENSE COPYING ${doc}
 	install -d ${share}/resources
 	install -pm 0644 resources/* ${share}/resources
+	ln -s ${SHARE_DIR}/wooly/resources ${share}/resources-wooly
 	install -d ${etc}
 	install -pm 0644 etc/* ${etc}
 	install -d ${log}

Modified: mgmt/trunk/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/__init__.py	2008-11-16 15:16:32 UTC (rev 2810)
+++ mgmt/trunk/cumin/python/cumin/__init__.py	2008-11-16 15:34:25 UTC (rev 2811)
@@ -33,9 +33,8 @@
         if self.config.debug:
             self.enable_debug()
 
-        #home, data_uri, spec_path):
-
         self.home = self.config.home
+        self.add_resource_dir(os.path.join(self.home, "resources-wooly"))
         self.add_resource_dir(os.path.join(self.home, "resources"))
 
         self.model = CuminModel(self, self.config.data, self.config.spec)

Deleted: mgmt/trunk/cumin/resources/wooly.js
===================================================================
--- mgmt/trunk/cumin/resources/wooly.js	2008-11-16 15:16:32 UTC (rev 2810)
+++ mgmt/trunk/cumin/resources/wooly.js	2008-11-16 15:34:25 UTC (rev 2811)
@@ -1,522 +0,0 @@
-var wooly;
-
-(function() {
-    wooly = new Wooly();
-
-    function assert() {
-        for (var i = 0; i < arguments.length; i++) {
-            if (!arguments[i]) {
-                throw new Error("Assertion failure in " +
-                                arguments.callee.caller.prototype);
-            }
-        }
-    }
-
-    function log() {
-        if (wooly.console) {
-            wooly.console.log.apply(wooly.console, arguments);
-        }
-    }
-
-    function dir() {
-        if (wooly.console) {
-            wooly.console.dir.apply(wooly.console, arguments);
-        }
-    }
-
-    function translate(node, parent) {
-        //log("node", node.nodeType, node, "parent", parent);
-        
-        var first = node.firstChild;
-        var name = node.nodeName;
-
-        if (first && first.nodeType == 3 && parent) {
-            parent[name] = first.nodeValue;
-
-            return null;
-        }
-
-        var object = new Object();
-        var attrs = node.attributes;
-
-        if (parent) {
-            var keyattr = null;
-
-            if (attrs) {
-                keyattr = attrs.getNamedItem("id");
-
-                if (keyattr == null) {
-                    keyattr = attrs.getNamedItem("key");
-                }
-
-                if (keyattr == null) {
-                    keyattr = attrs.getNamedItem("name");
-                }
-
-                if (keyattr) {
-                    var key = keyattr.nodeValue;
-                    var extant = parent[name];
-
-                    if (extant == null) {
-                        extant = new Object();
-                        parent[name] = extant;
-                    }
-
-                    extant[key] = object;
-                }
-            }
-
-            if (keyattr == null) {
-                var extant = parent[name];
-
-                if (extant == null) {
-                    parent[name] = object;
-                } else {
-                    var array;
-
-                    if (extant instanceof Array) {
-                        array = extant;
-                    } else {
-                        array = new Array();
-                        array.push(extant);
-
-                        parent[name] = array;
-                    }
-
-                    array.push(object);
-                }
-            }
-        }
-
-        var attr;
-
-        for (var i = 0; i < attrs.length; i++) {
-            attr = attrs[i];
-            object[attr.nodeName] = attr.nodeValue;
-        }
-
-        var childs = node.childNodes;
-
-        for (var i = 0; i < childs.length; i++) {
-            translate(childs[i], object);
-        }
-
-        return object;
-    }
-
-    function update(elem, elems, object) {
-        //log("update", "elem", elem, "elems", elems, "object", object);
-
-        if (typeof(object) == "string") {
-            if (elem.firstChild.nodeType == 3) {
-                elem.firstChild.data = object;
-            }
-        } else if (object instanceof Array) {
-            for (var i = 0; i < object.length; i++) {
-                update(elems[i], elems, object[i]);
-            }
-        } else {
-            for (var child in object) {
-                var elems = elem.getElementsByTagName(child);
-                update(elems[0], elems, object[child]);
-            }
-        }
-    }
-
-    function descendant(elem, path) {
-        var names = path.split(".");
-        var node = elem;
-
-        for (var i = 0; i < names.length; i++) {
-            var elems = elem.getElementsByTagName(names[i]);
-            
-            if (elems.length) {
-                node = elems[0];
-            } else {
-                break;
-            }
-        }
-
-        return node;
-    }
-
-    function findexpr(found, limit, node, expr) {
-        var result = document.evaluate
-            (expr, node, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
-
-        var node = result.iterateNext();
-
-        for (var i = 0; node != null && i < limit; i++) {
-            found.push(node);
-            node = result.iterateNext();
-        }
-
-        return found;
-    }
-
-    function find(found, limit,
-                  node, nodeType, nodeName,
-                  attr, attrValue) {
-        //log("find", found, limit, node, nodeType, nodeName, attr, attrValue);
-
-        /*
-        assert(found);
-        assert(found instanceof Array);
-        assert(node);
-        assert(nodeType);
-        */
-
-        var children = node.childNodes;
-
-        for (var i = 0; i < children.length; i++) {
-            var child = children[i];
-            var candidate = child;
-
-            if (child.nodeType != nodeType) {
-                candidate = null;
-            } else if (nodeName != null && child.nodeName.toLowerCase() != nodeName) {
-                candidate = null;
-            } else if (attr != null && child.nodeType == 1) {
-                var value = child.getAttribute(attr);
-
-                if (!value) {
-                    candidate = null;
-                } else if (attrValue != null && value != attrValue) {
-                    candidate = null;
-                }
-            }
-
-            if (candidate) {
-                found.push(candidate);
-
-                if (found.length == limit) {
-                    return;
-                }
-            } else if (child.nodeType == 1) {
-                find(found, limit, child, nodeType, nodeName, attr, attrValue);
-            }
-        }
-    }
-
-    function Wooly() {
-		this.getNewRequest = function() {
-			var request;
-			if (window.XMLHttpRequest) {
-	        	request = new XMLHttpRequest();
-			}
-			else {
-				if (window.ActiveXObject) {
-					try {			
-		        		request = new ActiveXObject("Microsoft.XMLHTTP");
-					} catch (e) {
-						request = new ActiveXObject("Msxml2.XMLHTTP");
-					}
-				}
-			}
-			return request;
-		}
-		
-        this.assert = assert;
-        this.log = log;
-        this.dir = dir;
-        this.updater_ids = [];
-
-        if (window.console) {
-            this.console = window.console;
-        }
-
-
-		this.deferredUpdate = function(url, callback, passback) {
-            var req = this.getNewRequest();
-
-            req.open("get", url, true);
-            req.onreadystatechange = update;
-            req.send(null);
-			
-            function update() {
-                try {
-                    if (req.readyState == 4 && req.status == 200) {
-                    	data = wooly.doc(req.responseXML);
-			            var obj = data.objectify();
-						callback(obj, passback);
-                    }
-                } catch (e) {
-                    log(e);
-                    throw e;
-                }
-            }
-		}
-
-        this.setIntervalUpdate = function(url, callback, interval) {
-            var req = this.getNewRequest();
-
-            function fetch() {
-                req.open("get", url, true);
-                req.onreadystatechange = update;
-                req.send(null);
-            }
-
-            var id = window.setInterval(fetch, interval);
-            
-            this.updater_ids.push(id);
-
-            function update() {
-                try {
-                    if (req.readyState == 4 && req.status == 200) {
-                        //dir(req);
-
-                        callback(wooly.doc(req.responseXML));
-                    }
-                } catch (e) {
-                    log(e);
-                    // XXX might want to retry for a bit before we do
-                    // this
-                    window.clearInterval(id);
-                    throw e;
-                }
-            }
-        }
-
-        this.clearUpdates = function() {
-            for (var i = 0; i < this.updater_ids.length; i++) {
-                window.clearInterval(this.updater_ids[i])
-            }
-        }
-
-        this._doc = new WoolyDocument(document);
-
-        this.doc = function(doc) {
-            if (doc) {
-                return new WoolyDocument(doc);
-            } else {
-                return this._doc;
-            }
-        }
-    }
-
-    function WoolyDocument(node) {
-        assert(node);
-
-        this.node = node;
-
-        this.root = function() {
-            return new WoolyElement(this, node.documentElement);
-        }
-
-        // XXX rename to id
-        this.elembyid = function(id) {
-            var node = this.node.getElementById(id);
-
-            if (node) {
-                return new WoolyElement(this, node);
-            }
-        }
-
-        this.elems = function(name, start) {
-            if (start == null) {
-                start = 0;
-            }
-
-            var nodes = this.node.getElementsByTagName(name);
-            var coll = new WoolyCollection(this, nodes, WoolyElement);
-
-            for (var i = 0; i < start; i++) {
-                coll.next();
-            }
-
-            return coll;
-        }
-
-        this.elem = function(name, n) {
-            return this.elems(name, n).next();
-        }
-
-        this.objectify = function() {
-            return this.root().object();
-        }
-    }
-
-    function WoolyCollection(doc, nodes, nodeClass) {
-        assert(doc);
-        assert(nodes);
-        assert(nodeClass);
-
-        this.doc = doc;
-        this.nodes = nodes;
-        this.nodeClass = nodeClass;
-
-        this.pos = 0;
-
-        this.next = function() {
-            var node = this.nodes[this.pos++];
-
-            if (node) {
-                return new this.nodeClass(this.doc, node);
-            } else {
-                return null;
-            }
-        }
-
-        this.get = function(index) {
-            var node = this.nodes[index];
-
-            if (node) {
-                return new this.nodeClass(this.doc, node);
-            } else {
-                return null;
-            }
-        }
-    }
-
-    function WoolyElement(doc, node) {
-        assert(doc);
-        assert(doc instanceof WoolyDocument);
-        assert(node);
-        // assert(node instanceof Node); IE pukes on this
-        assert(node.nodeType == 1);
-
-        this.doc = doc;
-        this.node = node;
-
-        this.clear = function() {
-            var child = this.node.firstChild;
-            var next;
-
-            while (child) {
-                next = child.nextSibling;
-                this.node.removeChild(child);
-                child = next;
-            }
-
-            return this;
-        }
-
-        this.add = function(content) {
-            assert(content);
-            
-            if (typeof content == "string") {
-                // XXX flatten this out
-                this.add(new WoolyText(this.doc, null).set(content));
-            } else if (content.hasOwnProperty("node")) {
-                this.node.appendChild(content.node);
-            } else {
-                throw new Error("Content is of unexpected type");
-            }
-
-            return this;
-        }
-
-        this.set = function(content) {
-            this.clear().add(content);
-
-            return this;
-        }
-
-        this.getattr = function(name) {
-            return this.node.getAttribute(name);
-        }
-
-        this.setattr = function(name, value) {
-            this.node.setAttribute(name, value);
-
-            return value
-        }
-
-        this.dict = function(name, kattr, vattr) {
-            var dict = new Object();
-            var elems = this.elems(name);
-            var elem = elems.next();
-
-            while (elem != null) {
-                dict[elem.getattr(kattr)] = elem.getattr(vattr);
-                elem = elems.next();
-            }
-
-            return dict;
-        }
-
-        // XXX Rename to objectify
-        this.object = function() {
-            return translate(this.node, null);
-        }
-
-        this.update = function(data) {
-            update(this.node, null, data);
-        }
-
-        this.descendant = function(path) {
-            var node = descendant(this.node, path);
-
-            return new WoolyElement(this.doc, node);
-        }
-
-        this.elems = function(name, attr, attrValue, start, limit) {
-            if (start == null) {
-                start = 0;
-            }
-
-            var nodes = new Array();
-
-            find(nodes, limit, this.node, 1, name, attr, attrValue);
-
-            var coll = new WoolyCollection(this.doc, nodes, WoolyElement);
-
-            for (var i = 0; i < start; i++) {
-                coll.next();
-            }
-
-            return coll;
-        }
-
-        this.elem = function(name, attr, attrValue) {
-            return this.elems(name, attr, attrValue, 0, 1).next();
-        }
-
-        this.texts = function(start, limit) {
-            var nodes = new Array();
-
-            find(nodes, limit, this.node, 3);
-
-            var coll = new WoolyCollection(this.doc, nodes, WoolyText);
-
-            for (var i = 0; i < start; i++) {
-                coll.next();
-            }
-
-            return coll;
-        }
-
-        this.text = function() {
-            return this.texts(0, 1).next();
-        }
-    }
-
-    function WoolyText(doc, node) {
-        assert(doc);
-        assert(doc instanceof WoolyDocument);
-        if (node) {
-        	//assert(node instanceof Node);
-        	assert(node.nodeType == 3);
-        }
-
-        this.doc = doc;
-
-        if (node == null) {
-            this.node = doc.node.createTextNode("");
-        } else {
-            this.node = node;
-        }
-
-        this.get = function() {
-            return this.node.data
-        }
-
-        this.set = function(data) {
-            assert(typeof data == "string");
-
-            this.node.data = data
-
-            return this;
-        }
-    }
-}())

Added: mgmt/trunk/cumin-test-0/resources-wooly
===================================================================
--- mgmt/trunk/cumin-test-0/resources-wooly	                        (rev 0)
+++ mgmt/trunk/cumin-test-0/resources-wooly	2008-11-16 15:34:25 UTC (rev 2811)
@@ -0,0 +1 @@
+link ../wooly/resources
\ No newline at end of file


Property changes on: mgmt/trunk/cumin-test-0/resources-wooly
___________________________________________________________________
Name: svn:special
   + *

Modified: mgmt/trunk/wooly/Makefile
===================================================================
--- mgmt/trunk/wooly/Makefile	2008-11-16 15:16:32 UTC (rev 2810)
+++ mgmt/trunk/wooly/Makefile	2008-11-16 15:34:25 UTC (rev 2811)
@@ -4,10 +4,15 @@
 
 name := wooly
 lib := ${PYTHON_LIB_DIR}/${name}
+doc := ${DOC_DIR}/${name}
+share := ${SHARE_DIR}/${name}
 
 build:
 	../bin/python-compile python
 
 install: build
 	install -d ${lib}
-	install python/wooly/*.py python/wooly/*.pyc ${lib}
+	install -pm 0644 python/wooly/*.py python/wooly/*.pyc python/wooly/*.strings ${PYTHON_LIB_DIR}/wooly
+	install -pm 0644 LICENSE* COPYING* ${doc}
+	install -d ${share}/resources
+	install -pm 0644 resources/* ${share}/resources

Copied: mgmt/trunk/wooly/resources/wooly.js (from rev 2809, mgmt/trunk/cumin/resources/wooly.js)
===================================================================
--- mgmt/trunk/wooly/resources/wooly.js	                        (rev 0)
+++ mgmt/trunk/wooly/resources/wooly.js	2008-11-16 15:34:25 UTC (rev 2811)
@@ -0,0 +1,522 @@
+var wooly;
+
+(function() {
+    wooly = new Wooly();
+
+    function assert() {
+        for (var i = 0; i < arguments.length; i++) {
+            if (!arguments[i]) {
+                throw new Error("Assertion failure in " +
+                                arguments.callee.caller.prototype);
+            }
+        }
+    }
+
+    function log() {
+        if (wooly.console) {
+            wooly.console.log.apply(wooly.console, arguments);
+        }
+    }
+
+    function dir() {
+        if (wooly.console) {
+            wooly.console.dir.apply(wooly.console, arguments);
+        }
+    }
+
+    function translate(node, parent) {
+        //log("node", node.nodeType, node, "parent", parent);
+        
+        var first = node.firstChild;
+        var name = node.nodeName;
+
+        if (first && first.nodeType == 3 && parent) {
+            parent[name] = first.nodeValue;
+
+            return null;
+        }
+
+        var object = new Object();
+        var attrs = node.attributes;
+
+        if (parent) {
+            var keyattr = null;
+
+            if (attrs) {
+                keyattr = attrs.getNamedItem("id");
+
+                if (keyattr == null) {
+                    keyattr = attrs.getNamedItem("key");
+                }
+
+                if (keyattr == null) {
+                    keyattr = attrs.getNamedItem("name");
+                }
+
+                if (keyattr) {
+                    var key = keyattr.nodeValue;
+                    var extant = parent[name];
+
+                    if (extant == null) {
+                        extant = new Object();
+                        parent[name] = extant;
+                    }
+
+                    extant[key] = object;
+                }
+            }
+
+            if (keyattr == null) {
+                var extant = parent[name];
+
+                if (extant == null) {
+                    parent[name] = object;
+                } else {
+                    var array;
+
+                    if (extant instanceof Array) {
+                        array = extant;
+                    } else {
+                        array = new Array();
+                        array.push(extant);
+
+                        parent[name] = array;
+                    }
+
+                    array.push(object);
+                }
+            }
+        }
+
+        var attr;
+
+        for (var i = 0; i < attrs.length; i++) {
+            attr = attrs[i];
+            object[attr.nodeName] = attr.nodeValue;
+        }
+
+        var childs = node.childNodes;
+
+        for (var i = 0; i < childs.length; i++) {
+            translate(childs[i], object);
+        }
+
+        return object;
+    }
+
+    function update(elem, elems, object) {
+        //log("update", "elem", elem, "elems", elems, "object", object);
+
+        if (typeof(object) == "string") {
+            if (elem.firstChild.nodeType == 3) {
+                elem.firstChild.data = object;
+            }
+        } else if (object instanceof Array) {
+            for (var i = 0; i < object.length; i++) {
+                update(elems[i], elems, object[i]);
+            }
+        } else {
+            for (var child in object) {
+                var elems = elem.getElementsByTagName(child);
+                update(elems[0], elems, object[child]);
+            }
+        }
+    }
+
+    function descendant(elem, path) {
+        var names = path.split(".");
+        var node = elem;
+
+        for (var i = 0; i < names.length; i++) {
+            var elems = elem.getElementsByTagName(names[i]);
+            
+            if (elems.length) {
+                node = elems[0];
+            } else {
+                break;
+            }
+        }
+
+        return node;
+    }
+
+    function findexpr(found, limit, node, expr) {
+        var result = document.evaluate
+            (expr, node, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
+
+        var node = result.iterateNext();
+
+        for (var i = 0; node != null && i < limit; i++) {
+            found.push(node);
+            node = result.iterateNext();
+        }
+
+        return found;
+    }
+
+    function find(found, limit,
+                  node, nodeType, nodeName,
+                  attr, attrValue) {
+        //log("find", found, limit, node, nodeType, nodeName, attr, attrValue);
+
+        /*
+        assert(found);
+        assert(found instanceof Array);
+        assert(node);
+        assert(nodeType);
+        */
+
+        var children = node.childNodes;
+
+        for (var i = 0; i < children.length; i++) {
+            var child = children[i];
+            var candidate = child;
+
+            if (child.nodeType != nodeType) {
+                candidate = null;
+            } else if (nodeName != null && child.nodeName.toLowerCase() != nodeName) {
+                candidate = null;
+            } else if (attr != null && child.nodeType == 1) {
+                var value = child.getAttribute(attr);
+
+                if (!value) {
+                    candidate = null;
+                } else if (attrValue != null && value != attrValue) {
+                    candidate = null;
+                }
+            }
+
+            if (candidate) {
+                found.push(candidate);
+
+                if (found.length == limit) {
+                    return;
+                }
+            } else if (child.nodeType == 1) {
+                find(found, limit, child, nodeType, nodeName, attr, attrValue);
+            }
+        }
+    }
+
+    function Wooly() {
+		this.getNewRequest = function() {
+			var request;
+			if (window.XMLHttpRequest) {
+	        	request = new XMLHttpRequest();
+			}
+			else {
+				if (window.ActiveXObject) {
+					try {			
+		        		request = new ActiveXObject("Microsoft.XMLHTTP");
+					} catch (e) {
+						request = new ActiveXObject("Msxml2.XMLHTTP");
+					}
+				}
+			}
+			return request;
+		}
+		
+        this.assert = assert;
+        this.log = log;
+        this.dir = dir;
+        this.updater_ids = [];
+
+        if (window.console) {
+            this.console = window.console;
+        }
+
+
+		this.deferredUpdate = function(url, callback, passback) {
+            var req = this.getNewRequest();
+
+            req.open("get", url, true);
+            req.onreadystatechange = update;
+            req.send(null);
+			
+            function update() {
+                try {
+                    if (req.readyState == 4 && req.status == 200) {
+                    	data = wooly.doc(req.responseXML);
+			            var obj = data.objectify();
+						callback(obj, passback);
+                    }
+                } catch (e) {
+                    log(e);
+                    throw e;
+                }
+            }
+		}
+
+        this.setIntervalUpdate = function(url, callback, interval) {
+            var req = this.getNewRequest();
+
+            function fetch() {
+                req.open("get", url, true);
+                req.onreadystatechange = update;
+                req.send(null);
+            }
+
+            var id = window.setInterval(fetch, interval);
+            
+            this.updater_ids.push(id);
+
+            function update() {
+                try {
+                    if (req.readyState == 4 && req.status == 200) {
+                        //dir(req);
+
+                        callback(wooly.doc(req.responseXML));
+                    }
+                } catch (e) {
+                    log(e);
+                    // XXX might want to retry for a bit before we do
+                    // this
+                    window.clearInterval(id);
+                    throw e;
+                }
+            }
+        }
+
+        this.clearUpdates = function() {
+            for (var i = 0; i < this.updater_ids.length; i++) {
+                window.clearInterval(this.updater_ids[i])
+            }
+        }
+
+        this._doc = new WoolyDocument(document);
+
+        this.doc = function(doc) {
+            if (doc) {
+                return new WoolyDocument(doc);
+            } else {
+                return this._doc;
+            }
+        }
+    }
+
+    function WoolyDocument(node) {
+        assert(node);
+
+        this.node = node;
+
+        this.root = function() {
+            return new WoolyElement(this, node.documentElement);
+        }
+
+        // XXX rename to id
+        this.elembyid = function(id) {
+            var node = this.node.getElementById(id);
+
+            if (node) {
+                return new WoolyElement(this, node);
+            }
+        }
+
+        this.elems = function(name, start) {
+            if (start == null) {
+                start = 0;
+            }
+
+            var nodes = this.node.getElementsByTagName(name);
+            var coll = new WoolyCollection(this, nodes, WoolyElement);
+
+            for (var i = 0; i < start; i++) {
+                coll.next();
+            }
+
+            return coll;
+        }
+
+        this.elem = function(name, n) {
+            return this.elems(name, n).next();
+        }
+
+        this.objectify = function() {
+            return this.root().object();
+        }
+    }
+
+    function WoolyCollection(doc, nodes, nodeClass) {
+        assert(doc);
+        assert(nodes);
+        assert(nodeClass);
+
+        this.doc = doc;
+        this.nodes = nodes;
+        this.nodeClass = nodeClass;
+
+        this.pos = 0;
+
+        this.next = function() {
+            var node = this.nodes[this.pos++];
+
+            if (node) {
+                return new this.nodeClass(this.doc, node);
+            } else {
+                return null;
+            }
+        }
+
+        this.get = function(index) {
+            var node = this.nodes[index];
+
+            if (node) {
+                return new this.nodeClass(this.doc, node);
+            } else {
+                return null;
+            }
+        }
+    }
+
+    function WoolyElement(doc, node) {
+        assert(doc);
+        assert(doc instanceof WoolyDocument);
+        assert(node);
+        // assert(node instanceof Node); IE pukes on this
+        assert(node.nodeType == 1);
+
+        this.doc = doc;
+        this.node = node;
+
+        this.clear = function() {
+            var child = this.node.firstChild;
+            var next;
+
+            while (child) {
+                next = child.nextSibling;
+                this.node.removeChild(child);
+                child = next;
+            }
+
+            return this;
+        }
+
+        this.add = function(content) {
+            assert(content);
+            
+            if (typeof content == "string") {
+                // XXX flatten this out
+                this.add(new WoolyText(this.doc, null).set(content));
+            } else if (content.hasOwnProperty("node")) {
+                this.node.appendChild(content.node);
+            } else {
+                throw new Error("Content is of unexpected type");
+            }
+
+            return this;
+        }
+
+        this.set = function(content) {
+            this.clear().add(content);
+
+            return this;
+        }
+
+        this.getattr = function(name) {
+            return this.node.getAttribute(name);
+        }
+
+        this.setattr = function(name, value) {
+            this.node.setAttribute(name, value);
+
+            return value
+        }
+
+        this.dict = function(name, kattr, vattr) {
+            var dict = new Object();
+            var elems = this.elems(name);
+            var elem = elems.next();
+
+            while (elem != null) {
+                dict[elem.getattr(kattr)] = elem.getattr(vattr);
+                elem = elems.next();
+            }
+
+            return dict;
+        }
+
+        // XXX Rename to objectify
+        this.object = function() {
+            return translate(this.node, null);
+        }
+
+        this.update = function(data) {
+            update(this.node, null, data);
+        }
+
+        this.descendant = function(path) {
+            var node = descendant(this.node, path);
+
+            return new WoolyElement(this.doc, node);
+        }
+
+        this.elems = function(name, attr, attrValue, start, limit) {
+            if (start == null) {
+                start = 0;
+            }
+
+            var nodes = new Array();
+
+            find(nodes, limit, this.node, 1, name, attr, attrValue);
+
+            var coll = new WoolyCollection(this.doc, nodes, WoolyElement);
+
+            for (var i = 0; i < start; i++) {
+                coll.next();
+            }
+
+            return coll;
+        }
+
+        this.elem = function(name, attr, attrValue) {
+            return this.elems(name, attr, attrValue, 0, 1).next();
+        }
+
+        this.texts = function(start, limit) {
+            var nodes = new Array();
+
+            find(nodes, limit, this.node, 3);
+
+            var coll = new WoolyCollection(this.doc, nodes, WoolyText);
+
+            for (var i = 0; i < start; i++) {
+                coll.next();
+            }
+
+            return coll;
+        }
+
+        this.text = function() {
+            return this.texts(0, 1).next();
+        }
+    }
+
+    function WoolyText(doc, node) {
+        assert(doc);
+        assert(doc instanceof WoolyDocument);
+        if (node) {
+        	//assert(node instanceof Node);
+        	assert(node.nodeType == 3);
+        }
+
+        this.doc = doc;
+
+        if (node == null) {
+            this.node = doc.node.createTextNode("");
+        } else {
+            this.node = node;
+        }
+
+        this.get = function() {
+            return this.node.data
+        }
+
+        this.set = function(data) {
+            assert(typeof data == "string");
+
+            this.node.data = data
+
+            return this;
+        }
+    }
+}())




More information about the rhmessaging-commits mailing list