summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org/madore/damlengine/TodoDamlElement.java10
-rw-r--r--org/madore/damlengine/TodoElement.java10
-rw-r--r--org/madore/damlengine/TodoStyleOrScript.java78
3 files changed, 82 insertions, 16 deletions
diff --git a/org/madore/damlengine/TodoDamlElement.java b/org/madore/damlengine/TodoDamlElement.java
index 93275d9..599e49a 100644
--- a/org/madore/damlengine/TodoDamlElement.java
+++ b/org/madore/damlengine/TodoDamlElement.java
@@ -163,11 +163,13 @@ public final class TodoDamlElement extends TodoDefaultElement {
this.ownerDeque.registerAtStart(toProcess);
this.ownerDeque.registerAtStart(toProcessFirst);
this.ownerDeque.
- registerAtEnd(new TodoStyleOrScript(TodoStyleOrScript.Type.STYLE,
- this.ctx, this));
+ registerAtEnd(new TodoStyleOrScript.
+ HeadStyleOrScript(TodoStyleOrScript.Type.STYLE,
+ this.ctx, this));
this.ownerDeque.
- registerAtEnd(new TodoStyleOrScript(TodoStyleOrScript.Type.SCRIPT,
- this.ctx, this));
+ registerAtEnd(new TodoStyleOrScript.
+ HeadStyleOrScript(TodoStyleOrScript.Type.SCRIPT,
+ this.ctx, this));
}
}
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index 12810c0..4f15afa 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -76,6 +76,12 @@ public abstract class TodoElement extends TodoItem {
protected final static Factory killAcronymFactory
= new TodoKillAcronymElement.Factory();
+ protected final static Factory styleFactory
+ = new TodoStyleOrScript.Factory(TodoStyleOrScript.Type.STYLE);
+
+ protected final static Factory scriptFactory
+ = new TodoStyleOrScript.Factory(TodoStyleOrScript.Type.SCRIPT);
+
protected final Element node;
public TodoElement(Element node,
@@ -97,6 +103,10 @@ public abstract class TodoElement extends TodoItem {
factory = killAFactory;
else if ( node.getLocalName().equals("acronym") )
factory = killAcronymFactory;
+ else if ( node.getLocalName().equals("style") )
+ factory = styleFactory;
+ else if ( node.getLocalName().equals("script") )
+ factory = scriptFactory;
}
if ( factory == null )
factory = defaultFactory;
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));
+ }
+
+ }
+
}