001: /*
002: * @(#)AttributeTable.java 1.11 2000/08/16
003: *
004: */
005:
006: package org.w3c.tidy;
007:
008: import java.util.Hashtable;
009: import java.util.Enumeration;
010:
011: /**
012: *
013: * HTML attribute hash table
014: *
015: * (c) 1998-2000 (W3C) MIT, INRIA, Keio University
016: * See Tidy.java for the copyright notice.
017: * Derived from <a href="http://www.w3.org/People/Raggett/tidy">
018: * HTML Tidy Release 4 Aug 2000</a>
019: *
020: * @author Dave Raggett <dsr@w3.org>
021: * @author Andy Quick <ac.quick@sympatico.ca> (translation to Java)
022: * @version 1.0, 1999/05/22
023: * @version 1.0.1, 1999/05/29
024: * @version 1.1, 1999/06/18 Java Bean
025: * @version 1.2, 1999/07/10 Tidy Release 7 Jul 1999
026: * @version 1.3, 1999/07/30 Tidy Release 26 Jul 1999
027: * @version 1.4, 1999/09/04 DOM support
028: * @version 1.5, 1999/10/23 Tidy Release 27 Sep 1999
029: * @version 1.6, 1999/11/01 Tidy Release 22 Oct 1999
030: * @version 1.7, 1999/12/06 Tidy Release 30 Nov 1999
031: * @version 1.8, 2000/01/22 Tidy Release 13 Jan 2000
032: * @version 1.9, 2000/06/03 Tidy Release 30 Apr 2000
033: * @version 1.10, 2000/07/22 Tidy Release 8 Jul 2000
034: * @version 1.11, 2000/08/16 Tidy Release 4 Aug 2000
035: */
036:
037: public class AttributeTable {
038:
039: public AttributeTable() {
040: }
041:
042: public Attribute lookup(String name) {
043: return (Attribute) attributeHashtable.get(name);
044: }
045:
046: public Attribute install(Attribute attr) {
047: return (Attribute) attributeHashtable.put(attr.name, attr);
048: }
049:
050: /* public method for finding attribute definition by name */
051: public Attribute findAttribute(AttVal attval) {
052: Attribute np;
053:
054: if (attval.attribute != null) {
055: np = lookup(attval.attribute);
056: return np;
057: }
058:
059: return null;
060: }
061:
062: public boolean isUrl(String attrname) {
063: Attribute np;
064:
065: np = lookup(attrname);
066: return (np != null && np.attrchk == AttrCheckImpl.getCheckUrl());
067: }
068:
069: public boolean isScript(String attrname) {
070: Attribute np;
071:
072: np = lookup(attrname);
073: return (np != null && np.attrchk == AttrCheckImpl
074: .getCheckScript());
075: }
076:
077: public boolean isLiteralAttribute(String attrname) {
078: Attribute np;
079:
080: np = lookup(attrname);
081: return (np != null && np.literal);
082: }
083:
084: /*
085: Henry Zrepa reports that some folk are
086: using embed with script attributes where
087: newlines are signficant. These need to be
088: declared and handled specially!
089: */
090: public void declareLiteralAttrib(String name) {
091: Attribute attrib = lookup(name);
092:
093: if (attrib == null)
094: attrib = install(new Attribute(name, Dict.VERS_PROPRIETARY,
095: null));
096:
097: attrib.literal = true;
098: }
099:
100: private Hashtable attributeHashtable = new Hashtable();
101:
102: private static AttributeTable defaultAttributeTable = null;
103:
104: private static Attribute[] attrs = {
105:
106: new Attribute("abbr", Dict.VERS_HTML40, null),
107: new Attribute("accept-charset", Dict.VERS_HTML40, null),
108: new Attribute("accept", Dict.VERS_ALL, null),
109: new Attribute("accesskey", Dict.VERS_HTML40, null),
110: new Attribute("action", Dict.VERS_ALL, AttrCheckImpl
111: .getCheckUrl()),
112: new Attribute("add_date", Dict.VERS_NETSCAPE, null), /* A */
113: new Attribute("align", Dict.VERS_ALL, AttrCheckImpl
114: .getCheckAlign()), /* set varies with element */
115: new Attribute("alink", Dict.VERS_LOOSE, null),
116: new Attribute("alt", Dict.VERS_ALL, null),
117: new Attribute("archive", Dict.VERS_HTML40, null), /* space or comma separated list */
118: new Attribute("axis", Dict.VERS_HTML40, null),
119: new Attribute("background", Dict.VERS_LOOSE, AttrCheckImpl
120: .getCheckUrl()),
121: new Attribute("bgcolor", Dict.VERS_LOOSE, null),
122: new Attribute("bgproperties", Dict.VERS_PROPRIETARY, null), /* BODY "fixed" fixes background */
123: new Attribute("border", Dict.VERS_ALL, AttrCheckImpl
124: .getCheckBool()), /* like LENGTH + "border" */
125: new Attribute("bordercolor", Dict.VERS_MICROSOFT, null), /* used on TABLE */
126: new Attribute("bottommargin", Dict.VERS_MICROSOFT, null), /* used on BODY */
127: new Attribute("cellpadding", Dict.VERS_FROM32, null), /* % or pixel values */
128: new Attribute("cellspacing", Dict.VERS_FROM32, null),
129: new Attribute("char", Dict.VERS_HTML40, null),
130: new Attribute("charoff", Dict.VERS_HTML40, null),
131: new Attribute("charset", Dict.VERS_HTML40, null),
132: new Attribute("checked", Dict.VERS_ALL, AttrCheckImpl
133: .getCheckBool()), /* i.e. "checked" or absent */
134: new Attribute("cite", Dict.VERS_HTML40, AttrCheckImpl
135: .getCheckUrl()),
136: new Attribute("class", Dict.VERS_HTML40, null),
137: new Attribute("classid", Dict.VERS_HTML40, AttrCheckImpl
138: .getCheckUrl()),
139: new Attribute("clear", Dict.VERS_LOOSE, null), /* BR: left, right, all */
140: new Attribute("code", Dict.VERS_LOOSE, null), /* APPLET */
141: new Attribute("codebase", Dict.VERS_HTML40, AttrCheckImpl
142: .getCheckUrl()), /* OBJECT */
143: new Attribute("codetype", Dict.VERS_HTML40, null), /* OBJECT */
144: new Attribute("color", Dict.VERS_LOOSE, null), /* BASEFONT, FONT */
145: new Attribute("cols", Dict.VERS_IFRAMES, null), /* TABLE & FRAMESET */
146: new Attribute("colspan", Dict.VERS_FROM32, null),
147: new Attribute("compact", Dict.VERS_ALL, AttrCheckImpl
148: .getCheckBool()), /* lists */
149: new Attribute("content", Dict.VERS_ALL, null), /* META */
150: new Attribute("coords", Dict.VERS_FROM32, null), /* AREA, A */
151: new Attribute("data", Dict.VERS_HTML40, AttrCheckImpl
152: .getCheckUrl()), /* OBJECT */
153: new Attribute("datafld", Dict.VERS_MICROSOFT, null), /* used on DIV, IMG */
154: new Attribute("dataformatas", Dict.VERS_MICROSOFT, null), /* used on DIV, IMG */
155: new Attribute("datapagesize", Dict.VERS_MICROSOFT, null), /* used on DIV, IMG */
156: new Attribute("datasrc", Dict.VERS_MICROSOFT, AttrCheckImpl
157: .getCheckUrl()), /* used on TABLE */
158: new Attribute("datetime", Dict.VERS_HTML40, null), /* INS, DEL */
159: new Attribute("declare", Dict.VERS_HTML40, AttrCheckImpl
160: .getCheckBool()), /* OBJECT */
161: new Attribute("defer", Dict.VERS_HTML40, AttrCheckImpl
162: .getCheckBool()), /* SCRIPT */
163: new Attribute("dir", Dict.VERS_HTML40, null), /* ltr or rtl */
164: new Attribute("disabled", Dict.VERS_HTML40, AttrCheckImpl
165: .getCheckBool()), /* form fields */
166: new Attribute("enctype", Dict.VERS_ALL, null), /* FORM */
167: new Attribute("face", Dict.VERS_LOOSE, null), /* BASEFONT, FONT */
168: new Attribute("for", Dict.VERS_HTML40, null), /* LABEL */
169: new Attribute("frame", Dict.VERS_HTML40, null), /* TABLE */
170: new Attribute("frameborder", Dict.VERS_FRAMES, null), /* 0 or 1 */
171: new Attribute("framespacing", Dict.VERS_PROPRIETARY, null), /* pixel value */
172: new Attribute("gridx", Dict.VERS_PROPRIETARY, null), /* TABLE Adobe golive*/
173: new Attribute("gridy", Dict.VERS_PROPRIETARY, null), /* TABLE Adobe golive */
174: new Attribute("headers", Dict.VERS_HTML40, null), /* table cells */
175: new Attribute("height", Dict.VERS_ALL, null), /* pixels only for TH/TD */
176: new Attribute("href", Dict.VERS_ALL, AttrCheckImpl
177: .getCheckUrl()), /* A, AREA, LINK and BASE */
178: new Attribute("hreflang", Dict.VERS_HTML40, null), /* A, LINK */
179: new Attribute("hspace", Dict.VERS_ALL, null), /* APPLET, IMG, OBJECT */
180: new Attribute("http-equiv", Dict.VERS_ALL, null), /* META */
181: new Attribute("id", Dict.VERS_HTML40, AttrCheckImpl
182: .getCheckId()),
183: new Attribute("ismap", Dict.VERS_ALL, AttrCheckImpl
184: .getCheckBool()), /* IMG */
185: new Attribute("label", Dict.VERS_HTML40, null), /* OPT, OPTGROUP */
186: new Attribute("lang", Dict.VERS_HTML40, null),
187: new Attribute("language", Dict.VERS_LOOSE, null), /* SCRIPT */
188: new Attribute("last_modified", Dict.VERS_NETSCAPE, null), /* A */
189: new Attribute("last_visit", Dict.VERS_NETSCAPE, null), /* A */
190: new Attribute("leftmargin", Dict.VERS_MICROSOFT, null), /* used on BODY */
191: new Attribute("link", Dict.VERS_LOOSE, null), /* BODY */
192: new Attribute("longdesc", Dict.VERS_HTML40, AttrCheckImpl
193: .getCheckUrl()), /* IMG */
194: new Attribute("lowsrc", Dict.VERS_PROPRIETARY,
195: AttrCheckImpl.getCheckUrl()), /* IMG */
196: new Attribute("marginheight", Dict.VERS_IFRAMES, null), /* FRAME, IFRAME, BODY */
197: new Attribute("marginwidth", Dict.VERS_IFRAMES, null), /* ditto */
198: new Attribute("maxlength", Dict.VERS_ALL, null), /* INPUT */
199: new Attribute("media", Dict.VERS_HTML40, null), /* STYLE, LINK */
200: new Attribute("method", Dict.VERS_ALL, null), /* FORM: get or post */
201: new Attribute("multiple", Dict.VERS_ALL, AttrCheckImpl
202: .getCheckBool()), /* SELECT */
203: new Attribute("name", Dict.VERS_ALL, AttrCheckImpl
204: .getCheckName()),
205: new Attribute("nohref", Dict.VERS_FROM32, AttrCheckImpl
206: .getCheckBool()), /* AREA */
207: new Attribute("noresize", Dict.VERS_FRAMES, AttrCheckImpl
208: .getCheckBool()), /* FRAME */
209: new Attribute("noshade", Dict.VERS_LOOSE, AttrCheckImpl
210: .getCheckBool()), /* HR */
211: new Attribute("nowrap", Dict.VERS_LOOSE, AttrCheckImpl
212: .getCheckBool()), /* table cells */
213: new Attribute("object", Dict.VERS_HTML40_LOOSE, null), /* APPLET */
214: new Attribute("onblur", Dict.VERS_HTML40, AttrCheckImpl
215: .getCheckScript()), /* event */
216: new Attribute("onchange", Dict.VERS_HTML40, AttrCheckImpl
217: .getCheckScript()), /* event */
218: new Attribute("onclick", Dict.VERS_HTML40, AttrCheckImpl
219: .getCheckScript()), /* event */
220: new Attribute("ondblclick", Dict.VERS_HTML40, AttrCheckImpl
221: .getCheckScript()), /* event */
222: new Attribute("onkeydown", Dict.VERS_HTML40, AttrCheckImpl
223: .getCheckScript()), /* event */
224: new Attribute("onkeypress", Dict.VERS_HTML40, AttrCheckImpl
225: .getCheckScript()), /* event */
226: new Attribute("onkeyup", Dict.VERS_HTML40, AttrCheckImpl
227: .getCheckScript()), /* event */
228: new Attribute("onload", Dict.VERS_HTML40, AttrCheckImpl
229: .getCheckScript()), /* event */
230: new Attribute("onmousedown", Dict.VERS_HTML40,
231: AttrCheckImpl.getCheckScript()), /* event */
232: new Attribute("onmousemove", Dict.VERS_HTML40,
233: AttrCheckImpl.getCheckScript()), /* event */
234: new Attribute("onmouseout", Dict.VERS_HTML40, AttrCheckImpl
235: .getCheckScript()), /* event */
236: new Attribute("onmouseover", Dict.VERS_HTML40,
237: AttrCheckImpl.getCheckScript()), /* event */
238: new Attribute("onmouseup", Dict.VERS_HTML40, AttrCheckImpl
239: .getCheckScript()), /* event */
240: new Attribute("onsubmit", Dict.VERS_HTML40, AttrCheckImpl
241: .getCheckScript()), /* event */
242: new Attribute("onreset", Dict.VERS_HTML40, AttrCheckImpl
243: .getCheckScript()), /* event */
244: new Attribute("onselect", Dict.VERS_HTML40, AttrCheckImpl
245: .getCheckScript()), /* event */
246: new Attribute("onunload", Dict.VERS_HTML40, AttrCheckImpl
247: .getCheckScript()), /* event */
248: new Attribute("onafterupdate", Dict.VERS_MICROSOFT,
249: AttrCheckImpl.getCheckScript()), /* form fields */
250: new Attribute("onbeforeupdate", Dict.VERS_MICROSOFT,
251: AttrCheckImpl.getCheckScript()), /* form fields */
252: new Attribute("onerrorupdate", Dict.VERS_MICROSOFT,
253: AttrCheckImpl.getCheckScript()), /* form fields */
254: new Attribute("onrowenter", Dict.VERS_MICROSOFT,
255: AttrCheckImpl.getCheckScript()), /* form fields */
256: new Attribute("onrowexit", Dict.VERS_MICROSOFT,
257: AttrCheckImpl.getCheckScript()), /* form fields */
258: new Attribute("onbeforeunload", Dict.VERS_MICROSOFT,
259: AttrCheckImpl.getCheckScript()), /* form fields */
260: new Attribute("ondatasetchanged", Dict.VERS_MICROSOFT,
261: AttrCheckImpl.getCheckScript()), /* object, applet */
262: new Attribute("ondataavailable", Dict.VERS_MICROSOFT,
263: AttrCheckImpl.getCheckScript()), /* object, applet */
264: new Attribute("ondatasetcomplete", Dict.VERS_MICROSOFT,
265: AttrCheckImpl.getCheckScript()), /* object, applet */
266: new Attribute("profile", Dict.VERS_HTML40, AttrCheckImpl
267: .getCheckUrl()), /* HEAD */
268: new Attribute("prompt", Dict.VERS_LOOSE, null), /* ISINDEX */
269: new Attribute("readonly", Dict.VERS_HTML40, AttrCheckImpl
270: .getCheckBool()), /* form fields */
271: new Attribute("rel", Dict.VERS_ALL, null), /* A, LINK */
272: new Attribute("rev", Dict.VERS_ALL, null), /* A, LINK */
273: new Attribute("rightmargin", Dict.VERS_MICROSOFT, null), /* used on BODY */
274: new Attribute("rows", Dict.VERS_ALL, null), /* TEXTAREA */
275: new Attribute("rowspan", Dict.VERS_ALL, null), /* table cells */
276: new Attribute("rules", Dict.VERS_HTML40, null), /* TABLE */
277: new Attribute("scheme", Dict.VERS_HTML40, null), /* META */
278: new Attribute("scope", Dict.VERS_HTML40, null), /* table cells */
279: new Attribute("scrolling", Dict.VERS_IFRAMES, null), /* yes, no or auto */
280: new Attribute("selected", Dict.VERS_ALL, AttrCheckImpl
281: .getCheckBool()), /* OPTION */
282: new Attribute("shape", Dict.VERS_FROM32, null), /* AREA, A */
283: new Attribute("showgrid", Dict.VERS_PROPRIETARY,
284: AttrCheckImpl.getCheckBool()), /* TABLE Adobe golive */
285: new Attribute("showgridx", Dict.VERS_PROPRIETARY,
286: AttrCheckImpl.getCheckBool()), /* TABLE Adobe golive*/
287: new Attribute("showgridy", Dict.VERS_PROPRIETARY,
288: AttrCheckImpl.getCheckBool()), /* TABLE Adobe golive*/
289: new Attribute("size", Dict.VERS_LOOSE, null), /* HR, FONT, BASEFONT, SELECT */
290: new Attribute("span", Dict.VERS_HTML40, null), /* COL, COLGROUP */
291: new Attribute("src",
292: (short) (Dict.VERS_ALL | Dict.VERS_FRAMES),
293: AttrCheckImpl.getCheckUrl()), /* IMG, FRAME, IFRAME */
294: new Attribute("standby", Dict.VERS_HTML40, null), /* OBJECT */
295: new Attribute("start", Dict.VERS_ALL, null), /* OL */
296: new Attribute("style", Dict.VERS_HTML40, null),
297: new Attribute("summary", Dict.VERS_HTML40, null), /* TABLE */
298: new Attribute("tabindex", Dict.VERS_HTML40, null), /* fields, OBJECT and A */
299: new Attribute("target", Dict.VERS_HTML40, null), /* names a frame/window */
300: new Attribute("text", Dict.VERS_LOOSE, null), /* BODY */
301: new Attribute("title", Dict.VERS_HTML40, null), /* text tool tip */
302: new Attribute("topmargin", Dict.VERS_MICROSOFT, null), /* used on BODY */
303: new Attribute("type", Dict.VERS_FROM32, null), /* also used by SPACER */
304: new Attribute("usemap", Dict.VERS_ALL, AttrCheckImpl
305: .getCheckBool()), /* things with images */
306: new Attribute("valign", Dict.VERS_FROM32, AttrCheckImpl
307: .getCheckValign()),
308: new Attribute("value", Dict.VERS_ALL, null), /* OPTION, PARAM */
309: new Attribute("valuetype", Dict.VERS_HTML40, null), /* PARAM: data, ref, object */
310: new Attribute("version", Dict.VERS_ALL, null), /* HTML */
311: new Attribute("vlink", Dict.VERS_LOOSE, null), /* BODY */
312: new Attribute("vspace", Dict.VERS_LOOSE, null), /* IMG, OBJECT, APPLET */
313: new Attribute("width", Dict.VERS_ALL, null), /* pixels only for TD/TH */
314: new Attribute("wrap", Dict.VERS_NETSCAPE, null), /* textarea */
315: new Attribute("xml:lang", Dict.VERS_XML, null), /* XML language */
316: new Attribute("xmlns", Dict.VERS_ALL, null), /* name space */
317:
318: };
319:
320: public static Attribute attrHref = null;
321: public static Attribute attrSrc = null;
322: public static Attribute attrId = null;
323: public static Attribute attrName = null;
324: public static Attribute attrSummary = null;
325: public static Attribute attrAlt = null;
326: public static Attribute attrLongdesc = null;
327: public static Attribute attrUsemap = null;
328: public static Attribute attrIsmap = null;
329: public static Attribute attrLanguage = null;
330: public static Attribute attrType = null;
331: public static Attribute attrTitle = null;
332: public static Attribute attrXmlns = null;
333: public static Attribute attrValue = null;
334: public static Attribute attrContent = null;
335: public static Attribute attrDatafld = null;
336: public static Attribute attrWidth = null;
337: public static Attribute attrHeight = null;
338:
339: public static AttributeTable getDefaultAttributeTable() {
340: if (defaultAttributeTable == null) {
341: defaultAttributeTable = new AttributeTable();
342: for (int i = 0; i < attrs.length; i++) {
343: defaultAttributeTable.install(attrs[i]);
344: }
345: attrHref = defaultAttributeTable.lookup("href");
346: attrSrc = defaultAttributeTable.lookup("src");
347: attrId = defaultAttributeTable.lookup("id");
348: attrName = defaultAttributeTable.lookup("name");
349: attrSummary = defaultAttributeTable.lookup("summary");
350: attrAlt = defaultAttributeTable.lookup("alt");
351: attrLongdesc = defaultAttributeTable.lookup("longdesc");
352: attrUsemap = defaultAttributeTable.lookup("usemap");
353: attrIsmap = defaultAttributeTable.lookup("ismap");
354: attrLanguage = defaultAttributeTable.lookup("language");
355: attrType = defaultAttributeTable.lookup("type");
356: attrTitle = defaultAttributeTable.lookup("title");
357: attrXmlns = defaultAttributeTable.lookup("xmlns");
358: attrValue = defaultAttributeTable.lookup("value");
359: attrContent = defaultAttributeTable.lookup("content");
360: attrDatafld = defaultAttributeTable.lookup("datafld");
361: ;
362: attrWidth = defaultAttributeTable.lookup("width");
363: ;
364: attrHeight = defaultAttributeTable.lookup("height");
365: ;
366:
367: attrAlt.nowrap = true;
368: attrValue.nowrap = true;
369: attrContent.nowrap = true;
370: }
371: return defaultAttributeTable;
372: }
373:
374: }
|