summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoComments.java
blob: 85ce7d3276af4035719b1f49be2f818a12ae1459 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.ent == 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.ent.yandm + ".html%23d." + ctx.ent.date
	    + "." + ctx.ent.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.ent.date + "."
			    + ctx.ent.number + ".numcomments");
	p.appendChild(span);
	span.appendChild(ctx.doc.createComment(" EMPTY "));
    }
}