diff options
Diffstat (limited to 'org/madore/damlengine/TodoStyleOrScript.java')
-rw-r--r-- | org/madore/damlengine/TodoStyleOrScript.java | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/org/madore/damlengine/TodoStyleOrScript.java b/org/madore/damlengine/TodoStyleOrScript.java index 44741e4..553366d 100644 --- a/org/madore/damlengine/TodoStyleOrScript.java +++ b/org/madore/damlengine/TodoStyleOrScript.java @@ -2,7 +2,7 @@ package org.madore.damlengine; import org.w3c.dom.*; -public final class TodoStyleOrScript extends TodoItem { +public final class TodoStyleOrScript extends TodoDefaultElement { public enum Type { STYLE("style", "text/css", "/* ", " */\n"), @@ -20,31 +20,85 @@ public final class TodoStyleOrScript extends TodoItem { } } + public static class Factory extends TodoElement.Factory { + final Type t; + public Factory(Type t) { + super(); + this.t = t; + } + @Override + public TodoStyleOrScript newItem(Element node, + Context ctx, + TodoItem caller) { + return new TodoStyleOrScript(t, node, ctx, caller); + } + } + final Type t; + final CharSequence useThisContent; + + public TodoStyleOrScript(Type t, + Element node, + Context ctx, + TodoItem caller, + CharSequence useThisContent) { + super(node, ctx, caller); + this.t = t; + this.useThisContent = useThisContent; + } + public TodoStyleOrScript(Type t, + Element node, Context ctx, TodoItem caller) { - super(ctx, caller); + super(node, ctx, caller); this.t = t; + this.useThisContent = null; } @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")); + public void handleNodeOnly() { + String content; + if ( useThisContent != null ) + content = useThisContent.toString(); + else + content = node.getTextContent(); + while ( node.getLastChild() != null ) { + node.removeChild(node.getLastChild()); + } 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)); } + public static final class HeadStyleOrScript extends TodoItem { + + final Type t; + + public HeadStyleOrScript(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")); + StringBuffer content + = (t==Type.SCRIPT)?ctx.gc.scriptContent:ctx.gc.styleContent; + this.ownerDeque. + registerAtStart(new TodoStyleOrScript(t, node, this.ctx, this, + content)); + } + + } + } |