summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoTitleElement.java
blob: 877e719a59f6027082065619d46e5149562c184a (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
package org.madore.damlengine;

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

public final class TodoTitleElement extends TodoDefaultElement {

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

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

    @Override
    public void handleNodeOnly() {
	if ( ctx.gc.title != null )
	    throw new IllegalArgumentException("attempting to redefine title");
	ctx.gc.title = ctx.doc.createDocumentFragment();
	ctx.gc.titleStr = node.getTextContent();
	ctx.gc.titleLang = LangHelper.getLangRec(node);
	String lang = LangHelper.getLangNorec(node);
	ArrayList<Node> childList = getChildList(node);
	for ( Node child : childList ) {
	    ctx.gc.title.appendChild(child);
	}
	Element tit = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "title");
	if ( lang != null )
	    LangHelper.setLangNorec(tit, lang);
	node.getParentNode().replaceChild(tit, node);
	tit.appendChild(ctx.doc.createTextNode(ctx.gc.titleStr));
    }

}