From 5c6ccfca16a421860cd57d11e41d94d8a70cda76 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Wed, 14 Apr 2010 20:52:52 +0200 Subject: Make handlers instances instead of using static methods. --- org/madore/damlengine/ElementHandler.java | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 org/madore/damlengine/ElementHandler.java (limited to 'org/madore/damlengine/ElementHandler.java') diff --git a/org/madore/damlengine/ElementHandler.java b/org/madore/damlengine/ElementHandler.java new file mode 100644 index 0000000..4e14756 --- /dev/null +++ b/org/madore/damlengine/ElementHandler.java @@ -0,0 +1,41 @@ +package org.madore.damlengine; + +import java.util.Vector; +import java.util.HashMap; +import org.w3c.dom.*; + +public abstract class ElementHandler { + + public void handleAttributes(TodoElement that) { + NamedNodeMap attrs = that.node.getAttributes(); + Node attr; + Vector toProcess = new Vector(); + for ( int i=0 ; (attr=attrs.item(i)) != null ; i++ ) { + TodoAttr it = new TodoAttr((Attr)attr, that.node, that.context, + new HashMap()); + toProcess.add(it); + } + TodoDeque.registerAtStart(toProcess); + } + + public void handleNodeOnly(TodoElement that) { + System.err.println("handling a "+that.node.getNodeName()+" element"); + NodeList children = that.node.getChildNodes(); + Node child; + Vector toProcess = new Vector(); + for ( int i=0 ; (child=children.item(i)) != null ; i++ ) { + if ( child.getNodeType() == Node.ELEMENT_NODE ) { + TodoElement it = new TodoElement((Element)child, that.context, + new HashMap()); + toProcess.add(it); + } + } + TodoDeque.registerAtStart(toProcess); + } + + public void handle(TodoElement that) { + handleAttributes(that); + handleNodeOnly(that); + } + +} -- cgit v1.2.3