summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoCategories.java
blob: a3bd3ef1bbb3175af6cf7bb800bfaf3061f5dd5f (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
58
59
60
61
62
63
package org.madore.damlengine;

import java.util.Map;
import java.util.HashMap;
import org.w3c.dom.*;

public final class TodoCategories extends TodoElement {

    public TodoCategories(Element node,
			  Context ctx,
			  TodoItem caller) {
	super(node, ctx, caller);
    }

    protected final static Map<String,String> listNameTable;

    static {
	listNameTable = new HashMap<String,String>();
	listNameTable.put("en", "Categories:");
	listNameTable.put("fr", "Cat\u00e9gories\u00a0:");
	listNameTable.put("de", "Kategorien:");
	listNameTable.put("ia", "Categorias\u00a0:");
    }

    @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 || listNameTable.get(lang) == null ) {
	    System.err.println("warning: will use English categories list");
	    lang = "en";
	    explicitLang = "en";
	}
	if ( explicitLang != null )
	    LangHelper.setLangNorec(p, explicitLang);
	p.setAttributeNS(null, "class", "categories-list");
	node.getParentNode().replaceChild(p, node);
	p.appendChild(ctx.doc.createTextNode(listNameTable.get(lang)));
	if ( ctx.ent == null )
	    throw new IllegalStateException("entry context not defined in categories element");
	for ( String cat : ctx.ent.catList ) {
	    WeblogLink lk = new WeblogLink(ctx.ent.year, ctx.ent.month,
					   ctx.ent.day, ctx.ent.number, "",
					   ctx.ent.specialName);
	    lk.setTypeCat(cat);
	    String baseDir = ((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/"));
	    p.appendChild(ctx.doc.createTextNode(" "));
	    Element a1 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
	    a1.setAttributeNS(null, "href", lk.getFile(baseDir));
	    a1.setAttributeNS(null, "title",
			      TodoWeblogSelectionElement.categoryName(cat, lang));
	    p.appendChild(a1);
	    a1.appendChild(ctx.doc.createTextNode(cat));
	    p.appendChild(ctx.doc.createTextNode("("));
	    Element a2 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
	    a2.setAttributeNS(null, "href", lk.getTarget(baseDir));
	    p.appendChild(a2);
	    a2.appendChild(ctx.doc.createTextNode("\u2022"));
	    p.appendChild(ctx.doc.createTextNode(")"));
	}
    }
}