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