summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoElement.java
blob: a5784bb7f9168c478f3802b9ed9235f76a9586f4 (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
58
59
60
61
62
63
64
65
66
67
package org.madore.damlengine;

import java.util.Map;
import java.util.HashMap;
import org.w3c.dom.Element;

public abstract class TodoElement extends TodoItem {

    public static abstract class Factory {
	public abstract TodoElement newItem(Element node,
					    Context ctx,
					    TodoItem caller);
    }

    public static class TitleDisambiguationFactory extends Factory {
	Factory mainTitleFactory = new TodoTitleElement.Factory();
	Factory entryTitleFactory = new TodoDefaultElement.Factory();
	public TodoElement newItem(Element node,
				   Context ctx,
				   TodoItem caller) {
	    if ( caller instanceof TodoDamlElement )
		return mainTitleFactory.newItem(node, ctx, caller);
	    else
		return entryTitleFactory.newItem(node, ctx, caller);
	}
    }

    protected final static Map<String,Factory> damlFactories;
    protected final static Factory damlDefaultFactory;

    static {
	damlFactories = new HashMap<String,Factory>();
	damlDefaultFactory = new TodoDefaultElement.Factory();
	damlFactories.put("daml", new TodoDamlElement.Factory());
	damlFactories.put("body", new TodoBodyElement.Factory());
	damlFactories.put("title", new TitleDisambiguationFactory());
	damlFactories.put("subtitle", new TodoSubtitleElement.Factory());
	damlFactories.put("translation", new TodoTranslationElement.Factory());
	damlFactories.put("meta-description", new TodoMetaElement.Factory(TodoMetaElement.Type.DESCRIPTION));
	damlFactories.put("meta-keywords", new TodoMetaElement.Factory(TodoMetaElement.Type.KEYWORDS));
	damlFactories.put("email-despammed", new TodoEmailDespammedElement.Factory());
	damlFactories.put("email-at", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.AT));
	damlFactories.put("email-dot", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.DOT));
    }

    protected final Element node;

    public TodoElement(Element node,
		       Context ctx,
		       TodoItem caller) {
	super(ctx, caller);
	this.node = node;
    }

    public static TodoElement getTodoElement(Element node,
					     Context ctx,
					     TodoItem caller) {
	Factory factory = null;
	String nsuri = node.getNamespaceURI();
	if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) )
	    factory = damlFactories.get(node.getLocalName());
	if ( factory == null )
	    factory = damlDefaultFactory;
	return factory.newItem(node, ctx, caller);
    }

}