summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoTranslations.java
blob: 95f1ab7d3eead8f8bac1459e72891b18e163e2cc (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
53
54
55
56
57
package org.madore.damlengine;

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

public final class TodoTranslations extends TodoElement {

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

    @Override
    public void handle() {
	ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>(ctx.gc.translations.size()+8);
	for ( String trlang : ctx.gc.translations ) {
	    Element p = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "p");
	    LangHelper.setLangNorec(p, trlang);
	    p.setAttributeNS(null, "class", "translation-offer");
	    node.getParentNode().insertBefore(p, node);
	    node.getParentNode().insertBefore(ctx.doc.createTextNode("\n"), node);
	    String str = "[";
	    if ( trlang.equals("en") )
		str = "[An ";
	    else if ( trlang.equals("fr") )
		str = "[Une ";
	    p.appendChild(ctx.doc.createTextNode(str));
	    Element a = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a");
	    p.appendChild(a);
	    a.setAttributeNS(null, "href", ctx.gc.fileName+"."+trlang);
	    a.setAttributeNS(null, "hreflang", trlang);
	    str = trlang;
	    if ( trlang.equals("en") )
		str = "English version";
	    else if ( trlang.equals("fr") )
		str = "version fran\u00e7aise";
	    a.appendChild(ctx.doc.createTextNode(str));
	    str = "]";
	    if ( trlang.equals("en") )
		str = " of this page is also available.]";
	    else if ( trlang.equals("fr") )
		str = " de cette page est \u00e9galement disponible.]";
	    p.appendChild(ctx.doc.createTextNode(str));
	    toProcess.add(TodoElement.getTodoElement(p, this.ctx, this));
	}
	Node ws = node.getNextSibling();
	if ( ( 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);
	this.ownerDeque.registerAtStart(toProcess);
    }

}