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
|
package org.madore.damlengine;
import org.w3c.dom.*;
public final class TodoStyleOrScript extends TodoItem {
public enum Type {
STYLE("style", "text/css", "/* ", " */\n"),
SCRIPT("script", "text/javascript", "// ", "\n");
final String eltName;
final String mimeType;
final String preCdata;
final String postCdata;
Type(String eltName, String mimeType,
String preCdata, String postCdata) {
this.eltName = eltName;
this.mimeType = mimeType;
this.preCdata = preCdata;
this.postCdata = postCdata;
}
}
final Type t;
public TodoStyleOrScript(Type t,
Context ctx,
TodoItem caller) {
super(ctx, caller);
this.t = t;
}
@Override
public void handle() {
if ( ctx.gc.headNode == null )
throw new IllegalStateException("head node is null when doing style or script");
Element node
= ctx.doc.createElementNS(DamlEngine.XHTML_NS, t.eltName);
node.setAttributeNS(null, "type", t.mimeType);
ctx.gc.headNode.appendChild(node);
ctx.gc.headNode.appendChild(ctx.doc.createTextNode("\n"));
node.appendChild(ctx.doc.createTextNode("\n"+t.preCdata));
StringBuffer content
= (t==Type.SCRIPT)?ctx.gc.scriptContent:ctx.gc.styleContent;
node.appendChild(ctx.doc.
createCDATASection(t.postCdata+content
+t.preCdata));
node.appendChild(ctx.doc.createTextNode(t.postCdata));
}
}
|