summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine
diff options
context:
space:
mode:
Diffstat (limited to 'org/madore/damlengine')
-rw-r--r--org/madore/damlengine/Context.java31
-rw-r--r--org/madore/damlengine/TodoComments.java57
-rw-r--r--org/madore/damlengine/TodoEntryElement.java11
-rw-r--r--org/madore/damlengine/TodoWrefAttr.java2
4 files changed, 95 insertions, 6 deletions
diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java
index 6321ca2..22912a7 100644
--- a/org/madore/damlengine/Context.java
+++ b/org/madore/damlengine/Context.java
@@ -3,9 +3,9 @@ package org.madore.damlengine;
import java.util.ArrayList;
import org.w3c.dom.*;
-public class Context {
+public class Context implements Cloneable {
- public Document doc;
+ public final Document doc;
public Element htmlNode;
public Element headNode;
public String uriToTop;
@@ -20,8 +20,35 @@ public class Context {
public String subtitleLang;
public ArrayList<String> translations;
+ public static class EntryContext {
+ public String year;
+ public String month;
+ public String day;
+ public String yandm;
+ public String date;
+ public String number;
+ public String dow;
+ public EntryContext(String year, String month, String day,
+ String number, String dow) {
+ this.year = year; this.month = month; this.day = day;
+ this.yandm = year+"-"+month;
+ this.date = yandm+"-"+day;
+ this.number = number; this.dow = dow;
+ }
+ }
+
+ public EntryContext entryCtx;
+
public Context(Document doc) {
this.doc = doc;
}
+ public Context clone() {
+ try {
+ return (Context) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
diff --git a/org/madore/damlengine/TodoComments.java b/org/madore/damlengine/TodoComments.java
new file mode 100644
index 0000000..e1dd027
--- /dev/null
+++ b/org/madore/damlengine/TodoComments.java
@@ -0,0 +1,57 @@
+package org.madore.damlengine;
+
+import java.util.Map;
+import java.util.HashMap;
+import org.w3c.dom.*;
+
+public final class TodoComments extends TodoElement {
+
+ public TodoComments(Element node,
+ Context ctx,
+ TodoItem caller) {
+ super(node, ctx, caller);
+ }
+
+ protected final static Map<String,String> linkNameTable;
+
+ static {
+ linkNameTable = new HashMap<String,String>();
+ linkNameTable.put("en", "Comments");
+ linkNameTable.put("fr", "Commentaires");
+ linkNameTable.put("de", "Kommentare");
+ linkNameTable.put("ia", "Commentos");
+ }
+
+ @Override
+ public void handle() {
+ Element p = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "p");
+ String lang = LangHelper.getLangRec(node);
+ String explicitLang = LangHelper.getLangNorec(node);
+ if ( lang == null || linkNameTable.get(lang) == null ) {
+ System.err.println("warning: will use English comments link");
+ lang = "en";
+ explicitLang = "en";
+ }
+ if ( explicitLang != null )
+ LangHelper.setLangNorec(p, explicitLang);
+ p.setAttributeNS(null, "class", "talkback-link");
+ node.getParentNode().replaceChild(p, node);
+ Element a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
+ if ( ctx.entryCtx == null )
+ throw new IllegalStateException("entry context not defined in comments element");
+ String commentURL = "http://www.madore.org/cgi-bin/comment.pl/"
+ + "showcomments?href=http%3a%2f%2fwww.madore.org%2f"
+ + "%7edavid%2fweblog%2f"
+ + ctx.entryCtx.yandm + ".html%23d." + ctx.entryCtx.date
+ + "." + ctx.entryCtx.number;
+ a.setAttributeNS(null, "href", commentURL);
+ p.appendChild(a);
+ a.appendChild(ctx.doc.createTextNode(linkNameTable.get(lang)));
+ Element span = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span");
+ span.setAttributeNS(null, "id",
+ "d." + ctx.entryCtx.date + "."
+ + ctx.entryCtx.number + ".numcomments");
+ p.appendChild(span);
+ span.appendChild(ctx.doc.createComment(" EMPTY "));
+ }
+}
diff --git a/org/madore/damlengine/TodoEntryElement.java b/org/madore/damlengine/TodoEntryElement.java
index 7e6f384..14560a5 100644
--- a/org/madore/damlengine/TodoEntryElement.java
+++ b/org/madore/damlengine/TodoEntryElement.java
@@ -42,7 +42,7 @@ public final class TodoEntryElement extends TodoDefaultElement {
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 entryDayStr = entryDateMatcher.group(3);
String entryDowStr = node.getAttributeNS(null, "day_of_week");
String entryIdStr = "d."+entryDateStr+"."+entryNumberStr;
@@ -69,6 +69,11 @@ public final class TodoEntryElement extends TodoDefaultElement {
if ( ! entryDowStr.equals("") )
header.appendChild(ctx.doc.createTextNode(" ("+entryDowStr+")"));
+ Context ctx2 = ctx.clone();
+ ctx2.entryCtx
+ = new Context.EntryContext(entryYearStr, entryMonthStr, entryDayStr,
+ entryNumberStr, entryDowStr);
+
ArrayList<Node> childList = getChildList(this.node);
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(childList.size()+8);
for ( Node child : childList ) {
@@ -80,7 +85,7 @@ public final class TodoEntryElement extends TodoDefaultElement {
} else if ( child.getNodeType() == Node.ELEMENT_NODE ) {
div.appendChild(child);
TodoElement it
- = TodoElement.getTodoElement((Element)child, this.ctx, this);
+ = TodoElement.getTodoElement((Element)child, ctx2, this);
toProcess.add(it);
}
}
@@ -89,7 +94,7 @@ public final class TodoEntryElement extends TodoDefaultElement {
"d:implicit-do-comments");
div.appendChild(token);
div.appendChild(ctx.doc.createTextNode("\n"));
- // toProcess.add(new TodoComments(token, this.ctx, this));
+ toProcess.add(new TodoComments(token, ctx2, this));
}
this.ownerDeque.registerAtStart(toProcess);
}
diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java
index 5737577..5a15045 100644
--- a/org/madore/damlengine/TodoWrefAttr.java
+++ b/org/madore/damlengine/TodoWrefAttr.java
@@ -26,7 +26,7 @@ public class TodoWrefAttr extends TodoAttr {
String wrefStr = attr.getValue();
Matcher wrefMatcher = Pattern.compile("^\\#d\\.(\\d{4})-(\\d{2})-(\\d{2})\\.(\\d{4})(|\\..*)$").matcher(wrefStr);
if ( ! wrefMatcher.matches() )
- throw new IllegalArgumentException("wref attribute ("+wrefStr+") must be of the form #d.YYYY-MM-DD.NNNN[.xxx]");
+ throw new IllegalArgumentException("wref attribute must be of the form #d.YYYY-MM-DD.NNNN[.xxx]");
String wrefYearStr = wrefMatcher.group(1);
String wrefMonthStr = wrefMatcher.group(2);
String wrefDayStr = wrefMatcher.group(3);