package org.madore.damlengine; import java.util.ArrayList; import java.util.regex.Pattern; import org.w3c.dom.*; public final class TodoBodyElement extends TodoDefaultElement { public static class Factory extends TodoElement.Factory { @Override public TodoBodyElement newItem(Element node, Context ctx, TodoItem caller) { return new TodoBodyElement(node, ctx, caller); } } public TodoBodyElement(Element node, Context ctx, TodoItem caller) { super(node, ctx, caller); } @Override public void handleNodeOnly() { if ( ! ( caller instanceof TodoDamlElement ) ) throw new IllegalArgumentException("body node can only be child of daml node"); Element bodyNode = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "body"); String lang = LangHelper.getLangNorec(node); if ( lang != null ) LangHelper.setLangNorec(bodyNode, lang); bodyNode.setAttributeNS(null, "onload", "onLoad()"); node.getParentNode().replaceChild(bodyNode, node); ArrayList childList = getChildList(this.node); ArrayList toProcess = new ArrayList(childList.size()+8); if ( node.getAttributeNS(null, "notitle").equals("") && ctx.gc.title != null ) { 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("") && ctx.gc.subtitle != null ) { 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("") && ctx.gc.translations != null ) { 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.TEXT_NODE || child.getNodeType() == Node.CDATA_SECTION_NODE ) { if ( ! Pattern.matches("^\\s*$",((CharacterData)child).getData()) ) throw new IllegalArgumentException("body element cannot contain text"); } bodyNode.appendChild(child); if ( child.getNodeType() == Node.ELEMENT_NODE ) { TodoElement it = TodoElement.getTodoElement((Element)child, this.ctx, this); toProcess.add(it); } } 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); } }