summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoImgAElement.java
blob: 0d8edf619cb4babe59d05a7d814df6b5e0739144 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.madore.damlengine;

import java.util.ArrayList;
import org.w3c.dom.*;

public final class TodoImgAElement extends TodoDefaultElement {

    public static class Factory extends TodoElement.Factory {
	@Override
	public TodoImgAElement newItem(Element node,
				       Context ctx,
				       TodoItem caller) {
	    return new TodoImgAElement(node, ctx, caller);
	}
    }

    public TodoImgAElement(Element node,
			   Context ctx,
			   TodoItem caller) {
	super(node, ctx, caller);
    }

    @Override
    public void handleNodeOnly() {
	String explicitLang = LangHelper.getLangNorec(node);
	Element a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
	if ( explicitLang != null )
	    LangHelper.setLangNorec(node, explicitLang);
	Node pnode = node.getParentNode();
	if ( pnode == null )
	    // See "FIXME" in TodoCutHere.java (node may have moved out of DOM).
	    return;
	pnode.replaceChild(a, node);
	Element img = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "img");
	a.appendChild(img);
	ArrayList<Attr> attrList = getAttrList(this.node);
	for ( Attr attr : attrList ) {
	    if ( attr.getNamespaceURI() == null ) {
		String attName = attr.getLocalName();
		if ( attName.equals("src") )
		    a.setAttributeNS(null, "href", attr.getValue());
		node.removeAttributeNode(attr);
		img.setAttributeNodeNS(attr);
	    }
	}
    }

}