From 29e1d0cef40d41fd262fedd8b023d341b53259f0 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 1 May 2011 01:00:00 +0200 Subject: (Temporary!) support for element. --- org/madore/damlengine/TodoElement.java | 1 + org/madore/damlengine/TodoWeblogElement.java | 48 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 org/madore/damlengine/TodoWeblogElement.java diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index 8db448c..7449ea3 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -33,6 +33,7 @@ public abstract class TodoElement extends TodoItem { damlDefaultFactory = new TodoDefaultElement.Factory(); damlFactories.put("daml", new TodoDamlElement.Factory()); damlFactories.put("body", new TodoBodyElement.Factory()); + damlFactories.put("weblog", new TodoWeblogElement.Factory()); damlFactories.put("title", new TitleDisambiguationFactory()); damlFactories.put("subtitle", new TodoSubtitleElement.Factory()); damlFactories.put("translation", new TodoTranslationElement.Factory()); diff --git a/org/madore/damlengine/TodoWeblogElement.java b/org/madore/damlengine/TodoWeblogElement.java new file mode 100644 index 0000000..2b42820 --- /dev/null +++ b/org/madore/damlengine/TodoWeblogElement.java @@ -0,0 +1,48 @@ +package org.madore.damlengine; + +import java.util.ArrayList; +import java.util.regex.Pattern; +import org.w3c.dom.*; + +public final class TodoWeblogElement extends TodoDefaultElement { + + public static class Factory extends TodoElement.Factory { + @Override + public TodoWeblogElement newItem(Element node, + Context ctx, + TodoItem caller) { + return new TodoWeblogElement(node, ctx, caller); + } + } + + public TodoWeblogElement(Element node, + Context ctx, + TodoItem caller) { + super(node, ctx, caller); + } + + @Override + public void handleNodeOnly() { + Node parent = node.getParentNode(); + String lang = LangHelper.getLangNorec(node); + ArrayList childList = getChildList(this.node); + ArrayList toProcess = new ArrayList(childList.size()+8); + 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("weblog element cannot contain text"); + } + parent.insertBefore(child, node); + if ( child.getNodeType() == Node.ELEMENT_NODE ) { + if ( lang != null ) + LangHelper.setLangRec((Element)child, lang); // Dubious + TodoElement it + = TodoElement.getTodoElement((Element)child, this.ctx, this); + toProcess.add(it); + } + } + this.ownerDeque.registerAtStart(toProcess); + } + +} -- cgit v1.2.3