summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-18 21:58:49 +0200
committerDavid A. Madore <david+git@madore.org>2010-04-18 21:58:49 +0200
commit876a83c647bfa499323a14d1cd08a4690eef5a34 (patch)
tree945c604d1f509bedcb35224c60c965a13ebae46d
parent99cea43742283d7bc383021ebd52087115448159 (diff)
downloaddamlengine-876a83c647bfa499323a14d1cd08a4690eef5a34.tar.gz
damlengine-876a83c647bfa499323a14d1cd08a4690eef5a34.tar.bz2
damlengine-876a83c647bfa499323a14d1cd08a4690eef5a34.zip
A handful of meta tags, script and style sections.
-rw-r--r--org/madore/damlengine/Context.java2
-rw-r--r--org/madore/damlengine/TodoDamlElement.java29
-rw-r--r--org/madore/damlengine/TodoStyleOrScript.java41
3 files changed, 72 insertions, 0 deletions
diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java
index cbb2c3e..2545f32 100644
--- a/org/madore/damlengine/Context.java
+++ b/org/madore/damlengine/Context.java
@@ -9,6 +9,8 @@ public class Context {
public Element headNode;
public String uriToTop;
public String fileName;
+ public StringBuffer styleContent;
+ public StringBuffer scriptContent;
public Context(Document doc) {
this.doc = doc;
diff --git a/org/madore/damlengine/TodoDamlElement.java b/org/madore/damlengine/TodoDamlElement.java
index fefd0f1..330c92d 100644
--- a/org/madore/damlengine/TodoDamlElement.java
+++ b/org/madore/damlengine/TodoDamlElement.java
@@ -50,6 +50,29 @@ public class TodoDamlElement extends TodoDefaultElement {
ctx.htmlNode.appendChild(ctx.doc.createTextNode("\n"));
ctx.headNode.appendChild(ctx.doc.createTextNode("\n"));
+ ctx.styleContent = new StringBuffer();
+ ctx.scriptContent = new StringBuffer();
+
+ Element meta;
+ meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "meta");
+ meta.setAttributeNS(null, "http-equiv", "Content-Type");
+ meta.setAttributeNS(null, "content", "text/html; charset=utf-8");
+ ctx.headNode.appendChild(meta);
+ ctx.headNode.appendChild(ctx.doc.createTextNode("\n"));
+ if ( lang != null ) {
+ meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "meta");
+ meta.setAttributeNS(null, "http-equiv", "Content-Language");
+ meta.setAttributeNS(null, "content", lang);
+ ctx.headNode.appendChild(meta);
+ ctx.headNode.appendChild(ctx.doc.createTextNode("\n"));
+ }
+ meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "link");
+ meta.setAttributeNS(null, "rel", "Shortcut Icon");
+ meta.setAttributeNS(null, "href", (((uriToTop!=null)?uriToTop:"")
+ +"favicon.ico"));
+ ctx.headNode.appendChild(meta);
+ ctx.headNode.appendChild(ctx.doc.createTextNode("\n"));
+
ArrayList<Node> childList = getChildList(this.node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size());
for ( Node child : childList ) {
@@ -73,6 +96,12 @@ public class TodoDamlElement extends TodoDefaultElement {
}
}
this.ownerDeque.registerAtStart(toProcess);
+ this.ownerDeque.
+ registerAtEnd(new TodoStyleOrScript(TodoStyleOrScript.Type.STYLE,
+ this.ctx, new DamlOptions()));
+ this.ownerDeque.
+ registerAtEnd(new TodoStyleOrScript(TodoStyleOrScript.Type.SCRIPT,
+ this.ctx, new DamlOptions()));
}
}
diff --git a/org/madore/damlengine/TodoStyleOrScript.java b/org/madore/damlengine/TodoStyleOrScript.java
new file mode 100644
index 0000000..7b06955
--- /dev/null
+++ b/org/madore/damlengine/TodoStyleOrScript.java
@@ -0,0 +1,41 @@
+package org.madore.damlengine;
+
+import org.w3c.dom.*;
+
+public class TodoStyleOrScript extends TodoItem {
+
+ public enum Type { STYLE, SCRIPT }
+
+ Type t;
+
+ public TodoStyleOrScript(Type t,
+ Context ctx,
+ TodoItem.Options options) {
+ super(ctx, options);
+ this.t = t;
+ }
+
+ public void handle() {
+ if ( ctx.headNode == null )
+ throw new Error("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");
+ 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((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"));
+ }
+
+}