diff options
Diffstat (limited to 'org/madore/damlengine/TodoStyleOrScript.java')
-rw-r--r-- | org/madore/damlengine/TodoStyleOrScript.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/org/madore/damlengine/TodoStyleOrScript.java b/org/madore/damlengine/TodoStyleOrScript.java new file mode 100644 index 0000000..7b06955 --- /dev/null +++ b/org/madore/damlengine/TodoStyleOrScript.java @@ -0,0 +1,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.Options options) { + super(ctx, options); + this.t = t; + } + + public void handle() { + if ( ctx.headNode == null ) + throw new Error("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")); + } + +} |