summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoImgAElement.java
blob: aa545bc76e82788afd3f283c5b56364413e73c13 (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
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.getParentNode().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);
	    }
	}
    }

}