summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoCommentsScript.java
blob: fbe0bbed4937f32492453b71ece8ec67a6310441 (plain)
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
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 != null && ( 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);
    }
}