summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org/madore/damlengine/Context.java6
-rw-r--r--org/madore/damlengine/TodoBodyElement.java18
-rw-r--r--org/madore/damlengine/TodoDefaultElement.java2
-rw-r--r--org/madore/damlengine/TodoElement.java2
-rw-r--r--org/madore/damlengine/TodoSubtitleElement.java44
-rw-r--r--org/madore/damlengine/TodoTitleElement.java53
-rw-r--r--org/madore/damlengine/TodoTitleOrSubtitle.java46
7 files changed, 170 insertions, 1 deletions
diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java
index 2cb56f9..6321ca2 100644
--- a/org/madore/damlengine/Context.java
+++ b/org/madore/damlengine/Context.java
@@ -12,6 +12,12 @@ public class Context {
public String fileName;
public StringBuffer styleContent;
public StringBuffer scriptContent;
+ public DocumentFragment title;
+ public String titleStr;
+ public String titleLang;
+ public DocumentFragment subtitle;
+ public String subtitleStr;
+ public String subtitleLang;
public ArrayList<String> translations;
public Context(Document doc) {
diff --git a/org/madore/damlengine/TodoBodyElement.java b/org/madore/damlengine/TodoBodyElement.java
index e70bd3b..fd75b89 100644
--- a/org/madore/damlengine/TodoBodyElement.java
+++ b/org/madore/damlengine/TodoBodyElement.java
@@ -35,6 +35,24 @@ public final class TodoBodyElement extends TodoDefaultElement {
ArrayList<Node> childList = getChildList(this.node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()+8);
+ if ( node.getAttributeNS(null, "notitle").equals("")
+ && ctx.title != null ) {
+ Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS,
+ "d:implicit-do-title");
+ bodyNode.appendChild(ctx.doc.createTextNode("\n"));
+ bodyNode.appendChild(token);
+ toProcess.add(new TodoTitleOrSubtitle(TodoTitleOrSubtitle.Type.TITLE,
+ token, this.ctx, this));
+ }
+ if ( node.getAttributeNS(null, "nosubtitle").equals("")
+ && ctx.subtitle != null ) {
+ Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS,
+ "d:implicit-do-subtitle");
+ bodyNode.appendChild(ctx.doc.createTextNode("\n"));
+ bodyNode.appendChild(token);
+ toProcess.add(new TodoTitleOrSubtitle(TodoTitleOrSubtitle.Type.SUBTITLE,
+ token, this.ctx, this));
+ }
if ( node.getAttributeNS(null, "nonavbar").equals("") ) {
Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS,
"d:implicit-do-navbar");
diff --git a/org/madore/damlengine/TodoDefaultElement.java b/org/madore/damlengine/TodoDefaultElement.java
index 7cd9aae..d7a6430 100644
--- a/org/madore/damlengine/TodoDefaultElement.java
+++ b/org/madore/damlengine/TodoDefaultElement.java
@@ -29,7 +29,7 @@ public class TodoDefaultElement extends TodoElement {
return attrList;
}
- public static ArrayList<Node> getChildList(Element node) {
+ public static ArrayList<Node> getChildList(Node node) {
NodeList children = node.getChildNodes();
ArrayList<Node> childList = new ArrayList<Node>(children.getLength());
Node child;
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index 8515688..c8b2d11 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -20,6 +20,8 @@ public abstract class TodoElement extends TodoItem {
damlDefaultFactory = new TodoDefaultElement.Factory();
damlFactories.put("daml", new TodoDamlElement.Factory());
damlFactories.put("body", new TodoBodyElement.Factory());
+ damlFactories.put("title", new TodoTitleElement.Factory());
+ damlFactories.put("subtitle", new TodoSubtitleElement.Factory());
damlFactories.put("translation", new TodoTranslationElement.Factory());
}
diff --git a/org/madore/damlengine/TodoSubtitleElement.java b/org/madore/damlengine/TodoSubtitleElement.java
new file mode 100644
index 0000000..a00a266
--- /dev/null
+++ b/org/madore/damlengine/TodoSubtitleElement.java
@@ -0,0 +1,44 @@
+package org.madore.damlengine;
+
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+import org.w3c.dom.*;
+
+public final class TodoSubtitleElement extends TodoDefaultElement {
+
+ public static class Factory extends TodoElement.Factory {
+ @Override
+ public TodoSubtitleElement newItem(Element node,
+ Context ctx,
+ TodoItem caller) {
+ return new TodoSubtitleElement(node, ctx, caller);
+ }
+ }
+
+ public TodoSubtitleElement(Element node,
+ Context ctx,
+ TodoItem caller) {
+ super(node, ctx, caller);
+ }
+
+ @Override
+ public void handleNodeOnly() {
+ if ( ctx.subtitle != null )
+ throw new IllegalArgumentException("attempting to redefine subtitle");
+ ctx.subtitle = ctx.doc.createDocumentFragment();
+ ctx.subtitleStr = node.getTextContent();
+ ctx.subtitleLang = LangHelper.getLangRec(node);
+ String lang = LangHelper.getLangNorec(node);
+ ArrayList<Node> childList = getChildList(node);
+ for ( Node child : childList ) {
+ ctx.subtitle.appendChild(child);
+ }
+ Node ws = node.getNextSibling();
+ if ( ( ws.getNodeType() == Node.TEXT_NODE
+ || ws.getNodeType() == Node.CDATA_SECTION_NODE )
+ && Pattern.matches("^\\s*$",((CharacterData)ws).getData()) )
+ node.getParentNode().removeChild(ws);
+ node.getParentNode().removeChild(node);
+ }
+
+}
diff --git a/org/madore/damlengine/TodoTitleElement.java b/org/madore/damlengine/TodoTitleElement.java
new file mode 100644
index 0000000..8c28ee9
--- /dev/null
+++ b/org/madore/damlengine/TodoTitleElement.java
@@ -0,0 +1,53 @@
+package org.madore.damlengine;
+
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+import org.w3c.dom.*;
+
+public final class TodoTitleElement extends TodoDefaultElement {
+
+ public static class Factory extends TodoElement.Factory {
+ @Override
+ public TodoTitleElement newItem(Element node,
+ Context ctx,
+ TodoItem caller) {
+ return new TodoTitleElement(node, ctx, caller);
+ }
+ }
+
+ public TodoTitleElement(Element node,
+ Context ctx,
+ TodoItem caller) {
+ super(node, ctx, caller);
+ }
+
+ @Override
+ public void handleNodeOnly() {
+ if ( ctx.title != null )
+ throw new IllegalArgumentException("attempting to redefine title");
+ ctx.title = ctx.doc.createDocumentFragment();
+ ctx.titleStr = node.getTextContent();
+ ctx.titleLang = LangHelper.getLangRec(node);
+ String lang = LangHelper.getLangNorec(node);
+ ArrayList<Node> childList = getChildList(node);
+ for ( Node child : childList ) {
+ ctx.title.appendChild(child);
+ }
+ Element tit = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "title");
+ if ( lang != null )
+ LangHelper.setLangNorec(tit, lang);
+ node.getParentNode().replaceChild(tit, node);
+ tit.appendChild(ctx.doc.createTextNode(ctx.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.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/TodoTitleOrSubtitle.java b/org/madore/damlengine/TodoTitleOrSubtitle.java
new file mode 100644
index 0000000..5e92f41
--- /dev/null
+++ b/org/madore/damlengine/TodoTitleOrSubtitle.java
@@ -0,0 +1,46 @@
+package org.madore.damlengine;
+
+import java.util.ArrayList;
+import org.w3c.dom.*;
+
+public final class TodoTitleOrSubtitle extends TodoElement {
+
+ public enum Type {
+ TITLE("h1","title"),
+ SUBTITLE("p","subtitle");
+ final String eltName;
+ final String eltClass;
+ Type(String eltName, String eltClass) {
+ this.eltName = eltName;
+ this.eltClass = eltClass;
+ }
+ }
+
+ final Type t;
+
+ public TodoTitleOrSubtitle(Type t,
+ Element node,
+ Context ctx,
+ TodoItem caller) {
+ super(node, ctx, caller);
+ this.t = t;
+ }
+
+ @Override
+ public void handle() {
+ Element elt = ctx.doc.createElementNS(DamlEngine.XHTML_NS, t.eltName);
+ String expLang = (t==Type.TITLE)?ctx.titleLang:ctx.subtitleLang;
+ if ( expLang != null )
+ LangHelper.setLangNorec(node, expLang);
+ elt.setAttributeNS(null, "class", t.eltClass);
+ node.getParentNode().replaceChild(elt, node);
+ ArrayList<Node> childList
+ = TodoDefaultElement.getChildList((t==Type.TITLE)?ctx.title:ctx.subtitle);
+ for ( Node child : childList )
+ elt.appendChild(child.cloneNode(true));
+ TodoElement it
+ = TodoElement.getTodoElement(elt, this.ctx, this);
+ this.ownerDeque.registerAtStart(it);
+ }
+
+}