From 58e0ddcdc2b5d47db753868b3cc937bbac59ec55 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Wed, 7 Sep 2011 14:21:29 +0200 Subject: Move body handling (header, footer, etc.) to the element. The element is now sort of useless. --- org/madore/damlengine/TodoDamlElement.java | 96 ++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 24 deletions(-) (limited to 'org/madore/damlengine/TodoDamlElement.java') diff --git a/org/madore/damlengine/TodoDamlElement.java b/org/madore/damlengine/TodoDamlElement.java index 10696f1..5237d91 100644 --- a/org/madore/damlengine/TodoDamlElement.java +++ b/org/madore/damlengine/TodoDamlElement.java @@ -36,22 +36,28 @@ public final class TodoDamlElement extends TodoDefaultElement { if ( node.hasAttributeNS(null, fileNameName) ) ctx.gc.fileName = node.getAttributeNS(null, fileNameName); + Element htmlNode = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "html"); if ( ctx.gc.htmlNode != null ) throw new IllegalStateException("html node already defined at daml node"); - ctx.gc.htmlNode = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "html"); + ctx.gc.htmlNode = htmlNode; String lang = LangHelper.getLangNorec(node); if ( lang != null ) - LangHelper.setLangNorec(ctx.gc.htmlNode, lang); - node.getParentNode().replaceChild(ctx.gc.htmlNode, node); - ctx.gc.htmlNode.appendChild(ctx.doc.createTextNode("\n")); - ctx.gc.htmlNode.appendChild(ctx.doc.createComment(" This file is automatically generated. Do not edit! ")); - ctx.gc.htmlNode.appendChild(ctx.doc.createTextNode("\n")); + LangHelper.setLangNorec(htmlNode, lang); + node.getParentNode().replaceChild(htmlNode, node); + htmlNode.appendChild(ctx.doc.createTextNode("\n")); + htmlNode.appendChild(ctx.doc.createComment(" This file is automatically generated. Do not edit! ")); + htmlNode.appendChild(ctx.doc.createTextNode("\n")); + Element headNode = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "head"); if ( ctx.gc.headNode != null ) throw new IllegalStateException("head node already defined at daml node"); - ctx.gc.headNode = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "head"); - ctx.gc.htmlNode.appendChild(ctx.gc.headNode); - ctx.gc.htmlNode.appendChild(ctx.doc.createTextNode("\n")); - ctx.gc.headNode.appendChild(ctx.doc.createTextNode("\n")); + ctx.gc.headNode = headNode; + htmlNode.appendChild(headNode); + htmlNode.appendChild(ctx.doc.createTextNode("\n")); + headNode.appendChild(ctx.doc.createTextNode("\n")); + Element bodyNode = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "body"); + htmlNode.appendChild(bodyNode); + htmlNode.appendChild(ctx.doc.createTextNode("\n")); + bodyNode.setAttributeNS(null, "onload", "onLoad()"); ctx.gc.styleContent = new StringBuffer(); try { @@ -77,37 +83,79 @@ public final class TodoDamlElement extends TodoDefaultElement { Element meta; meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "meta"); meta.setAttributeNS(null, "charset", "utf-8"); - ctx.gc.headNode.appendChild(meta); - ctx.gc.headNode.appendChild(ctx.doc.createTextNode("\n")); + headNode.appendChild(meta); + headNode.appendChild(ctx.doc.createTextNode("\n")); meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "link"); meta.setAttributeNS(null, "rel", "Shortcut Icon"); meta.setAttributeNS(null, "href", (((ctx.gc.uriToTop!=null)?ctx.gc.uriToTop:"") +"favicon.ico")); - ctx.gc.headNode.appendChild(meta); - ctx.gc.headNode.appendChild(ctx.doc.createTextNode("\n")); + headNode.appendChild(meta); + headNode.appendChild(ctx.doc.createTextNode("\n")); ArrayList childList = getChildList(this.node); - ArrayList toProcess = new ArrayList(childList.size()); + ArrayList toProcessFirst = new ArrayList(); + ArrayList toProcess = new ArrayList(childList.size()+8); + if ( node.getAttributeNS(null, "notitle").equals("") ) { + Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS, + "d:implicit-do-title"); + bodyNode.appendChild(ctx.doc.createTextNode("\n")); + bodyNode.appendChild(token); + toProcess.add(new TodoTitleOrSubtitle(TodoTitleOrSubtitle.Type.TITLE, + token, this.ctx, this)); + } + if ( node.getAttributeNS(null, "nosubtitle").equals("") ) { + Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS, + "d:implicit-do-subtitle"); + bodyNode.appendChild(ctx.doc.createTextNode("\n")); + bodyNode.appendChild(token); + toProcess.add(new TodoTitleOrSubtitle(TodoTitleOrSubtitle.Type.SUBTITLE, + token, this.ctx, this)); + } + if ( node.getAttributeNS(null, "nonavbar").equals("") ) { + Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS, + "d:implicit-do-navbar"); + bodyNode.appendChild(ctx.doc.createTextNode("\n")); + bodyNode.appendChild(token); + toProcess.add(new TodoNavbar(token, this.ctx, this)); + } + if ( node.getAttributeNS(null, "notranslations").equals("") ) { + Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS, + "d:implicit-do-translations"); + bodyNode.appendChild(ctx.doc.createTextNode("\n")); + bodyNode.appendChild(token); + toProcess.add(new TodoTranslations(token, this.ctx, this)); + } for ( Node child : childList ) { if ( child.getNodeType() == Node.ELEMENT_NODE ) { - if ( child.getLocalName().equals("body") ) { - ctx.gc.htmlNode.appendChild(ctx.doc.createTextNode("\n")); - ctx.gc.htmlNode.appendChild(child); - ctx.gc.htmlNode.appendChild(ctx.doc.createTextNode("\n")); + if ( child.getLocalName().equals("body") + || child.getLocalName().equals("weblog") ) { + bodyNode.appendChild(child); + bodyNode.appendChild(ctx.doc.createTextNode("\n")); + TodoElement it + = TodoElement.getTodoElement((Element)child, this.ctx, this); + toProcess.add(it); } else { - ctx.gc.headNode.appendChild(child); - ctx.gc.headNode.appendChild(ctx.doc.createTextNode("\n")); + headNode.appendChild(child); + headNode.appendChild(ctx.doc.createTextNode("\n")); + TodoElement it + = TodoElement.getTodoElement((Element)child, this.ctx, this); + toProcessFirst.add(it); } - TodoElement it - = TodoElement.getTodoElement((Element)child, this.ctx, this); - 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 IllegalArgumentException("daml element cannot contain text"); } } + if ( node.getAttributeNS(null, "nofooter").equals("") ) { + Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS, + "d:implicit-do-footer"); + bodyNode.appendChild(token); + bodyNode.appendChild(ctx.doc.createTextNode("\n")); + toProcess.add(new TodoFooter(token, this.ctx, this)); + } this.ownerDeque.registerAtStart(toProcess); + this.ownerDeque.registerAtStart(toProcessFirst); this.ownerDeque. registerAtEnd(new TodoStyleOrScript(TodoStyleOrScript.Type.STYLE, this.ctx, this)); -- cgit v1.2.3