summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-18 22:27:13 +0200
committerDavid A. Madore <david+git@madore.org>2010-04-18 22:27:13 +0200
commit9d602700ed1eae5ce4b443f5182e1a15e4875da2 (patch)
tree3bc427c281a927296a9fb63e91cdee75f5c21b3a
parent876a83c647bfa499323a14d1cd08a4690eef5a34 (diff)
downloaddamlengine-9d602700ed1eae5ce4b443f5182e1a15e4875da2.tar.gz
damlengine-9d602700ed1eae5ce4b443f5182e1a15e4875da2.tar.bz2
damlengine-9d602700ed1eae5ce4b443f5182e1a15e4875da2.zip
Handle <body> element.
-rw-r--r--org/madore/damlengine/TodoBodyElement.java77
-rw-r--r--org/madore/damlengine/TodoElement.java1
2 files changed, 78 insertions, 0 deletions
diff --git a/org/madore/damlengine/TodoBodyElement.java b/org/madore/damlengine/TodoBodyElement.java
new file mode 100644
index 0000000..c2be164
--- /dev/null
+++ b/org/madore/damlengine/TodoBodyElement.java
@@ -0,0 +1,77 @@
+package org.madore.damlengine;
+
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+import org.w3c.dom.*;
+
+public class TodoBodyElement extends TodoDefaultElement {
+
+ public static class Factory extends TodoElement.Factory {
+ public TodoBodyElement newItem(Element node,
+ Context ctx,
+ TodoItem.Options options) {
+ return new TodoBodyElement(node, ctx, options);
+ }
+ }
+
+ public TodoBodyElement(Element node,
+ Context ctx,
+ TodoItem.Options options) {
+ super(node, ctx, options);
+ }
+
+ public void handleNodeOnly() {
+ if ( ! ( options instanceof TodoDamlElement.DamlOptions ) )
+ throw new Error("body node can only be child of daml node");
+
+ Element bodyNode = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "body");
+ String lang = LangHelper.getLangNorec(node);
+ if ( lang != null )
+ LangHelper.setLangNorec(bodyNode, lang);
+ bodyNode.setAttributeNS(null, "onload", "onLoad()");
+ node.getParentNode().replaceChild(bodyNode, node);
+
+ ArrayList<Node> childList = getChildList(this.node);
+ ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()+8);
+ if ( node.getAttributeNS(null, "nonavbar").equals("") ) {
+ Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS,
+ "d:implicit-do-navbar");
+ bodyNode.appendChild(ctx.doc.createTextNode("\n"));
+ bodyNode.appendChild(token);
+ // toProcess.add(new TodoNavbar(token, this.ctx,
+ // new TodoItem.Options()));
+ }
+ if ( node.getAttributeNS(null, "notranslations").equals("") ) {
+ Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS,
+ "d:implicit-do-translations");
+ bodyNode.appendChild(ctx.doc.createTextNode("\n"));
+ bodyNode.appendChild(token);
+ // toProcess.add(new TodoTranslations(token, this.ctx,
+ // new TodoItem.Options()));
+ }
+ 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 Error("body element cannot contain text");
+ }
+ bodyNode.appendChild(child);
+ if ( child.getNodeType() == Node.ELEMENT_NODE ) {
+ TodoElement it
+ = TodoElement.getTodoElement((Element)child, this.ctx,
+ new TodoItem.Options());
+ toProcess.add(it);
+ }
+ }
+ if ( node.getAttributeNS(null, "nofooter").equals("") ) {
+ Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS,
+ "d:implicit-do-footer");
+ bodyNode.appendChild(token);
+ bodyNode.appendChild(ctx.doc.createTextNode("\n"));
+ // toProcess.add(new TodoFooter(token, this.ctx,
+ // new TodoItem.Options()));
+ }
+ this.ownerDeque.registerAtStart(toProcess);
+ }
+
+}
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index 279b65b..3cb07de 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -19,6 +19,7 @@ public abstract class TodoElement extends TodoItem {
damlFactories = new HashMap<String,Factory>();
damlDefaultFactory = new TodoDefaultElement.Factory();
damlFactories.put("daml", new TodoDamlElement.Factory());
+ damlFactories.put("body", new TodoBodyElement.Factory());
}
Element node;