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 parent = (Element)(this.node.getParentNode()); String explicitLang = LangHelper.getLangNorec(this.node); ArrayList childList = getChildList(this.node); ArrayList toProcess = new ArrayList(childList.size()); 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"); } parent.insertBefore(child, node); if ( child.getNodeType() == Node.ELEMENT_NODE ) { if ( explicitLang != null ) LangHelper.setWeakLangNorec((Element)child, explicitLang); TodoElement it = TodoElement.getTodoElement((Element)child, this.ctx, this); toProcess.add(it); } } parent.removeChild(node); this.ownerDeque.registerAtStart(toProcess); } }