diff options
author | David A. Madore <david@procyon.(none)> | 2010-04-18 18:29:01 +0200 |
---|---|---|
committer | David A. Madore <david@procyon.(none)> | 2010-04-18 18:29:01 +0200 |
commit | 98f35c3443d6df4db5a73916d9a4cd80c482f4c5 (patch) | |
tree | f0715319586fed47387acfb433cf1ce0ca0a935c /org/madore/damlengine | |
parent | 852ff66033951ea44a94c25d5eb9da418c87dac4 (diff) | |
download | damlengine-98f35c3443d6df4db5a73916d9a4cd80c482f4c5.tar.gz damlengine-98f35c3443d6df4db5a73916d9a4cd80c482f4c5.tar.bz2 damlengine-98f35c3443d6df4db5a73916d9a4cd80c482f4c5.zip |
Hide the use of NodeList and NamedNodeMap by real Java ArrayList objects.
This makes it possible to modify the underlying tree without getting
hit by .item(i) returning the wrong next item.
Diffstat (limited to 'org/madore/damlengine')
-rw-r--r-- | org/madore/damlengine/TodoDefaultElement.java | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/org/madore/damlengine/TodoDefaultElement.java b/org/madore/damlengine/TodoDefaultElement.java index fd916e3..50a460f 100644 --- a/org/madore/damlengine/TodoDefaultElement.java +++ b/org/madore/damlengine/TodoDefaultElement.java @@ -19,13 +19,30 @@ public class TodoDefaultElement extends TodoElement { super(node, context, options); } - public void handleAttributes() { - NamedNodeMap attrs = this.node.getAttributes(); + public static ArrayList<Attr> getAttrList(Element node) { + NamedNodeMap attrs = node.getAttributes(); + ArrayList<Attr> attrList = new ArrayList<Attr>(attrs.getLength()); Node attr; - ArrayList<TodoAttr> toProcess = new ArrayList<TodoAttr>(); - for ( int i=0 ; (attr=attrs.item(i)) != null ; i++ ) { + for ( int i=0 ; (attr=attrs.item(i)) != null ; i++ ) + attrList.add((Attr)attr); + return attrList; + } + + public static ArrayList<Node> getChildList(Element node) { + NodeList children = node.getChildNodes(); + ArrayList<Node> childList = new ArrayList<Node>(children.getLength()); + Node child; + for ( int i=0 ; (child=children.item(i)) != null ; i++ ) + childList.add(child); + return childList; + } + + public void handleAttributes() { + ArrayList<Attr> attrList = getAttrList(this.node); + ArrayList<TodoAttr> toProcess = new ArrayList<TodoAttr>(attrList.size()); + for ( Attr attr : attrList ) { TodoAttr it - = TodoAttr.getTodoAttr((Attr)attr, this.node, this.context, + = TodoAttr.getTodoAttr(attr, this.node, this.context, new TodoItem.Options()); if ( it != null ) toProcess.add(it); @@ -35,10 +52,9 @@ public class TodoDefaultElement extends TodoElement { public void handleNodeOnly() { System.err.println("handling a "+this.node.getNodeName()+" element"); - NodeList children = this.node.getChildNodes(); - Node child; - ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(); - for ( int i=0 ; (child=children.item(i)) != null ; i++ ) { + ArrayList<Node> childList = getChildList(this.node); + ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()); + for ( Node child : childList ) { if ( child.getNodeType() == Node.ELEMENT_NODE ) { TodoElement it = TodoElement.getTodoElement((Element)child, this.context, |