summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoStyleOrScript.java
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-10-02 17:07:55 +0200
committerDavid A. Madore <david+git@madore.org>2011-10-02 17:07:55 +0200
commit16f86e7bf5f22806c2a64f9a9bc501a2f13e72e5 (patch)
tree2c0953f87fd023dad6a61707b7d69dee2e6863bf /org/madore/damlengine/TodoStyleOrScript.java
parent6e0587364ea813c1762a313feed942ff68e18e58 (diff)
downloaddamlengine-16f86e7bf5f22806c2a64f9a9bc501a2f13e72e5.tar.gz
damlengine-16f86e7bf5f22806c2a64f9a9bc501a2f13e72e5.tar.bz2
damlengine-16f86e7bf5f22806c2a64f9a9bc501a2f13e72e5.zip
Handle HTML <style> and <script> elements by adding CDATA sections as appropriate.
Previously, only the (automatically inserted) <style> and <script> elements in the HTML <head> were handled this way. This now extends to these elements anywhere in the document.
Diffstat (limited to 'org/madore/damlengine/TodoStyleOrScript.java')
-rw-r--r--org/madore/damlengine/TodoStyleOrScript.java78
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));
+ }
+
+ }
+
}