From 876a83c647bfa499323a14d1cd08a4690eef5a34 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 18 Apr 2010 21:58:49 +0200 Subject: A handful of meta tags, script and style sections. --- org/madore/damlengine/Context.java | 2 ++ org/madore/damlengine/TodoDamlElement.java | 29 ++++++++++++++++++++ org/madore/damlengine/TodoStyleOrScript.java | 41 ++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 org/madore/damlengine/TodoStyleOrScript.java (limited to 'org/madore/damlengine') 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 childList = getChildList(this.node); ArrayList toProcess = new ArrayList(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")); + } + +} -- cgit v1.2.3