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 ) { 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(")")); } } }