package org.madore.damlengine; import java.util.ArrayList; import org.w3c.dom.*; public class TodoDefaultElement extends TodoElement { public static class Factory extends TodoElement.Factory { public TodoDefaultElement newItem(Element node, TodoContext context, TodoItem.Options options) { return new TodoDefaultElement(node, context, options); } } public TodoDefaultElement(Element node, TodoContext context, TodoItem.Options options) { super(node, context, options); } public static ArrayList getAttrList(Element node) { NamedNodeMap attrs = node.getAttributes(); ArrayList attrList = new ArrayList(attrs.getLength()); Node attr; for ( int i=0 ; (attr=attrs.item(i)) != null ; i++ ) attrList.add((Attr)attr); return attrList; } public static ArrayList getChildList(Element node) { NodeList children = node.getChildNodes(); ArrayList childList = new ArrayList(children.getLength()); Node child; for ( int i=0 ; (child=children.item(i)) != null ; i++ ) childList.add(child); return childList; } public void handleAttributes() { ArrayList attrList = getAttrList(this.node); ArrayList toProcess = new ArrayList(attrList.size()); for ( Attr attr : attrList ) { TodoAttr it = TodoAttr.getTodoAttr(attr, this.node, this.context, new TodoItem.Options()); if ( it != null ) toProcess.add(it); } this.ownerDeque.registerAtStart(toProcess); } public void handleNodeOnly() { System.err.println("handling a "+this.node.getNodeName()+" element"); ArrayList childList = getChildList(this.node); ArrayList toProcess = new ArrayList(childList.size()); for ( Node child : childList ) { if ( child.getNodeType() == Node.ELEMENT_NODE ) { TodoElement it = TodoElement.getTodoElement((Element)child, this.context, new TodoItem.Options()); toProcess.add(it); } } this.ownerDeque.registerAtStart(toProcess); } public void handle() { assert(this.ownerDeque != null); handleAttributes(); handleNodeOnly(); } }