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 listNameTable; static { listNameTable = new HashMap(); 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); 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"); 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(")")); } } }