package org.madore.damlengine; import java.util.regex.Pattern; import org.w3c.dom.*; public final class TodoCommentsScript extends TodoElement { public TodoCommentsScript(Element node, Context ctx, TodoItem caller) { super(node, ctx, caller); } @Override public void handle() { if ( ctx.gc.commentsJSParam == null ) { Node ws = node.getNextSibling(); if ( ( ws.getNodeType() == Node.TEXT_NODE || ws.getNodeType() == Node.CDATA_SECTION_NODE ) && Pattern.matches("^\\s*$",((CharacterData)ws).getData()) ) node.getParentNode().removeChild(ws); node.getParentNode().removeChild(node); return; } Element script = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "script"); script.setAttributeNS(null, "type", "text/javascript"); script.setAttributeNS(null, "src", "/cgi-bin/numcomments.pl/x.js?"+ctx.gc.commentsJSParam); script.setAttributeNS(null, "defer", "defer"); node.appendChild(ctx.doc.createComment(" EMPTY ")); node.getParentNode().replaceChild(script, node); } }