summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoTitleElement.java
blob: 31659e06ffba920e04d08a85345a6d0eaa5d65d8 (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
49
50
51
52
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.title != null )
	    throw new IllegalArgumentException("attempting to redefine title");
	ctx.title = ctx.doc.createDocumentFragment();
	ctx.titleStr = node.getTextContent();
	ctx.titleLang = LangHelper.getLangRec(node);
	String lang = LangHelper.getLangNorec(node);
	ArrayList<Node> childList = getChildList(node);
	for ( Node child : childList ) {
	    ctx.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.titleStr));
	Element meta = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "meta");
	if ( lang != null )
	    LangHelper.setLangNorec(meta, lang);
	meta.setAttributeNS(null, "name", "Title");
	meta.setAttributeNS(null, "content", ctx.titleStr);
	if ( tit.getNextSibling() != null )
	    tit.getParentNode().insertBefore(meta, tit.getNextSibling());
	else
	    tit.getParentNode().appendChild(meta);
	tit.getParentNode().insertBefore(ctx.doc.createTextNode("\n"), meta);
    }

}