diff options
Diffstat (limited to 'org/madore/damlengine/TodoTitleElement.java')
-rw-r--r-- | org/madore/damlengine/TodoTitleElement.java | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/org/madore/damlengine/TodoTitleElement.java b/org/madore/damlengine/TodoTitleElement.java index 877e719..9854f1a 100644 --- a/org/madore/damlengine/TodoTitleElement.java +++ b/org/madore/damlengine/TodoTitleElement.java @@ -20,23 +20,52 @@ public final class TodoTitleElement extends TodoDefaultElement { super(node, ctx, caller); } + public class TodoAgain extends TodoItem { + /* Make this a member class (i.e., not "static") so we can + * access the "node" field of the container class. Another + * option would have been to create a new subclass of + * TodoElement and initialize it on the same node: which is + * better? */ + public TodoAgain(Context ctx, TodoItem caller) { + super(ctx, caller); + } + @Override + public void handle() { + assert(this.ctx == TodoTitleElement.this.ctx); + assert(this.caller == TodoTitleElement.this); + if ( ctx.gc.title != null ) + throw new IllegalArgumentException("attempting to redefine title"); + ctx.gc.title = ctx.doc.createDocumentFragment(); + ctx.gc.titleStr = node.getTextContent(); + ctx.gc.titleLang = LangHelper.getLangRec(node); + String lang = LangHelper.getLangNorec(node); + ArrayList<Node> childList = getChildList(node); + for ( Node child : childList ) { + ctx.gc.title.appendChild(child); + } + Element tit = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "title"); + if ( lang != null ) + LangHelper.setLangNorec(tit, lang); + node.getParentNode().replaceChild(tit, node); + tit.appendChild(ctx.doc.createTextNode(ctx.gc.titleStr)); + } + } + @Override public void handleNodeOnly() { - if ( ctx.gc.title != null ) - throw new IllegalArgumentException("attempting to redefine title"); - ctx.gc.title = ctx.doc.createDocumentFragment(); - ctx.gc.titleStr = node.getTextContent(); - ctx.gc.titleLang = LangHelper.getLangRec(node); - String lang = LangHelper.getLangNorec(node); - ArrayList<Node> childList = getChildList(node); + // First process the children, then come back to processing + // title, so we can extract the text content after replacement. + ArrayList<Node> childList = getChildList(this.node); + ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()); for ( Node child : childList ) { - ctx.gc.title.appendChild(child); + if ( child.getNodeType() == Node.ELEMENT_NODE ) { + TodoElement it + = TodoElement.getTodoElement((Element)child, this.ctx, this); + toProcess.add(it); + } } - Element tit = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "title"); - if ( lang != null ) - LangHelper.setLangNorec(tit, lang); - node.getParentNode().replaceChild(tit, node); - tit.appendChild(ctx.doc.createTextNode(ctx.gc.titleStr)); + this.ownerDeque.registerAtStart(new TodoAgain(ctx, this)); + this.ownerDeque.registerAtStart(toProcess); } } |