From 9124ad9a07d19753abcb696d04483589c2a45355 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 18 Apr 2010 19:28:58 +0200 Subject: Preliminary handler for element. --- org/madore/damlengine/TodoDamlElement.java | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 org/madore/damlengine/TodoDamlElement.java (limited to 'org/madore/damlengine/TodoDamlElement.java') diff --git a/org/madore/damlengine/TodoDamlElement.java b/org/madore/damlengine/TodoDamlElement.java new file mode 100644 index 0000000..88881ae --- /dev/null +++ b/org/madore/damlengine/TodoDamlElement.java @@ -0,0 +1,78 @@ +package org.madore.damlengine; + +import java.util.ArrayList; +import java.util.regex.Pattern; +import org.w3c.dom.*; + +public class TodoDamlElement extends TodoDefaultElement { + + public static class Factory extends TodoElement.Factory { + public TodoDamlElement newItem(Element node, + TodoContext context, + TodoItem.Options options) { + return new TodoDamlElement(node, context, options); + } + } + + public TodoDamlElement(Element node, + TodoContext context, + TodoItem.Options options) { + super(node, context, options); + } + + public static class DamlOptions extends TodoItem.Options { + } + + public void handleNodeOnly() { + if ( ! ( options instanceof DamlEngine.RootOptions ) ) + throw new Error("daml node can only be root node"); + String uriToTop = node.getAttributeNS(null, "uri-to-top"); + if ( uriToTop != null ) + context.uriToTop = uriToTop; + String fileName = node.getAttributeNS(null, "file.name"); + if ( fileName != null ) + context.fileName = fileName; + + if ( context.htmlNode != null ) + throw new Error("html node already defined at daml node"); + context.htmlNode = context.doc.createElementNS(DamlEngine.XHTML_NS, "html"); + String lang = LangHelper.getLangNorec(node); + if ( lang != null ) + LangHelper.setLangNorec(context.htmlNode, lang); + node.getParentNode().replaceChild(context.htmlNode, node); + context.htmlNode.appendChild(context.doc.createTextNode("\n")); + context.htmlNode.appendChild(context.doc.createComment(" This file is automatically generated. Do not edit! ")); + context.htmlNode.appendChild(context.doc.createTextNode("\n")); + if ( context.headNode != null ) + throw new Error("head node already defined at daml node"); + context.headNode = context.doc.createElementNS(DamlEngine.XHTML_NS, "head"); + context.htmlNode.appendChild(context.headNode); + context.htmlNode.appendChild(context.doc.createTextNode("\n")); + context.headNode.appendChild(context.doc.createTextNode("\n")); + + ArrayList childList = getChildList(this.node); + ArrayList toProcess = new ArrayList(childList.size()); + for ( Node child : childList ) { + if ( child.getNodeType() == Node.ELEMENT_NODE ) { + if ( child.getLocalName().equals("body") ) { + context.htmlNode.appendChild(context.doc.createTextNode("\n")); + context.htmlNode.appendChild(child); + context.htmlNode.appendChild(context.doc.createTextNode("\n")); + } else { + context.headNode.appendChild(child); + context.headNode.appendChild(context.doc.createTextNode("\n")); + } + TodoElement it + = TodoElement.getTodoElement((Element)child, this.context, + new DamlOptions()); + toProcess.add(it); + } else if ( child.getNodeType() == Node.TEXT_NODE + || child.getNodeType() == Node.CDATA_SECTION_NODE ) { + if ( ! Pattern.matches("^\\s*$",((CharacterData)child).getData()) ) + throw new Error("daml element cannot contain text"); + } + } + this.ownerDeque.registerAtStart(toProcess); + } + +} -- cgit v1.2.3