summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoBodyElement.java
blob: c2be1647ee200a3eaab6ef577cdc5cf0132d84c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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);
    }

}