1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.millscript.millscript.loaders;
23
24 import org.millscript.commons.xml.api.Name;
25 import org.millscript.commons.xml.api.token.StartTagToken;
26 import org.millscript.commons.xml.tokenizer.NoNamespacesName;
27 import org.millscript.millscript.alert.Alerts;
28
29 import java.util.HashSet;
30
31 /**
32 * This class is a starting point for implementing an XHTML template loader. It
33 * allows specific sub-classes to customize the loading process for custom tags
34 * and attributes.
35 */
36 public abstract class BasicXHTMLTemplateLoader extends BasicTemplateLoader {
37
38 /**
39 * A set of supported element names.
40 */
41 private static final HashSet< Name > SUPPORTED_ELEMENTS = new HashSet< Name >();
42
43 /**
44 * Array of all the supported XHTML element names.
45 */
46 private static final String[] xhtmlTagNames = {
47 "a", "abbr", "address", "applet", "area", "b", "base",
48 "basefont", "bdo", "bgsound", "big", "blink", "blockquote",
49 "body", "br", "button", "caption", "center", "cite", "code",
50 "col", "colgroup", "dd", "dfn", "dir", "div", "dl", "dt",
51 "em", "embed", "fieldset", "font", "form", "frame",
52 "frameset", "head", "h1", "h2", "h3", "h4", "h5", "h6", "hr",
53 "html", "i", "iframe", "ilayer", "img", "input", "isindex",
54 "kbd", "keygen", "label", "layer", "legend", "li", "link",
55 "map", "marquee", "menu", "meta", "nobr", "noembed",
56 "noframes", "nolayer", "noscript", "object", "ol", "optgroup",
57 "option", "p", "param", "pre", "q", "s", "samp", "script",
58 "select", "server", "small", "spacer", "span", "strike",
59 "strong", "style", "sub", "sup", "table", "tbody", "td",
60 "textarea", "tfoot", "th", "thead", "title", "tr", "tt", "u",
61 "ul", "var", "wbr"
62 };
63
64
65 static {
66 for ( int i = 0; i < xhtmlTagNames.length; i++ ) {
67 SUPPORTED_ELEMENTS.add(
68 new NoNamespacesName( xhtmlTagNames[ i ] )
69 );
70 }
71 }
72
73 /**
74 * Constructs a new basic XHTML template loader with optional XML namespace
75 * support.
76 *
77 * @param ns indicates if the XML tokenizer should support namespaces
78 */
79 BasicXHTMLTemplateLoader( final boolean ns ) {
80 super( ns );
81 }
82
83 /**
84 * @see org.millscript.millscript.loaders.BasicTemplateLoader#compileStartTag(org.millscript.commons.xml.api.token.StartTagToken)
85 */
86 @Override
87 public void compileStartTag( final StartTagToken token ) {
88
89
90 if ( SUPPORTED_ELEMENTS.contains( token.getName() ) ) {
91
92 super.compileStartTag( token );
93 } else {
94
95 throw(
96 Alerts.template(
97 "Unrecognized template element (spelling error?)",
98 "All XHTML element names must be pre-registered"
99 ).decorate( token ).mishap()
100 );
101 }
102 }
103
104 }