summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoEntryElement.java
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-05-01 01:58:53 +0200
committerDavid A. Madore <david+git@madore.org>2011-05-01 01:59:31 +0200
commitf33bb94503c9a7acfdb4fd00594e3985a3e1979b (patch)
treeffd8851d5f22d45d5487ceef269b56903e39228b /org/madore/damlengine/TodoEntryElement.java
parent29e1d0cef40d41fd262fedd8b023d341b53259f0 (diff)
downloaddamlengine-f33bb94503c9a7acfdb4fd00594e3985a3e1979b.tar.gz
damlengine-f33bb94503c9a7acfdb4fd00594e3985a3e1979b.tar.bz2
damlengine-f33bb94503c9a7acfdb4fd00594e3985a3e1979b.zip
(Preliminary) handling of weblog <entry>.
Diffstat (limited to 'org/madore/damlengine/TodoEntryElement.java')
-rw-r--r--org/madore/damlengine/TodoEntryElement.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/org/madore/damlengine/TodoEntryElement.java b/org/madore/damlengine/TodoEntryElement.java
new file mode 100644
index 0000000..a67e770
--- /dev/null
+++ b/org/madore/damlengine/TodoEntryElement.java
@@ -0,0 +1,97 @@
+package org.madore.damlengine;
+
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import org.w3c.dom.*;
+
+public final class TodoEntryElement extends TodoDefaultElement {
+
+ public static class Factory extends TodoElement.Factory {
+ @Override
+ public TodoEntryElement newItem(Element node,
+ Context ctx,
+ TodoItem caller) {
+ return new TodoEntryElement(node, ctx, caller);
+ }
+ }
+
+ public TodoEntryElement(Element node,
+ Context ctx,
+ TodoItem caller) {
+ super(node, ctx, caller);
+ }
+
+ @Override
+ public void handleNodeOnly() {
+ if ( ! ( caller instanceof TodoWeblogElement ) )
+ throw new IllegalArgumentException("entry node can only be child of weblog node");
+
+ Element div = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "div");
+ String explicitLang = LangHelper.getLangNorec(node);
+ if ( explicitLang != null )
+ LangHelper.setLangNorec(div, explicitLang);
+ node.getParentNode().replaceChild(div, node);
+
+ String entryNumberStr = node.getAttributeNS(null, "number");
+ if ( ! Pattern.matches("^\\d{4}$", entryNumberStr) )
+ throw new IllegalArgumentException("title number attribute must be of the form NNNN");
+ String entryDateStr = node.getAttributeNS(null, "date");
+ Matcher entryDateMatcher = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})$").matcher(entryDateStr);
+ if ( ! entryDateMatcher.matches() )
+ throw new IllegalArgumentException("title date attribute must be of the form YYYY-MM-DD");
+ String entryYearStr = entryDateMatcher.group(1);
+ String entryMonthStr = entryDateMatcher.group(2);
+ String entryDayStr = entryDateMatcher.group(3);
+ String entryDowStr = node.getAttributeNS(null, "day_of_week");
+
+ String entryIdStr = "d."+entryDateStr+"."+entryNumberStr;
+ div.setAttributeNS(null, "id", entryIdStr);
+ div.setAttributeNS(null, "class", "weblog-entry");
+ {
+ String styleAtt = node.getAttributeNS(null, "style");
+ if ( ! styleAtt.equals("") )
+ node.setAttributeNS(null, "style", styleAtt);
+ }
+ div.appendChild(ctx.doc.createTextNode("\n"));
+
+ Element header = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "p");
+ header.setAttributeNS(null, "class", "weblog-entry-header");
+ div.appendChild(header);
+ div.appendChild(ctx.doc.createTextNode("\n"));
+
+ Element permalink = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
+ permalink.setAttributeNS(null, "href",
+ entryYearStr+"-"+entryMonthStr+".html"
+ +"#"+entryIdStr);
+ permalink.appendChild(ctx.doc.createTextNode(entryDateStr));
+ header.appendChild(permalink);
+ if ( ! entryDowStr.equals("") )
+ header.appendChild(ctx.doc.createTextNode(" ("+entryDowStr+")"));
+
+ ArrayList<Node> childList = getChildList(this.node);
+ ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()+8);
+ for ( Node child : childList ) {
+ if ( child.getNodeType() == Node.TEXT_NODE
+ || child.getNodeType() == Node.CDATA_SECTION_NODE ) {
+ if ( ! Pattern.matches("^\\s*$",((CharacterData)child).getData()) )
+ throw new IllegalArgumentException("entry element cannot contain text");
+ div.appendChild(ctx.doc.createTextNode("\n"));
+ } else if ( child.getNodeType() == Node.ELEMENT_NODE ) {
+ div.appendChild(child);
+ TodoElement it
+ = TodoElement.getTodoElement((Element)child, this.ctx, this);
+ toProcess.add(it);
+ }
+ }
+ if ( node.getAttributeNS(null, "nocomments").equals("") ) {
+ Element token = ctx.doc.createElementNS(DamlEngine.DAML_NS,
+ "d:implicit-do-comments");
+ div.appendChild(token);
+ div.appendChild(ctx.doc.createTextNode("\n"));
+ // toProcess.add(new TodoComments(token, this.ctx, this));
+ }
+ this.ownerDeque.registerAtStart(toProcess);
+ }
+
+}