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
|
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 ) {
p.appendChild(ctx.doc.createTextNode(" "));
Element a1 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
String target1URL = ((ctx.gc.uriToTop==null)?"":(ctx.gc.uriToTop+"weblog/"))
+ cat + ".html";
a1.setAttributeNS(null, "href", target1URL);
p.appendChild(a1);
a1.appendChild(ctx.doc.createTextNode(cat));
p.appendChild(ctx.doc.createTextNode("("));
Element a2 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
String target2URL = target1URL
+ "#d." + ctx.ent.date + "." + ctx.ent.number;
a2.setAttributeNS(null, "href", target2URL);
p.appendChild(a2);
a2.appendChild(ctx.doc.createTextNode("\u2022"));
p.appendChild(ctx.doc.createTextNode(")"));
}
}
}
|