From c1aa7509008d3aaa4afa9ceb3c3e029b9542f75a Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Thu, 8 Sep 2011 15:53:31 +0200 Subject: Improve title of weblog pages. --- org/madore/damlengine/TodoTitleElement.java | 55 ++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 13 deletions(-) (limited to 'org/madore/damlengine/TodoTitleElement.java') 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 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 childList = getChildList(node); + // First process the children, then come back to processing + // title, so we can extract the text content after replacement. + ArrayList childList = getChildList(this.node); + ArrayList toProcess = new ArrayList(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); } } -- cgit v1.2.3