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