From d0aff8ce86b968cb9add39facad924385fafa292 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 1 May 2011 20:54:11 +0200 Subject: Handle element for weblog entries. --- org/madore/damlengine/TodoElement.java | 6 ++-- org/madore/damlengine/TodoEntryTitleElement.java | 46 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 org/madore/damlengine/TodoEntryTitleElement.java (limited to 'org/madore/damlengine') diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index c779e89..462b503 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -14,14 +14,16 @@ public abstract class TodoElement extends TodoItem { public static class TitleDisambiguationFactory extends Factory { Factory mainTitleFactory = new TodoTitleElement.Factory(); - Factory entryTitleFactory = new TodoDefaultElement.Factory(); + Factory entryTitleFactory = new TodoEntryTitleElement.Factory(); public TodoElement newItem(Element node, Context ctx, TodoItem caller) { if ( caller instanceof TodoDamlElement ) return mainTitleFactory.newItem(node, ctx, caller); - else + else if ( caller instanceof TodoEntryElement ) return entryTitleFactory.newItem(node, ctx, caller); + else + throw new IllegalArgumentException("title element can only be child of daml or entry elements"); } } diff --git a/org/madore/damlengine/TodoEntryTitleElement.java b/org/madore/damlengine/TodoEntryTitleElement.java new file mode 100644 index 0000000..26f8670 --- /dev/null +++ b/org/madore/damlengine/TodoEntryTitleElement.java @@ -0,0 +1,46 @@ +package org.madore.damlengine; + +import java.util.ArrayList; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import org.w3c.dom.*; + +public final class TodoEntryTitleElement extends TodoDefaultElement { + + public static class Factory extends TodoElement.Factory { + @Override + public TodoEntryTitleElement newItem(Element node, + Context ctx, + TodoItem caller) { + return new TodoEntryTitleElement(node, ctx, caller); + } + } + + public TodoEntryTitleElement(Element node, + Context ctx, + TodoItem caller) { + super(node, ctx, caller); + } + + @Override + public void handleNodeOnly() { + Element h2 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "h2"); + String explicitLang = LangHelper.getLangNorec(node); + if ( explicitLang != null ) + LangHelper.setLangNorec(h2, explicitLang); + node.getParentNode().replaceChild(h2, node); + h2.setAttributeNS(null, "class", "weblog-entry-title"); + ArrayList<Node> childList = getChildList(this.node); + ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()); + for ( Node child : childList ) { + h2.appendChild(child); + if ( child.getNodeType() == Node.ELEMENT_NODE ) { + TodoElement it + = TodoElement.getTodoElement((Element)child, this.ctx, this); + toProcess.add(it); + } + } + this.ownerDeque.registerAtStart(toProcess); + } + +} -- cgit v1.2.3