From 5acce829dc6ded492cca5ec87cd8bdbdb81667a5 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Wed, 7 Sep 2011 12:37:42 +0200 Subject: Try to produce HTML5/XHTML5 (polyglot) output. --- org/madore/damlengine/DamlEngine.java | 2 +- org/madore/damlengine/TodoDamlElement.java | 10 +--- org/madore/damlengine/TodoElement.java | 18 ++++--- org/madore/damlengine/TodoKillAcronymElement.java | 58 +++++++++++++++++++++++ org/madore/damlengine/TodoStyleOrScript.java | 2 - org/madore/damlengine/TodoTitleElement.java | 10 ---- org/madore/damlengine/Unparser.java | 2 +- 7 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 org/madore/damlengine/TodoKillAcronymElement.java diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java index 7bc81bd..c24ea33 100644 --- a/org/madore/damlengine/DamlEngine.java +++ b/org/madore/damlengine/DamlEngine.java @@ -138,7 +138,7 @@ public final class DamlEngine { doc.normalizeDocument(); Unparser unparser = new Unparser(doc, new OutputStreamWriter(out, "UTF-8"), - "html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); + "html"); unparser.unparse(); } diff --git a/org/madore/damlengine/TodoDamlElement.java b/org/madore/damlengine/TodoDamlElement.java index 31e7357..10696f1 100644 --- a/org/madore/damlengine/TodoDamlElement.java +++ b/org/madore/damlengine/TodoDamlElement.java @@ -76,17 +76,9 @@ public final class TodoDamlElement extends TodoDefaultElement { 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"); + meta.setAttributeNS(null, "charset", "utf-8"); ctx.gc.headNode.appendChild(meta); ctx.gc.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.gc.headNode.appendChild(meta); - ctx.gc.headNode.appendChild(ctx.doc.createTextNode("\n")); - } meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "link"); meta.setAttributeNS(null, "rel", "Shortcut Icon"); meta.setAttributeNS(null, "href", (((ctx.gc.uriToTop!=null)?ctx.gc.uriToTop:"") diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index 7df38c9..ee1a90f 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -28,11 +28,11 @@ public abstract class TodoElement extends TodoItem { } protected final static Map damlFactories; - protected final static Factory damlDefaultFactory; + protected final static Factory defaultFactory; static { damlFactories = new HashMap(); - damlDefaultFactory = new TodoDefaultElement.Factory(); + defaultFactory = new TodoDefaultElement.Factory(); damlFactories.put("daml", new TodoDamlElement.Factory()); damlFactories.put("body", new TodoBodyElement.Factory()); damlFactories.put("weblog", new TodoWeblogElement.Factory()); @@ -72,6 +72,9 @@ public abstract class TodoElement extends TodoItem { protected final static Factory killAFactory = new TodoKillAElement.Factory(); + protected final static Factory killAcronymFactory + = new TodoKillAcronymElement.Factory(); + protected final Element node; public TodoElement(Element node, @@ -88,11 +91,14 @@ public abstract class TodoElement extends TodoItem { String nsuri = node.getNamespaceURI(); if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) ) factory = damlFactories.get(node.getLocalName()); - else if ( nsuri != null && nsuri.equals(DamlEngine.XHTML_NS) - && ctx.killA && node.getLocalName().equals("a") ) - factory = killAFactory; + else if ( nsuri != null && nsuri.equals(DamlEngine.XHTML_NS) ) { + if ( ctx.killA && node.getLocalName().equals("a") ) + factory = killAFactory; + else if ( node.getLocalName().equals("acronym") ) + factory = killAcronymFactory; + } if ( factory == null ) - factory = damlDefaultFactory; + factory = defaultFactory; return factory.newItem(node, ctx, caller); } diff --git a/org/madore/damlengine/TodoKillAcronymElement.java b/org/madore/damlengine/TodoKillAcronymElement.java new file mode 100644 index 0000000..65664e9 --- /dev/null +++ b/org/madore/damlengine/TodoKillAcronymElement.java @@ -0,0 +1,58 @@ +package org.madore.damlengine; + +import java.util.ArrayList; +import org.w3c.dom.*; + +public final class TodoKillAcronymElement extends TodoDefaultElement { + + public static class Factory extends TodoElement.Factory { + @Override + public TodoKillAcronymElement newItem(Element node, + Context ctx, + TodoItem caller) { + return new TodoKillAcronymElement(node, ctx, caller); + } + } + + public TodoKillAcronymElement(Element node, + Context ctx, + TodoItem caller) { + super(node, ctx, caller); + } + + @Override + public void handleNodeOnly() { + Element newNode = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "abbr"); + if ( node.hasAttributeNS(null, "class") ) + newNode.setAttributeNS(null, "class", + "acronym "+node.getAttributeNS(null, "class")); + else + newNode.setAttributeNS(null, "class", "acronym"); + String lang = LangHelper.getLangNorec(node); + if ( lang != null ) + LangHelper.setLangNorec(newNode, lang); + ArrayList attrList = getAttrList(this.node); + for ( Attr attr : attrList ) { + if ( attr.getNamespaceURI() == null ) { + String attName = attr.getLocalName(); + if ( attName.equals("class") ) + continue; + node.removeAttributeNode(attr); + newNode.setAttributeNodeNS(attr); + } + } + ArrayList childList = getChildList(node); + ArrayList toProcess = new ArrayList(childList.size()); + node.getParentNode().replaceChild(newNode, node); + for ( Node child : childList ) { + newNode.appendChild(child); + if ( child.getNodeType() == Node.ELEMENT_NODE ) { + TodoElement it + = TodoElement.getTodoElement((Element)child, this.ctx, this); + toProcess.add(it); + } + } + this.ownerDeque.registerAtStart(toProcess); + } + +} diff --git a/org/madore/damlengine/TodoStyleOrScript.java b/org/madore/damlengine/TodoStyleOrScript.java index cc00e11..44741e4 100644 --- a/org/madore/damlengine/TodoStyleOrScript.java +++ b/org/madore/damlengine/TodoStyleOrScript.java @@ -36,8 +36,6 @@ public final class TodoStyleOrScript extends TodoItem { Element node = ctx.doc.createElementNS(DamlEngine.XHTML_NS, t.eltName); node.setAttributeNS(null, "type", t.mimeType); - if ( t==Type.SCRIPT ) - node.setAttributeNS(null, "defer", "defer"); ctx.gc.headNode.appendChild(node); ctx.gc.headNode.appendChild(ctx.doc.createTextNode("\n")); node.appendChild(ctx.doc.createTextNode("\n"+t.preCdata)); diff --git a/org/madore/damlengine/TodoTitleElement.java b/org/madore/damlengine/TodoTitleElement.java index bfa1949..877e719 100644 --- a/org/madore/damlengine/TodoTitleElement.java +++ b/org/madore/damlengine/TodoTitleElement.java @@ -37,16 +37,6 @@ public final class TodoTitleElement extends TodoDefaultElement { LangHelper.setLangNorec(tit, lang); node.getParentNode().replaceChild(tit, node); tit.appendChild(ctx.doc.createTextNode(ctx.gc.titleStr)); - Element meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "meta"); - if ( lang != null ) - LangHelper.setLangNorec(meta, lang); - meta.setAttributeNS(null, "name", "Title"); - meta.setAttributeNS(null, "content", ctx.gc.titleStr); - if ( tit.getNextSibling() != null ) - tit.getParentNode().insertBefore(meta, tit.getNextSibling()); - else - tit.getParentNode().appendChild(meta); - tit.getParentNode().insertBefore(ctx.doc.createTextNode("\n"), meta); } } diff --git a/org/madore/damlengine/Unparser.java b/org/madore/damlengine/Unparser.java index 87945c6..36747fc 100644 --- a/org/madore/damlengine/Unparser.java +++ b/org/madore/damlengine/Unparser.java @@ -130,7 +130,7 @@ public final class Unparser { public void unparse() throws IOException { - out.write(""); + // out.write(""); if ( forceDoctype == null ) { DocumentType doctype = doc.getDoctype(); if ( doctype != null ) { -- cgit v1.2.3