From 9d602700ed1eae5ce4b443f5182e1a15e4875da2 Mon Sep 17 00:00:00 2001
From: "David A. Madore" <david+git@madore.org>
Date: Sun, 18 Apr 2010 22:27:13 +0200
Subject: Handle <body> element.

---
 org/madore/damlengine/TodoBodyElement.java | 77 ++++++++++++++++++++++++++++++
 org/madore/damlengine/TodoElement.java     |  1 +
 2 files changed, 78 insertions(+)
 create mode 100644 org/madore/damlengine/TodoBodyElement.java

(limited to 'org/madore/damlengine')

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;
-- 
cgit v1.2.3