summaryrefslogtreecommitdiffstats
path: root/org
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-05-01 20:54:11 +0200
committerDavid A. Madore <david+git@madore.org>2011-05-01 20:54:11 +0200
commitd0aff8ce86b968cb9add39facad924385fafa292 (patch)
tree14357d5c48f77264f1a1d799d7b874330f1176ad /org
parentf33bb94503c9a7acfdb4fd00594e3985a3e1979b (diff)
downloaddamlengine-d0aff8ce86b968cb9add39facad924385fafa292.tar.gz
damlengine-d0aff8ce86b968cb9add39facad924385fafa292.tar.bz2
damlengine-d0aff8ce86b968cb9add39facad924385fafa292.zip
Handle <title> element for weblog entries.
Diffstat (limited to 'org')
-rw-r--r--org/madore/damlengine/TodoElement.java6
-rw-r--r--org/madore/damlengine/TodoEntryTitleElement.java46
2 files changed, 50 insertions, 2 deletions
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);
+ }
+
+}