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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
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 TodoEntryTitleElement.Factory();
public TodoElement newItem(Element node,
Context ctx,
TodoItem caller) {
if ( caller instanceof TodoDamlElement )
return mainTitleFactory.newItem(node, ctx, caller);
else if ( caller instanceof TodoEntryElement )
return entryTitleFactory.newItem(node, ctx, caller);
else
throw new IllegalArgumentException("title element can only be child of daml or entry elements");
}
}
protected final static Map<String,Factory> damlFactories;
protected final static Factory defaultFactory;
static {
damlFactories = new HashMap<String,Factory>();
defaultFactory = new TodoDefaultElement.Factory();
damlFactories.put("daml", new TodoDamlElement.Factory());
damlFactories.put("body", new TodoBodyElement.Factory());
damlFactories.put("weblog", new TodoWeblogElement.Factory());
damlFactories.put("entry", new TodoEntryElement.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("date-extra", new TodoDateExtraElement.Factory());
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));
damlFactories.put("extra-style", new TodoExtraStyleOrScriptElement.Factory(TodoStyleOrScript.Type.STYLE));
damlFactories.put("extra-script", new TodoExtraStyleOrScriptElement.Factory(TodoStyleOrScript.Type.SCRIPT));
damlFactories.put("smiley-smile", new TodoSmileyElement.Factory(TodoSmileyElement.Type.SMILE));
damlFactories.put("smiley-wink", new TodoSmileyElement.Factory(TodoSmileyElement.Type.WINK));
damlFactories.put("smiley-surprised", new TodoSmileyElement.Factory(TodoSmileyElement.Type.SURPRISED));
damlFactories.put("smiley-sad", new TodoSmileyElement.Factory(TodoSmileyElement.Type.SAD));
damlFactories.put("smiley-cool", new TodoSmileyElement.Factory(TodoSmileyElement.Type.COOL));
damlFactories.put("smiley-biggrin", new TodoSmileyElement.Factory(TodoSmileyElement.Type.BIGGRIN));
damlFactories.put("smiley-confused", new TodoSmileyElement.Factory(TodoSmileyElement.Type.CONFUSED));
damlFactories.put("smiley-crazy", new TodoSmileyElement.Factory(TodoSmileyElement.Type.CRAZY));
damlFactories.put("smiley-neutral", new TodoSmileyElement.Factory(TodoSmileyElement.Type.NEUTRAL));
damlFactories.put("smiley-twisted", new TodoSmileyElement.Factory(TodoSmileyElement.Type.TWISTED));
damlFactories.put("smiley-cry", new TodoSmileyElement.Factory(TodoSmileyElement.Type.CRY));
damlFactories.put("smiley-evil", new TodoSmileyElement.Factory(TodoSmileyElement.Type.EVIL));
damlFactories.put("img-a", new TodoImgAElement.Factory());
damlFactories.put("weblog-select", new TodoWeblogSelectElement.Factory());
damlFactories.put("weblog-index-select", new TodoWeblogIndexSelectElement.Factory());
damlFactories.put("weblog-selection-recent-count", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.RECENT_COUNT));
damlFactories.put("weblog-selection-month-numeric", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_NUMERIC));
damlFactories.put("weblog-selection-month-literal", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_LITERAL));
damlFactories.put("weblog-selection-cat-code", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_CODE));
damlFactories.put("weblog-selection-cat-name", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_NAME));
damlFactories.put("weblog-selection-single-number", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.SINGLE_NUMBER));
damlFactories.put("weblog-selection-single-title", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.SINGLE_TITLE));
damlFactories.put("weblog-months-calendar", new TodoWeblogMonthsCalendar.Factory());
damlFactories.put("cut-here", new TodoCutHere.Factory());
}
protected final static Factory killAFactory
= new TodoKillAElement.Factory();
protected final static Factory killAcronymFactory
= new TodoKillAcronymElement.Factory();
protected final static Factory styleFactory
= new TodoStyleOrScript.Factory(TodoStyleOrScript.Type.STYLE);
protected final static Factory scriptFactory
= new TodoStyleOrScript.Factory(TodoStyleOrScript.Type.SCRIPT);
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());
else if ( nsuri != null && nsuri.equals(DamlEngine.XHTML_NS) ) {
if ( ctx.killA && node.getLocalName().equals("a") )
factory = killAFactory;
else if ( node.getLocalName().equals("acronym") )
factory = killAcronymFactory;
else if ( node.getLocalName().equals("style") )
factory = styleFactory;
else if ( node.getLocalName().equals("script") )
factory = scriptFactory;
}
if ( factory == null )
factory = defaultFactory;
return factory.newItem(node, ctx, caller);
}
}
|