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")); } }