2 * @(#)AttributeTable.java 1.11 2000/08/16
6 package net.sourceforge.phpdt.tidy;
8 import java.util.Hashtable;
9 import java.util.Enumeration;
13 * HTML attribute hash table
15 * (c) 1998-2000 (W3C) MIT, INRIA, Keio University
16 * See Tidy.java for the copyright notice.
17 * Derived from <a href="http://www.w3.org/People/Raggett/tidy">
18 * HTML Tidy Release 4 Aug 2000</a>
20 * @author Dave Raggett <dsr@w3.org>
21 * @author Andy Quick <ac.quick@sympatico.ca> (translation to Java)
22 * @version 1.0, 1999/05/22
23 * @version 1.0.1, 1999/05/29
24 * @version 1.1, 1999/06/18 Java Bean
25 * @version 1.2, 1999/07/10 Tidy Release 7 Jul 1999
26 * @version 1.3, 1999/07/30 Tidy Release 26 Jul 1999
27 * @version 1.4, 1999/09/04 DOM support
28 * @version 1.5, 1999/10/23 Tidy Release 27 Sep 1999
29 * @version 1.6, 1999/11/01 Tidy Release 22 Oct 1999
30 * @version 1.7, 1999/12/06 Tidy Release 30 Nov 1999
31 * @version 1.8, 2000/01/22 Tidy Release 13 Jan 2000
32 * @version 1.9, 2000/06/03 Tidy Release 30 Apr 2000
33 * @version 1.10, 2000/07/22 Tidy Release 8 Jul 2000
34 * @version 1.11, 2000/08/16 Tidy Release 4 Aug 2000
37 public class AttributeTable {
39 public AttributeTable()
43 public Attribute lookup( String name )
45 return (Attribute)attributeHashtable.get( name );
48 public Attribute install( Attribute attr )
50 return (Attribute)attributeHashtable.put( attr.name, attr );
53 /* public method for finding attribute definition by name */
54 public Attribute findAttribute( AttVal attval )
58 if ( attval.attribute != null ) {
59 np = lookup( attval.attribute );
66 public boolean isUrl( String attrname )
70 np = lookup( attrname );
71 return ( np != null && np.attrchk == AttrCheckImpl.getCheckUrl() );
74 public boolean isScript( String attrname )
78 np = lookup( attrname );
79 return ( np != null && np.attrchk == AttrCheckImpl.getCheckScript() );
82 public boolean isLiteralAttribute( String attrname )
86 np = lookup( attrname );
87 return ( np != null && np.literal );
91 Henry Zrepa reports that some folk are
92 using embed with script attributes where
93 newlines are signficant. These need to be
94 declared and handled specially!
96 public void declareLiteralAttrib(String name)
98 Attribute attrib = lookup(name);
101 attrib = install(new Attribute(name, Dict.VERS_PROPRIETARY, null));
103 attrib.literal = true;
106 private Hashtable attributeHashtable = new Hashtable();
108 private static AttributeTable defaultAttributeTable = null;
110 private static Attribute[] attrs = {
112 new Attribute( "abbr", Dict.VERS_HTML40, null ),
113 new Attribute( "accept-charset", Dict.VERS_HTML40, null ),
114 new Attribute( "accept", Dict.VERS_ALL, null ),
115 new Attribute( "accesskey", Dict.VERS_HTML40, null ),
116 new Attribute( "action", Dict.VERS_ALL, AttrCheckImpl.getCheckUrl() ),
117 new Attribute( "add_date", Dict.VERS_NETSCAPE, null ), /* A */
118 new Attribute( "align", Dict.VERS_ALL, AttrCheckImpl.getCheckAlign() ), /* set varies with element */
119 new Attribute( "alink", Dict.VERS_LOOSE, null ),
120 new Attribute( "alt", Dict.VERS_ALL, null ),
121 new Attribute( "archive", Dict.VERS_HTML40, null ), /* space or comma separated list */
122 new Attribute( "axis", Dict.VERS_HTML40, null ),
123 new Attribute( "background", Dict.VERS_LOOSE, AttrCheckImpl.getCheckUrl() ),
124 new Attribute( "bgcolor", Dict.VERS_LOOSE, null ),
125 new Attribute( "bgproperties", Dict.VERS_PROPRIETARY, null ), /* BODY "fixed" fixes background */
126 new Attribute( "border", Dict.VERS_ALL, AttrCheckImpl.getCheckBool() ), /* like LENGTH + "border" */
127 new Attribute( "bordercolor", Dict.VERS_MICROSOFT, null ), /* used on TABLE */
128 new Attribute( "bottommargin", Dict.VERS_MICROSOFT, null ), /* used on BODY */
129 new Attribute( "cellpadding", Dict.VERS_FROM32, null ), /* % or pixel values */
130 new Attribute( "cellspacing", Dict.VERS_FROM32, null ),
131 new Attribute( "char", Dict.VERS_HTML40, null ),
132 new Attribute( "charoff", Dict.VERS_HTML40, null ),
133 new Attribute( "charset", Dict.VERS_HTML40, null ),
134 new Attribute( "checked", Dict.VERS_ALL, AttrCheckImpl.getCheckBool() ), /* i.e. "checked" or absent */
135 new Attribute( "cite", Dict.VERS_HTML40, AttrCheckImpl.getCheckUrl() ),
136 new Attribute( "class", Dict.VERS_HTML40, null ),
137 new Attribute( "classid", Dict.VERS_HTML40, AttrCheckImpl.getCheckUrl() ),
138 new Attribute( "clear", Dict.VERS_LOOSE, null ), /* BR: left, right, all */
139 new Attribute( "code", Dict.VERS_LOOSE, null ), /* APPLET */
140 new Attribute( "codebase", Dict.VERS_HTML40, AttrCheckImpl.getCheckUrl() ), /* OBJECT */
141 new Attribute( "codetype", Dict.VERS_HTML40, null ), /* OBJECT */
142 new Attribute( "color", Dict.VERS_LOOSE, null ), /* BASEFONT, FONT */
143 new Attribute( "cols", Dict.VERS_IFRAMES, null ), /* TABLE & FRAMESET */
144 new Attribute( "colspan", Dict.VERS_FROM32, null ),
145 new Attribute( "compact", Dict.VERS_ALL, AttrCheckImpl.getCheckBool() ), /* lists */
146 new Attribute( "content", Dict.VERS_ALL, null ), /* META */
147 new Attribute( "coords", Dict.VERS_FROM32, null ), /* AREA, A */
148 new Attribute( "data", Dict.VERS_HTML40, AttrCheckImpl.getCheckUrl() ), /* OBJECT */
149 new Attribute( "datafld", Dict.VERS_MICROSOFT, null ), /* used on DIV, IMG */
150 new Attribute( "dataformatas", Dict.VERS_MICROSOFT, null ), /* used on DIV, IMG */
151 new Attribute( "datapagesize", Dict.VERS_MICROSOFT, null ), /* used on DIV, IMG */
152 new Attribute( "datasrc", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckUrl() ), /* used on TABLE */
153 new Attribute( "datetime", Dict.VERS_HTML40, null ), /* INS, DEL */
154 new Attribute( "declare", Dict.VERS_HTML40, AttrCheckImpl.getCheckBool() ), /* OBJECT */
155 new Attribute( "defer", Dict.VERS_HTML40, AttrCheckImpl.getCheckBool() ), /* SCRIPT */
156 new Attribute( "dir", Dict.VERS_HTML40, null ), /* ltr or rtl */
157 new Attribute( "disabled", Dict.VERS_HTML40, AttrCheckImpl.getCheckBool() ), /* form fields */
158 new Attribute( "enctype", Dict.VERS_ALL, null ), /* FORM */
159 new Attribute( "face", Dict.VERS_LOOSE, null ), /* BASEFONT, FONT */
160 new Attribute( "for", Dict.VERS_HTML40, null ), /* LABEL */
161 new Attribute( "frame", Dict.VERS_HTML40, null ), /* TABLE */
162 new Attribute( "frameborder", Dict.VERS_FRAMES, null ), /* 0 or 1 */
163 new Attribute( "framespacing", Dict.VERS_PROPRIETARY, null ), /* pixel value */
164 new Attribute( "gridx", Dict.VERS_PROPRIETARY, null ), /* TABLE Adobe golive*/
165 new Attribute( "gridy", Dict.VERS_PROPRIETARY, null ), /* TABLE Adobe golive */
166 new Attribute( "headers", Dict.VERS_HTML40, null ), /* table cells */
167 new Attribute( "height", Dict.VERS_ALL, null ), /* pixels only for TH/TD */
168 new Attribute( "href", Dict.VERS_ALL, AttrCheckImpl.getCheckUrl() ), /* A, AREA, LINK and BASE */
169 new Attribute( "hreflang", Dict.VERS_HTML40, null ), /* A, LINK */
170 new Attribute( "hspace", Dict.VERS_ALL, null ), /* APPLET, IMG, OBJECT */
171 new Attribute( "http-equiv", Dict.VERS_ALL, null ), /* META */
172 new Attribute( "id", Dict.VERS_HTML40, AttrCheckImpl.getCheckId() ),
173 new Attribute( "ismap", Dict.VERS_ALL, AttrCheckImpl.getCheckBool() ), /* IMG */
174 new Attribute( "label", Dict.VERS_HTML40, null ), /* OPT, OPTGROUP */
175 new Attribute( "lang", Dict.VERS_HTML40, null ),
176 new Attribute( "language", Dict.VERS_LOOSE, null ), /* SCRIPT */
177 new Attribute( "last_modified", Dict.VERS_NETSCAPE, null ), /* A */
178 new Attribute( "last_visit", Dict.VERS_NETSCAPE, null ), /* A */
179 new Attribute( "leftmargin", Dict.VERS_MICROSOFT, null ), /* used on BODY */
180 new Attribute( "link", Dict.VERS_LOOSE, null ), /* BODY */
181 new Attribute( "longdesc", Dict.VERS_HTML40, AttrCheckImpl.getCheckUrl() ), /* IMG */
182 new Attribute( "lowsrc", Dict.VERS_PROPRIETARY, AttrCheckImpl.getCheckUrl() ), /* IMG */
183 new Attribute( "marginheight", Dict.VERS_IFRAMES, null ), /* FRAME, IFRAME, BODY */
184 new Attribute( "marginwidth", Dict.VERS_IFRAMES, null ), /* ditto */
185 new Attribute( "maxlength", Dict.VERS_ALL, null ), /* INPUT */
186 new Attribute( "media", Dict.VERS_HTML40, null ), /* STYLE, LINK */
187 new Attribute( "method", Dict.VERS_ALL, null ), /* FORM: get or post */
188 new Attribute( "multiple", Dict.VERS_ALL, AttrCheckImpl.getCheckBool() ), /* SELECT */
189 new Attribute( "name", Dict.VERS_ALL, AttrCheckImpl.getCheckName() ),
190 new Attribute( "nohref", Dict.VERS_FROM32, AttrCheckImpl.getCheckBool() ), /* AREA */
191 new Attribute( "noresize", Dict.VERS_FRAMES, AttrCheckImpl.getCheckBool() ), /* FRAME */
192 new Attribute( "noshade", Dict.VERS_LOOSE, AttrCheckImpl.getCheckBool() ), /* HR */
193 new Attribute( "nowrap", Dict.VERS_LOOSE, AttrCheckImpl.getCheckBool() ), /* table cells */
194 new Attribute( "object", Dict.VERS_HTML40_LOOSE, null ), /* APPLET */
195 new Attribute( "onblur", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
196 new Attribute( "onchange", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
197 new Attribute( "onclick", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
198 new Attribute( "ondblclick", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
199 new Attribute( "onkeydown", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
200 new Attribute( "onkeypress", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
201 new Attribute( "onkeyup", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
202 new Attribute( "onload", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
203 new Attribute( "onmousedown", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
204 new Attribute( "onmousemove", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
205 new Attribute( "onmouseout", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
206 new Attribute( "onmouseover", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
207 new Attribute( "onmouseup", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
208 new Attribute( "onsubmit", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
209 new Attribute( "onreset", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
210 new Attribute( "onselect", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
211 new Attribute( "onunload", Dict.VERS_HTML40, AttrCheckImpl.getCheckScript() ), /* event */
212 new Attribute( "onafterupdate", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* form fields */
213 new Attribute( "onbeforeupdate", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* form fields */
214 new Attribute( "onerrorupdate", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* form fields */
215 new Attribute( "onrowenter", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* form fields */
216 new Attribute( "onrowexit", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* form fields */
217 new Attribute( "onbeforeunload", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* form fields */
218 new Attribute( "ondatasetchanged", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* object, applet */
219 new Attribute( "ondataavailable", Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* object, applet */
220 new Attribute( "ondatasetcomplete",Dict.VERS_MICROSOFT, AttrCheckImpl.getCheckScript() ), /* object, applet */
221 new Attribute( "profile", Dict.VERS_HTML40, AttrCheckImpl.getCheckUrl() ), /* HEAD */
222 new Attribute( "prompt", Dict.VERS_LOOSE, null ), /* ISINDEX */
223 new Attribute( "readonly", Dict.VERS_HTML40, AttrCheckImpl.getCheckBool() ), /* form fields */
224 new Attribute( "rel", Dict.VERS_ALL, null ), /* A, LINK */
225 new Attribute( "rev", Dict.VERS_ALL, null ), /* A, LINK */
226 new Attribute( "rightmargin", Dict.VERS_MICROSOFT, null ), /* used on BODY */
227 new Attribute( "rows", Dict.VERS_ALL, null ), /* TEXTAREA */
228 new Attribute( "rowspan", Dict.VERS_ALL, null ), /* table cells */
229 new Attribute( "rules", Dict.VERS_HTML40, null ), /* TABLE */
230 new Attribute( "scheme", Dict.VERS_HTML40, null ), /* META */
231 new Attribute( "scope", Dict.VERS_HTML40, null ), /* table cells */
232 new Attribute( "scrolling", Dict.VERS_IFRAMES, null ), /* yes, no or auto */
233 new Attribute( "selected", Dict.VERS_ALL, AttrCheckImpl.getCheckBool() ), /* OPTION */
234 new Attribute( "shape", Dict.VERS_FROM32, null ), /* AREA, A */
235 new Attribute( "showgrid", Dict.VERS_PROPRIETARY, AttrCheckImpl.getCheckBool() ), /* TABLE Adobe golive */
236 new Attribute( "showgridx", Dict.VERS_PROPRIETARY, AttrCheckImpl.getCheckBool() ), /* TABLE Adobe golive*/
237 new Attribute( "showgridy", Dict.VERS_PROPRIETARY, AttrCheckImpl.getCheckBool() ), /* TABLE Adobe golive*/
238 new Attribute( "size", Dict.VERS_LOOSE, null ), /* HR, FONT, BASEFONT, SELECT */
239 new Attribute( "span", Dict.VERS_HTML40, null ), /* COL, COLGROUP */
240 new Attribute( "src", (short)(Dict.VERS_ALL | Dict.VERS_FRAMES), AttrCheckImpl.getCheckUrl() ), /* IMG, FRAME, IFRAME */
241 new Attribute( "standby", Dict.VERS_HTML40, null ), /* OBJECT */
242 new Attribute( "start", Dict.VERS_ALL, null ), /* OL */
243 new Attribute( "style", Dict.VERS_HTML40, null ),
244 new Attribute( "summary", Dict.VERS_HTML40, null ), /* TABLE */
245 new Attribute( "tabindex", Dict.VERS_HTML40, null ), /* fields, OBJECT and A */
246 new Attribute( "target", Dict.VERS_HTML40, null ), /* names a frame/window */
247 new Attribute( "text", Dict.VERS_LOOSE, null ), /* BODY */
248 new Attribute( "title", Dict.VERS_HTML40, null ), /* text tool tip */
249 new Attribute( "topmargin", Dict.VERS_MICROSOFT, null ), /* used on BODY */
250 new Attribute( "type", Dict.VERS_FROM32, null ), /* also used by SPACER */
251 new Attribute( "usemap", Dict.VERS_ALL, AttrCheckImpl.getCheckBool() ), /* things with images */
252 new Attribute( "valign", Dict.VERS_FROM32, AttrCheckImpl.getCheckValign() ),
253 new Attribute( "value", Dict.VERS_ALL, null ), /* OPTION, PARAM */
254 new Attribute( "valuetype", Dict.VERS_HTML40, null ), /* PARAM: data, ref, object */
255 new Attribute( "version", Dict.VERS_ALL, null ), /* HTML */
256 new Attribute( "vlink", Dict.VERS_LOOSE, null ), /* BODY */
257 new Attribute( "vspace", Dict.VERS_LOOSE, null ), /* IMG, OBJECT, APPLET */
258 new Attribute( "width", Dict.VERS_ALL, null ), /* pixels only for TD/TH */
259 new Attribute( "wrap", Dict.VERS_NETSCAPE, null ), /* textarea */
260 new Attribute( "xml:lang", Dict.VERS_XML, null ), /* XML language */
261 new Attribute( "xmlns", Dict.VERS_ALL, null ), /* name space */
265 public static Attribute attrHref = null;
266 public static Attribute attrSrc = null;
267 public static Attribute attrId = null;
268 public static Attribute attrName = null;
269 public static Attribute attrSummary = null;
270 public static Attribute attrAlt = null;
271 public static Attribute attrLongdesc = null;
272 public static Attribute attrUsemap = null;
273 public static Attribute attrIsmap = null;
274 public static Attribute attrLanguage = null;
275 public static Attribute attrType = null;
276 public static Attribute attrTitle = null;
277 public static Attribute attrXmlns = null;
278 public static Attribute attrValue = null;
279 public static Attribute attrContent = null;
280 public static Attribute attrDatafld = null;
281 public static Attribute attrWidth = null;
282 public static Attribute attrHeight = null;
284 public static AttributeTable getDefaultAttributeTable()
286 if ( defaultAttributeTable == null ) {
287 defaultAttributeTable = new AttributeTable();
288 for ( int i = 0; i < attrs.length; i++ ) {
289 defaultAttributeTable.install( attrs[i] );
291 attrHref = defaultAttributeTable.lookup("href");
292 attrSrc = defaultAttributeTable.lookup("src");
293 attrId = defaultAttributeTable.lookup("id");
294 attrName = defaultAttributeTable.lookup("name");
295 attrSummary = defaultAttributeTable.lookup("summary");
296 attrAlt = defaultAttributeTable.lookup("alt");
297 attrLongdesc = defaultAttributeTable.lookup("longdesc");
298 attrUsemap = defaultAttributeTable.lookup("usemap");
299 attrIsmap = defaultAttributeTable.lookup("ismap");
300 attrLanguage = defaultAttributeTable.lookup("language");
301 attrType = defaultAttributeTable.lookup("type");
302 attrTitle = defaultAttributeTable.lookup("title");
303 attrXmlns = defaultAttributeTable.lookup("xmlns");
304 attrValue = defaultAttributeTable.lookup("value");
305 attrContent = defaultAttributeTable.lookup("content");
306 attrDatafld = defaultAttributeTable.lookup("datafld");;
307 attrWidth = defaultAttributeTable.lookup("width");;
308 attrHeight = defaultAttributeTable.lookup("height");;
310 attrAlt.nowrap = true;
311 attrValue.nowrap = true;
312 attrContent.nowrap = true;
314 return defaultAttributeTable;