summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoTranslationElement.java
blob: 943f7a7198cf65cfda5afc0cf419905d8e0c1647 (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
package org.madore.damlengine;

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

public final class TodoTranslationElement extends TodoDefaultElement {

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

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

    @Override
    public void handleNodeOnly() {
	if ( ctx.translations == null )
	    ctx.translations = new ArrayList<String>(8);
	String lang = LangHelper.getLangNorec(node);
	if ( lang == null )
	    throw new IllegalArgumentException("translation element must have an xml:lang attribute");
	ctx.translations.add(lang);
	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);
    }

}