summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-18 19:28:58 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-18 19:28:58 +0200
commit9124ad9a07d19753abcb696d04483589c2a45355 (patch)
tree25db743fd5eb6b3c94bd609eeea3ea9ed489310d
parent72c90e8bef113bbbfa944f8a8ce6601d8d44ecfc (diff)
downloaddamlengine-9124ad9a07d19753abcb696d04483589c2a45355.tar.gz
damlengine-9124ad9a07d19753abcb696d04483589c2a45355.tar.bz2
damlengine-9124ad9a07d19753abcb696d04483589c2a45355.zip
Preliminary handler for <daml> element.
-rw-r--r--org/madore/damlengine/DamlEngine.java1
-rw-r--r--org/madore/damlengine/TodoContext.java6
-rw-r--r--org/madore/damlengine/TodoDamlElement.java78
-rw-r--r--org/madore/damlengine/TodoDefaultElement.java1
-rw-r--r--org/madore/damlengine/TodoElement.java1
5 files changed, 85 insertions, 2 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java
index 4861f06..d71f62b 100644
--- a/org/madore/damlengine/DamlEngine.java
+++ b/org/madore/damlengine/DamlEngine.java
@@ -10,6 +10,7 @@ import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
public final class DamlEngine {
public static final String XML_NS = "http://www.w3.org/XML/1998/namespace";
+ public static final String XHTML_NS = "http://www.w3.org/1999/xhtml";
public static final String DAML_NS = "http://www.madore.org/~david/NS/daml/";
private DamlEngine() { } // Forbid instantiation
diff --git a/org/madore/damlengine/TodoContext.java b/org/madore/damlengine/TodoContext.java
index 65746b8..4042370 100644
--- a/org/madore/damlengine/TodoContext.java
+++ b/org/madore/damlengine/TodoContext.java
@@ -1,10 +1,14 @@
package org.madore.damlengine;
-import org.w3c.dom.Document;
+import org.w3c.dom.*;
public class TodoContext {
public Document doc;
+ public Element htmlNode;
+ public Element headNode;
+ public String uriToTop;
+ public String fileName;
public TodoContext(Document doc) {
this.doc = doc;
diff --git a/org/madore/damlengine/TodoDamlElement.java b/org/madore/damlengine/TodoDamlElement.java
new file mode 100644
index 0000000..88881ae
--- /dev/null
+++ b/org/madore/damlengine/TodoDamlElement.java
@@ -0,0 +1,78 @@
+package org.madore.damlengine;
+
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+import org.w3c.dom.*;
+
+public class TodoDamlElement extends TodoDefaultElement {
+
+ public static class Factory extends TodoElement.Factory {
+ public TodoDamlElement newItem(Element node,
+ TodoContext context,
+ TodoItem.Options options) {
+ return new TodoDamlElement(node, context, options);
+ }
+ }
+
+ public TodoDamlElement(Element node,
+ TodoContext context,
+ TodoItem.Options options) {
+ super(node, context, options);
+ }
+
+ public static class DamlOptions extends TodoItem.Options {
+ }
+
+ public void handleNodeOnly() {
+ if ( ! ( options instanceof DamlEngine.RootOptions ) )
+ throw new Error("daml node can only be root node");
+ String uriToTop = node.getAttributeNS(null, "uri-to-top");
+ if ( uriToTop != null )
+ context.uriToTop = uriToTop;
+ String fileName = node.getAttributeNS(null, "file.name");
+ if ( fileName != null )
+ context.fileName = fileName;
+
+ if ( context.htmlNode != null )
+ throw new Error("html node already defined at daml node");
+ context.htmlNode = context.doc.createElementNS(DamlEngine.XHTML_NS, "html");
+ String lang = LangHelper.getLangNorec(node);
+ if ( lang != null )
+ LangHelper.setLangNorec(context.htmlNode, lang);
+ node.getParentNode().replaceChild(context.htmlNode, node);
+ context.htmlNode.appendChild(context.doc.createTextNode("\n"));
+ context.htmlNode.appendChild(context.doc.createComment(" This file is automatically generated. Do not edit! "));
+ context.htmlNode.appendChild(context.doc.createTextNode("\n"));
+ if ( context.headNode != null )
+ throw new Error("head node already defined at daml node");
+ context.headNode = context.doc.createElementNS(DamlEngine.XHTML_NS, "head");
+ context.htmlNode.appendChild(context.headNode);
+ context.htmlNode.appendChild(context.doc.createTextNode("\n"));
+ context.headNode.appendChild(context.doc.createTextNode("\n"));
+
+ ArrayList<Node> childList = getChildList(this.node);
+ ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size());
+ for ( Node child : childList ) {
+ if ( child.getNodeType() == Node.ELEMENT_NODE ) {
+ if ( child.getLocalName().equals("body") ) {
+ context.htmlNode.appendChild(context.doc.createTextNode("\n"));
+ context.htmlNode.appendChild(child);
+ context.htmlNode.appendChild(context.doc.createTextNode("\n"));
+ } else {
+ context.headNode.appendChild(child);
+ context.headNode.appendChild(context.doc.createTextNode("\n"));
+ }
+ TodoElement it
+ = TodoElement.getTodoElement((Element)child, this.context,
+ new DamlOptions());
+ toProcess.add(it);
+ } else if ( child.getNodeType() == Node.TEXT_NODE
+ || child.getNodeType() == Node.CDATA_SECTION_NODE ) {
+ if ( ! Pattern.matches("^\\s*$",((CharacterData)child).getData()) )
+ throw new Error("daml element cannot contain text");
+ }
+ }
+ this.ownerDeque.registerAtStart(toProcess);
+ }
+
+}
diff --git a/org/madore/damlengine/TodoDefaultElement.java b/org/madore/damlengine/TodoDefaultElement.java
index 50a460f..8b0efa9 100644
--- a/org/madore/damlengine/TodoDefaultElement.java
+++ b/org/madore/damlengine/TodoDefaultElement.java
@@ -51,7 +51,6 @@ public class TodoDefaultElement extends TodoElement {
}
public void handleNodeOnly() {
- System.err.println("handling a "+this.node.getNodeName()+" element");
ArrayList<Node> childList = getChildList(this.node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size());
for ( Node child : childList ) {
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index 497b8f5..77c7891 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -18,6 +18,7 @@ public abstract class TodoElement extends TodoItem {
static {
damlFactories = new HashMap<String,Factory>();
damlDefaultFactory = new TodoDefaultElement.Factory();
+ damlFactories.put("daml", new TodoDamlElement.Factory());
}
Element node;