View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.renderkit.html;
21  
22  import java.util.Arrays;
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  public enum HtmlElements {
27  
28    A("a", Qualifier.INLINE),
29    ABBR("abbr", Qualifier.INLINE),
30    ADDRESS("address"),
31    AREA("area", Qualifier.VOID),
32    ARTICLE("article"),
33    ASIDE("aside"),
34    AUDIO("audio"),
35    B("b", Qualifier.INLINE),
36    BASE("base", Qualifier.VOID),
37    BDI("bdi"),
38    BDO("bdo"),
39    BLOCKQUOTE("blockquote"),
40    BODY("body"),
41    BR("br", Qualifier.VOID),
42    BUTTON("button", Qualifier.INLINE),
43    CANVAS("canvas"),
44    CAPTION("caption"),
45    CITE("cite", Qualifier.INLINE),
46    CODE("code"),
47    COL("col", Qualifier.VOID),
48    COLGROUP("colgroup"),
49    COMMAND("command", Qualifier.VOID),
50    DATALIST("datalist"),
51    DD("dd"),
52    DEL("del"),
53    DETAILS("details"),
54    DFN("dfn"),
55    DIV("div"),
56    DL("dl"),
57    DT("dt"),
58    EM("em", Qualifier.INLINE),
59    EMBED("embed", Qualifier.VOID),
60    FIELDSET("fieldset"),
61    FIGCAPTION("figcaption"),
62    FIGURE("figure"),
63    FOOTER("footer"),
64    FORM("form"),
65    H1("h1"),
66    H2("h2"),
67    H3("h3"),
68    H4("h4"),
69    H5("h5"),
70    H6("h6"),
71    HEAD("head"),
72    HEADER("header"),
73    HGROUP("hgroup"),
74    HR("hr", Qualifier.VOID),
75    HTML("html"),
76    I("i", Qualifier.INLINE),
77    IFRAME("iframe"),
78    IMG("img", Qualifier.VOID, Qualifier.INLINE),
79    INPUT("input", Qualifier.VOID, Qualifier.INLINE),
80    INS("ins"),
81    KBD("kbd"),
82    KEYGEN("keygen", Qualifier.VOID),
83    LABEL("label", Qualifier.INLINE),
84    LEGEND("legend"),
85    LI("li"),
86    LINK("link", Qualifier.VOID),
87    MAP("map"),
88    MARK("mark"),
89    MENU("menu"),
90    META("meta", Qualifier.VOID),
91    METER("meter"),
92    NAV("nav"),
93    NOSCRIPT("noscript"),
94    OBJECT("object"),
95    OL("ol"),
96    OPTGROUP("optgroup"),
97    OPTION("option"),
98    P("p"),
99    PARAM("param", Qualifier.VOID),
100   PRE("pre"),
101   PROGRESS("progress"),
102   Q("q"),
103   RP("rp"),
104   RT("rt"),
105   RUBY("ruby"),
106   S("s"),
107   SAMP("samp"),
108   SCRIPT("script", Qualifier.INLINE),
109   SECTION("section"),
110   SELECT("select", Qualifier.INLINE),
111   SMALL("small"),
112   SOURCE("source", Qualifier.VOID),
113   SPAN("span", Qualifier.INLINE),
114   STRONG("strong"),
115   STYLE("style"),
116   SUB("sub", Qualifier.INLINE),
117   SUMMARY("summary"),
118   SUP("sup", Qualifier.INLINE),
119   TABLE("table"),
120   TBODY("tbody"),
121   TD("td"),
122   TEXTAREA("textarea", Qualifier.INLINE),
123   TFOOT("tfoot"),
124   TH("th"),
125   THEAD("thead"),
126   TIME("time"),
127   TITLE("title"),
128   TR("tr"),
129   TRACK("track", Qualifier.VOID),
130   U("u", Qualifier.INLINE),
131   UL("ul"),
132   VAR("var"),
133   VIDEO("video"),
134   WBR("wbr", Qualifier.VOID);
135 
136   private final String value;
137   private final boolean voidElement;
138   private final boolean inlineElement;
139 
140   private static final Set<String> VOIDS = new HashSet<String>();
141 
142   HtmlElements(final String value, final Qualifier... qualifiers) {
143     this.value = value;
144     this.voidElement = Arrays.asList(qualifiers).contains(Qualifier.VOID);
145     this.inlineElement = Arrays.asList(qualifiers).contains(Qualifier.INLINE);
146   }
147 
148   static {
149     for (final HtmlElements htmlElement : values()) {
150       if (htmlElement.isVoid()) {
151         VOIDS.add(htmlElement.getValue());
152       }
153     }
154   }
155 
156   public String getValue() {
157     return value;
158   }
159 
160   /**
161    * A void HTML elements is an element whose content model never allows it to have contents under any circumstances.
162    * See <a href="http://www.w3.org/TR/html-markup/syntax.html#void-element">
163    * http://www.w3.org/TR/html-markup/syntax.html#void-element</a>
164    */
165   public boolean isVoid() {
166     return voidElement;
167   }
168 
169   public boolean isInline() {
170     return inlineElement;
171   }
172 
173   public static boolean isVoid(final String name) {
174     return VOIDS.contains(name);
175   }
176 
177   private enum Qualifier {VOID, INLINE}
178 }