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 linkNameTable; static { linkNameTable = new HashMap(); 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"); final WeblogLink lknc = new WeblogLink(ctx.ent.year, ctx.ent.month, ctx.ent.day, ctx.ent.number, ".numcomments", ctx.ent.doSinglePage); span.setAttributeNS(null, "id", lknc.getFragment()); p.appendChild(span); span.appendChild(ctx.doc.createComment(" EMPTY ")); if ( ctx.gc.commentsJSParam == null ) { ctx.gc.commentsJSParam = new StringBuffer("x=" + ctx.ent.date + "." + ctx.ent.number); } else { ctx.gc.commentsJSParam.append("&x=" + ctx.ent.date + "." + ctx.ent.number); } } }