summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoStyleOrScript.java
diff options
context:
space:
mode:
Diffstat (limited to 'org/madore/damlengine/TodoStyleOrScript.java')
-rw-r--r--org/madore/damlengine/TodoStyleOrScript.java43
1 files changed, 27 insertions, 16 deletions
diff --git a/org/madore/damlengine/TodoStyleOrScript.java b/org/madore/damlengine/TodoStyleOrScript.java
index 57aefba..dcec137 100644
--- a/org/madore/damlengine/TodoStyleOrScript.java
+++ b/org/madore/damlengine/TodoStyleOrScript.java
@@ -2,11 +2,25 @@ package org.madore.damlengine;
import org.w3c.dom.*;
-public class TodoStyleOrScript extends TodoItem {
+public final class TodoStyleOrScript extends TodoItem {
- public enum Type { STYLE, SCRIPT }
+ 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;
+ }
+ }
- Type t;
+ final Type t;
public TodoStyleOrScript(Type t,
Context ctx,
@@ -15,27 +29,24 @@ public class TodoStyleOrScript extends TodoItem {
this.t = t;
}
+ @Override
public void handle() {
if ( ctx.headNode == null )
- throw new IllegalArgumentException("head node is null when doing style or script");
+ throw new IllegalStateException("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");
+ = ctx.doc.createElementNS(DamlEngine.XHTML_NS, t.eltName);
+ node.setAttributeNS(null, "type", t.mimeType);
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("\n"+t.preCdata));
+ StringBuffer content
+ = (t==Type.SCRIPT)?ctx.scriptContent:ctx.styleContent;
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"));
+ createCDATASection(t.postCdata+content
+ +t.preCdata));
+ node.appendChild(ctx.doc.createTextNode(t.postCdata));
}
}