package org.madore.damlengine; import java.io.OutputStreamWriter; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.xml.sax.EntityResolver; import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; public final class DamlEngine { public static final String XML_NS = "http://www.w3.org/XML/1998/namespace"; public static final String XHTML_NS = "http://www.w3.org/1999/xhtml"; public static final String DAML_NS = "http://www.madore.org/~david/NS/daml/"; private DamlEngine() { // Forbid instantiation throw new AssertionError("DamlEngine cannot be instantiated"); } public static class RootTodo extends TodoItem { public RootTodo(Context ctx) { super(ctx, null); } public void handle() { TodoItem it = TodoElement.getTodoElement(ctx.doc.getDocumentElement(), ctx, this); this.ownerDeque.registerAtEnd(it); } } public static void processDocument(Document doc) { TodoDeque todoDeque = new TodoDeque(); Context ctx = new Context(doc); todoDeque.registerAtEnd(new RootTodo(ctx)); todoDeque.dispatchLoop(); } public static void main(String[] args) throws Exception { final Resolver resolver = new Resolver(); final DocumentBuilderFactory dbf = new DocumentBuilderFactoryImpl(); dbf.setNamespaceAware(true); dbf.setValidating(false); final DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(resolver); if ( args.length == 0 ) { System.err.println("expecting filename as argument"); } for (String fname : args) { Document doc = db.parse(fname); processDocument(doc); doc.normalizeDocument(); Unparser unparser = new Unparser(doc, new OutputStreamWriter(System.out, "UTF-8"), "html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); unparser.unparse(); } } }