summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoStyleOrScript.java
blob: 57aefba6a0b196024ebaa34205d268bb0df77391 (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
package org.madore.damlengine;

import org.w3c.dom.*;

public class TodoStyleOrScript extends TodoItem {

    public enum Type { STYLE, SCRIPT }

    Type t;

    public TodoStyleOrScript(Type t,
			     Context ctx,
			     TodoItem caller) {
	super(ctx, caller);
	this.t = t;
    }

    public void handle() {
	if ( ctx.headNode == null )
	    throw new IllegalArgumentException("head node is null when doing style or script");
	Element node
	    = ctx.doc.createElementNS(DamlEngine.XHTML_NS,
				      (t==Type.SCRIPT)?"script":"style");
	node.setAttributeNS(null, "type",
			    (t==Type.SCRIPT)?"text/javascript":"text/css");
	if ( t==Type.SCRIPT )
	    node.setAttributeNS(null, "defer", "defer");
	ctx.headNode.appendChild(node);
	ctx.headNode.appendChild(ctx.doc.createTextNode("\n"));
	node.appendChild(ctx.doc.
			 createTextNode((t==Type.SCRIPT)?"\n// ":"\n/* "));
	StringBuffer content = (t==Type.SCRIPT)?ctx.scriptContent:ctx.styleContent;
	node.appendChild(ctx.doc.
			 createCDATASection(((t==Type.SCRIPT)?"\n":" */\n")
					    +content
					    +((t==Type.SCRIPT)?"// ":"/* ")));
	node.appendChild(ctx.doc.
			 createTextNode((t==Type.SCRIPT)?"\n":" */\n"));
    }

}