001 /*
002 * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package javax.swing.text.html;
026
027 import java.io.*;
028 import java.util.Hashtable;
029 import javax.swing.text.AttributeSet;
030 import javax.swing.text.StyleConstants;
031 import javax.swing.text.StyleContext;
032
033 /**
034 * Constants used in the <code>HTMLDocument</code>. These
035 * are basically tag and attribute definitions.
036 *
037 * @author Timothy Prinzing
038 * @author Sunita Mani
039 *
040 * @version 1.49 05/05/07
041 */
042 public class HTML {
043
044 /**
045 * Typesafe enumeration for an HTML tag. Although the
046 * set of HTML tags is a closed set, we have left the
047 * set open so that people can add their own tag types
048 * to their custom parser and still communicate to the
049 * reader.
050 */
051 public static class Tag {
052
053 /** @since 1.3 */
054 public Tag() {
055 }
056
057 /**
058 * Creates a new <code>Tag</code> with the specified <code>id</code>,
059 * and with <code>causesBreak</code> and <code>isBlock</code>
060 * set to <code>false</code>.
061 *
062 * @param id the id of the new tag
063 */
064 protected Tag(String id) {
065 this (id, false, false);
066 }
067
068 /**
069 * Creates a new <code>Tag</code> with the specified <code>id</code>;
070 * <code>causesBreak</code> and <code>isBlock</code> are defined
071 * by the user.
072 *
073 * @param id the id of the new tag
074 * @param causesBreak <code>true</code> if this tag
075 * causes a break to the flow of data
076 * @param isBlock <code>true</code> if the tag is used
077 * to add structure to a document
078 */
079 protected Tag(String id, boolean causesBreak, boolean isBlock) {
080 name = id;
081 this .breakTag = causesBreak;
082 this .blockTag = isBlock;
083 }
084
085 /**
086 * Returns <code>true</code> if this tag is a block
087 * tag, which is a tag used to add structure to a
088 * document.
089 *
090 * @return <code>true</code> if this tag is a block
091 * tag, otherwise returns <code>false</code>
092 */
093 public boolean isBlock() {
094 return blockTag;
095 }
096
097 /**
098 * Returns <code>true</code> if this tag causes a
099 * line break to the flow of data, otherwise returns
100 * <code>false</code>.
101 *
102 * @return <code>true</code> if this tag causes a
103 * line break to the flow of data, otherwise returns
104 * <code>false</code>
105 */
106 public boolean breaksFlow() {
107 return breakTag;
108 }
109
110 /**
111 * Returns <code>true</code> if this tag is pre-formatted,
112 * which is true if the tag is either <code>PRE</code> or
113 * <code>TEXTAREA</code>.
114 *
115 * @return <code>true</code> if this tag is pre-formatted,
116 * otherwise returns <code>false</code>
117 */
118 public boolean isPreformatted() {
119 return (this == PRE || this == TEXTAREA);
120 }
121
122 /**
123 * Returns the string representation of the
124 * tag.
125 *
126 * @return the <code>String</code> representation of the tag
127 */
128 public String toString() {
129 return name;
130 }
131
132 /**
133 * Returns <code>true</code> if this tag is considered to be a paragraph
134 * in the internal HTML model. <code>false</code> - otherwise.
135 *
136 * @return <code>true</code> if this tag is considered to be a paragraph
137 * in the internal HTML model. <code>false</code> - otherwise.
138 * @see javax.swing.text.html.HTMLDocument#HTMLReader#ParagraphAction
139 */
140 boolean isParagraph() {
141 return (this == P || this == IMPLIED || this == DT
142 || this == H1 || this == H2 || this == H3
143 || this == H4 || this == H5 || this == H6);
144 }
145
146 boolean blockTag;
147 boolean breakTag;
148 String name;
149 boolean unknown;
150
151 // --- Tag Names -----------------------------------
152
153 public static final Tag A = new Tag("a");
154 public static final Tag ADDRESS = new Tag("address");
155 public static final Tag APPLET = new Tag("applet");
156 public static final Tag AREA = new Tag("area");
157 public static final Tag B = new Tag("b");
158 public static final Tag BASE = new Tag("base");
159 public static final Tag BASEFONT = new Tag("basefont");
160 public static final Tag BIG = new Tag("big");
161 public static final Tag BLOCKQUOTE = new Tag("blockquote",
162 true, true);
163 public static final Tag BODY = new Tag("body", true, true);
164 public static final Tag BR = new Tag("br", true, false);
165 public static final Tag CAPTION = new Tag("caption");
166 public static final Tag CENTER = new Tag("center", true, false);
167 public static final Tag CITE = new Tag("cite");
168 public static final Tag CODE = new Tag("code");
169 public static final Tag DD = new Tag("dd", true, true);
170 public static final Tag DFN = new Tag("dfn");
171 public static final Tag DIR = new Tag("dir", true, true);
172 public static final Tag DIV = new Tag("div", true, true);
173 public static final Tag DL = new Tag("dl", true, true);
174 public static final Tag DT = new Tag("dt", true, true);
175 public static final Tag EM = new Tag("em");
176 public static final Tag FONT = new Tag("font");
177 public static final Tag FORM = new Tag("form", true, false);
178 public static final Tag FRAME = new Tag("frame");
179 public static final Tag FRAMESET = new Tag("frameset");
180 public static final Tag H1 = new Tag("h1", true, true);
181 public static final Tag H2 = new Tag("h2", true, true);
182 public static final Tag H3 = new Tag("h3", true, true);
183 public static final Tag H4 = new Tag("h4", true, true);
184 public static final Tag H5 = new Tag("h5", true, true);
185 public static final Tag H6 = new Tag("h6", true, true);
186 public static final Tag HEAD = new Tag("head", true, true);
187 public static final Tag HR = new Tag("hr", true, false);
188 public static final Tag HTML = new Tag("html", true, false);
189 public static final Tag I = new Tag("i");
190 public static final Tag IMG = new Tag("img");
191 public static final Tag INPUT = new Tag("input");
192 public static final Tag ISINDEX = new Tag("isindex", true,
193 false);
194 public static final Tag KBD = new Tag("kbd");
195 public static final Tag LI = new Tag("li", true, true);
196 public static final Tag LINK = new Tag("link");
197 public static final Tag MAP = new Tag("map");
198 public static final Tag MENU = new Tag("menu", true, true);
199 public static final Tag META = new Tag("meta");
200 /*public*/static final Tag NOBR = new Tag("nobr");
201 public static final Tag NOFRAMES = new Tag("noframes", true,
202 true);
203 public static final Tag OBJECT = new Tag("object");
204 public static final Tag OL = new Tag("ol", true, true);
205 public static final Tag OPTION = new Tag("option");
206 public static final Tag P = new Tag("p", true, true);
207 public static final Tag PARAM = new Tag("param");
208 public static final Tag PRE = new Tag("pre", true, true);
209 public static final Tag SAMP = new Tag("samp");
210 public static final Tag SCRIPT = new Tag("script");
211 public static final Tag SELECT = new Tag("select");
212 public static final Tag SMALL = new Tag("small");
213 public static final Tag SPAN = new Tag("span");
214 public static final Tag STRIKE = new Tag("strike");
215 public static final Tag S = new Tag("s");
216 public static final Tag STRONG = new Tag("strong");
217 public static final Tag STYLE = new Tag("style");
218 public static final Tag SUB = new Tag("sub");
219 public static final Tag SUP = new Tag("sup");
220 public static final Tag TABLE = new Tag("table", false, true);
221 public static final Tag TD = new Tag("td", true, true);
222 public static final Tag TEXTAREA = new Tag("textarea");
223 public static final Tag TH = new Tag("th", true, true);
224 public static final Tag TITLE = new Tag("title", true, true);
225 public static final Tag TR = new Tag("tr", false, true);
226 public static final Tag TT = new Tag("tt");
227 public static final Tag U = new Tag("u");
228 public static final Tag UL = new Tag("ul", true, true);
229 public static final Tag VAR = new Tag("var");
230
231 /**
232 * All text content must be in a paragraph element.
233 * If a paragraph didn't exist when content was
234 * encountered, a paragraph is manufactured.
235 * <p>
236 * This is a tag synthesized by the HTML reader.
237 * Since elements are identified by their tag type,
238 * we create a some fake tag types to mark the elements
239 * that were manufactured.
240 */
241 public static final Tag IMPLIED = new Tag("p-implied");
242
243 /**
244 * All text content is labeled with this tag.
245 * <p>
246 * This is a tag synthesized by the HTML reader.
247 * Since elements are identified by their tag type,
248 * we create a some fake tag types to mark the elements
249 * that were manufactured.
250 */
251 public static final Tag CONTENT = new Tag("content");
252
253 /**
254 * All comments are labeled with this tag.
255 * <p>
256 * This is a tag synthesized by the HTML reader.
257 * Since elements are identified by their tag type,
258 * we create a some fake tag types to mark the elements
259 * that were manufactured.
260 */
261 public static final Tag COMMENT = new Tag("comment");
262
263 static final Tag allTags[] = { A, ADDRESS, APPLET, AREA, B,
264 BASE, BASEFONT, BIG, BLOCKQUOTE, BODY, BR, CAPTION,
265 CENTER, CITE, CODE, DD, DFN, DIR, DIV, DL, DT, EM,
266 FONT, FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6,
267 HEAD, HR, HTML, I, IMG, INPUT, ISINDEX, KBD, LI, LINK,
268 MAP, MENU, META, NOBR, NOFRAMES, OBJECT, OL, OPTION, P,
269 PARAM, PRE, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE,
270 S, STRONG, STYLE, SUB, SUP, TABLE, TD, TEXTAREA, TH,
271 TITLE, TR, TT, U, UL, VAR };
272
273 static {
274 // Force HTMLs static initialize to be loaded.
275 getTag("html");
276 }
277 }
278
279 // There is no unique instance of UnknownTag, so we allow it to be
280 // Serializable.
281 public static class UnknownTag extends Tag implements Serializable {
282
283 /**
284 * Creates a new <code>UnknownTag</code> with the specified
285 * <code>id</code>.
286 * @param id the id of the new tag
287 */
288 public UnknownTag(String id) {
289 super (id);
290 }
291
292 /**
293 * Returns the hash code which corresponds to the string
294 * for this tag.
295 */
296 public int hashCode() {
297 return toString().hashCode();
298 }
299
300 /**
301 * Compares this object to the specifed object.
302 * The result is <code>true</code> if and only if the argument is not
303 * <code>null</code> and is an <code>UnknownTag</code> object
304 * with the same name.
305 *
306 * @param obj the object to compare this tag with
307 * @return <code>true</code> if the objects are equal;
308 * <code>false</code> otherwise
309 */
310 public boolean equals(Object obj) {
311 if (obj instanceof UnknownTag) {
312 return toString().equals(obj.toString());
313 }
314 return false;
315 }
316
317 private void writeObject(java.io.ObjectOutputStream s)
318 throws IOException {
319 s.defaultWriteObject();
320 s.writeBoolean(blockTag);
321 s.writeBoolean(breakTag);
322 s.writeBoolean(unknown);
323 s.writeObject(name);
324 }
325
326 private void readObject(ObjectInputStream s)
327 throws ClassNotFoundException, IOException {
328 s.defaultReadObject();
329 blockTag = s.readBoolean();
330 breakTag = s.readBoolean();
331 unknown = s.readBoolean();
332 name = (String) s.readObject();
333 }
334 }
335
336 /**
337 * Typesafe enumeration representing an HTML
338 * attribute.
339 */
340 public static final class Attribute {
341
342 /**
343 * Creates a new <code>Attribute</code> with the specified
344 * <code>id</code>.
345 *
346 * @param id the id of the new <code>Attribute</code>
347 */
348 Attribute(String id) {
349 name = id;
350 }
351
352 /**
353 * Returns the string representation of this attribute.
354 * @return the string representation of this attribute
355 */
356 public String toString() {
357 return name;
358 }
359
360 private String name;
361
362 public static final Attribute SIZE = new Attribute("size");
363 public static final Attribute COLOR = new Attribute("color");
364 public static final Attribute CLEAR = new Attribute("clear");
365 public static final Attribute BACKGROUND = new Attribute(
366 "background");
367 public static final Attribute BGCOLOR = new Attribute("bgcolor");
368 public static final Attribute TEXT = new Attribute("text");
369 public static final Attribute LINK = new Attribute("link");
370 public static final Attribute VLINK = new Attribute("vlink");
371 public static final Attribute ALINK = new Attribute("alink");
372 public static final Attribute WIDTH = new Attribute("width");
373 public static final Attribute HEIGHT = new Attribute("height");
374 public static final Attribute ALIGN = new Attribute("align");
375 public static final Attribute NAME = new Attribute("name");
376 public static final Attribute HREF = new Attribute("href");
377 public static final Attribute REL = new Attribute("rel");
378 public static final Attribute REV = new Attribute("rev");
379 public static final Attribute TITLE = new Attribute("title");
380 public static final Attribute TARGET = new Attribute("target");
381 public static final Attribute SHAPE = new Attribute("shape");
382 public static final Attribute COORDS = new Attribute("coords");
383 public static final Attribute ISMAP = new Attribute("ismap");
384 public static final Attribute NOHREF = new Attribute("nohref");
385 public static final Attribute ALT = new Attribute("alt");
386 public static final Attribute ID = new Attribute("id");
387 public static final Attribute SRC = new Attribute("src");
388 public static final Attribute HSPACE = new Attribute("hspace");
389 public static final Attribute VSPACE = new Attribute("vspace");
390 public static final Attribute USEMAP = new Attribute("usemap");
391 public static final Attribute LOWSRC = new Attribute("lowsrc");
392 public static final Attribute CODEBASE = new Attribute(
393 "codebase");
394 public static final Attribute CODE = new Attribute("code");
395 public static final Attribute ARCHIVE = new Attribute("archive");
396 public static final Attribute VALUE = new Attribute("value");
397 public static final Attribute VALUETYPE = new Attribute(
398 "valuetype");
399 public static final Attribute TYPE = new Attribute("type");
400 public static final Attribute CLASS = new Attribute("class");
401 public static final Attribute STYLE = new Attribute("style");
402 public static final Attribute LANG = new Attribute("lang");
403 public static final Attribute FACE = new Attribute("face");
404 public static final Attribute DIR = new Attribute("dir");
405 public static final Attribute DECLARE = new Attribute("declare");
406 public static final Attribute CLASSID = new Attribute("classid");
407 public static final Attribute DATA = new Attribute("data");
408 public static final Attribute CODETYPE = new Attribute(
409 "codetype");
410 public static final Attribute STANDBY = new Attribute("standby");
411 public static final Attribute BORDER = new Attribute("border");
412 public static final Attribute SHAPES = new Attribute("shapes");
413 public static final Attribute NOSHADE = new Attribute("noshade");
414 public static final Attribute COMPACT = new Attribute("compact");
415 public static final Attribute START = new Attribute("start");
416 public static final Attribute ACTION = new Attribute("action");
417 public static final Attribute METHOD = new Attribute("method");
418 public static final Attribute ENCTYPE = new Attribute("enctype");
419 public static final Attribute CHECKED = new Attribute("checked");
420 public static final Attribute MAXLENGTH = new Attribute(
421 "maxlength");
422 public static final Attribute MULTIPLE = new Attribute(
423 "multiple");
424 public static final Attribute SELECTED = new Attribute(
425 "selected");
426 public static final Attribute ROWS = new Attribute("rows");
427 public static final Attribute COLS = new Attribute("cols");
428 public static final Attribute DUMMY = new Attribute("dummy");
429 public static final Attribute CELLSPACING = new Attribute(
430 "cellspacing");
431 public static final Attribute CELLPADDING = new Attribute(
432 "cellpadding");
433 public static final Attribute VALIGN = new Attribute("valign");
434 public static final Attribute HALIGN = new Attribute("halign");
435 public static final Attribute NOWRAP = new Attribute("nowrap");
436 public static final Attribute ROWSPAN = new Attribute("rowspan");
437 public static final Attribute COLSPAN = new Attribute("colspan");
438 public static final Attribute PROMPT = new Attribute("prompt");
439 public static final Attribute HTTPEQUIV = new Attribute(
440 "http-equiv");
441 public static final Attribute CONTENT = new Attribute("content");
442 public static final Attribute LANGUAGE = new Attribute(
443 "language");
444 public static final Attribute VERSION = new Attribute("version");
445 public static final Attribute N = new Attribute("n");
446 public static final Attribute FRAMEBORDER = new Attribute(
447 "frameborder");
448 public static final Attribute MARGINWIDTH = new Attribute(
449 "marginwidth");
450 public static final Attribute MARGINHEIGHT = new Attribute(
451 "marginheight");
452 public static final Attribute SCROLLING = new Attribute(
453 "scrolling");
454 public static final Attribute NORESIZE = new Attribute(
455 "noresize");
456 public static final Attribute ENDTAG = new Attribute("endtag");
457 public static final Attribute COMMENT = new Attribute("comment");
458 static final Attribute MEDIA = new Attribute("media");
459
460 static final Attribute allAttributes[] = { FACE, COMMENT, SIZE,
461 COLOR, CLEAR, BACKGROUND, BGCOLOR, TEXT, LINK, VLINK,
462 ALINK, WIDTH, HEIGHT, ALIGN, NAME, HREF, REL, REV,
463 TITLE, TARGET, SHAPE, COORDS, ISMAP, NOHREF, ALT, ID,
464 SRC, HSPACE, VSPACE, USEMAP, LOWSRC, CODEBASE, CODE,
465 ARCHIVE, VALUE, VALUETYPE, TYPE, CLASS, STYLE, LANG,
466 DIR, DECLARE, CLASSID, DATA, CODETYPE, STANDBY, BORDER,
467 SHAPES, NOSHADE, COMPACT, START, ACTION, METHOD,
468 ENCTYPE, CHECKED, MAXLENGTH, MULTIPLE, SELECTED, ROWS,
469 COLS, DUMMY, CELLSPACING, CELLPADDING, VALIGN, HALIGN,
470 NOWRAP, ROWSPAN, COLSPAN, PROMPT, HTTPEQUIV, CONTENT,
471 LANGUAGE, VERSION, N, FRAMEBORDER, MARGINWIDTH,
472 MARGINHEIGHT, SCROLLING, NORESIZE, MEDIA, ENDTAG };
473 }
474
475 // The secret to 73, is that, given that the Hashtable contents
476 // never change once the static initialization happens, the initial size
477 // that the hashtable grew to was determined, and then that very size
478 // is used.
479 //
480 private static final Hashtable tagHashtable = new Hashtable(73);
481
482 /** Maps from StyleConstant key to HTML.Tag. */
483 private static final Hashtable scMapping = new Hashtable(8);
484
485 static {
486
487 for (int i = 0; i < Tag.allTags.length; i++) {
488 tagHashtable.put(Tag.allTags[i].toString(), Tag.allTags[i]);
489 StyleContext.registerStaticAttributeKey(Tag.allTags[i]);
490 }
491 StyleContext.registerStaticAttributeKey(Tag.IMPLIED);
492 StyleContext.registerStaticAttributeKey(Tag.CONTENT);
493 StyleContext.registerStaticAttributeKey(Tag.COMMENT);
494 for (int i = 0; i < Attribute.allAttributes.length; i++) {
495 StyleContext
496 .registerStaticAttributeKey(Attribute.allAttributes[i]);
497 }
498 StyleContext
499 .registerStaticAttributeKey(HTML.NULL_ATTRIBUTE_VALUE);
500 scMapping.put(StyleConstants.Bold, Tag.B);
501 scMapping.put(StyleConstants.Italic, Tag.I);
502 scMapping.put(StyleConstants.Underline, Tag.U);
503 scMapping.put(StyleConstants.StrikeThrough, Tag.STRIKE);
504 scMapping.put(StyleConstants.Superscript, Tag.SUP);
505 scMapping.put(StyleConstants.Subscript, Tag.SUB);
506 scMapping.put(StyleConstants.FontFamily, Tag.FONT);
507 scMapping.put(StyleConstants.FontSize, Tag.FONT);
508 }
509
510 /**
511 * Returns the set of actual HTML tags that
512 * are recognized by the default HTML reader.
513 * This set does not include tags that are
514 * manufactured by the reader.
515 */
516 public static Tag[] getAllTags() {
517 Tag[] tags = new Tag[Tag.allTags.length];
518 System.arraycopy(Tag.allTags, 0, tags, 0, Tag.allTags.length);
519 return tags;
520 }
521
522 /**
523 * Fetches a tag constant for a well-known tag name (i.e. one of
524 * the tags in the set {A, ADDRESS, APPLET, AREA, B,
525 * BASE, BASEFONT, BIG,
526 * BLOCKQUOTE, BODY, BR, CAPTION, CENTER, CITE, CODE,
527 * DD, DFN, DIR, DIV, DL, DT, EM, FONT, FORM, FRAME,
528 * FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HR, HTML,
529 * I, IMG, INPUT, ISINDEX, KBD, LI, LINK, MAP, MENU,
530 * META, NOBR, NOFRAMES, OBJECT, OL, OPTION, P, PARAM,
531 * PRE, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, S,
532 * STRONG, STYLE, SUB, SUP, TABLE, TD, TEXTAREA,
533 * TH, TITLE, TR, TT, U, UL, VAR}. If the given
534 * name does not represent one of the well-known tags, then
535 * <code>null</code> will be returned.
536 *
537 * @param tagName the <code>String</code> name requested
538 * @return a tag constant corresponding to the <code>tagName</code>,
539 * or <code>null</code> if not found
540 */
541 public static Tag getTag(String tagName) {
542
543 Object t = tagHashtable.get(tagName);
544 return (t == null ? null : (Tag) t);
545 }
546
547 /**
548 * Returns the HTML <code>Tag</code> associated with the
549 * <code>StyleConstants</code> key <code>sc</code>.
550 * If no matching <code>Tag</code> is found, returns
551 * <code>null</code>.
552 *
553 * @param sc the <code>StyleConstants</code> key
554 * @return tag which corresponds to <code>sc</code>, or
555 * <code>null</code> if not found
556 */
557 static Tag getTagForStyleConstantsKey(StyleConstants sc) {
558 return (Tag) scMapping.get(sc);
559 }
560
561 /**
562 * Fetches an integer attribute value. Attribute values
563 * are stored as a string, and this is a convenience method
564 * to convert to an actual integer.
565 *
566 * @param attr the set of attributes to use to try to fetch a value
567 * @param key the key to use to fetch the value
568 * @param def the default value to use if the attribute isn't
569 * defined or there is an error converting to an integer
570 */
571 public static int getIntegerAttributeValue(AttributeSet attr,
572 Attribute key, int def) {
573 int value = def;
574 String istr = (String) attr.getAttribute(key);
575 if (istr != null) {
576 try {
577 value = Integer.valueOf(istr).intValue();
578 } catch (NumberFormatException e) {
579 value = def;
580 }
581 }
582 return value;
583 }
584
585 // This is used in cases where the value for the attribute has not
586 // been specified.
587 //
588 public static final String NULL_ATTRIBUTE_VALUE = "#DEFAULT";
589
590 // size determined similar to size of tagHashtable
591 private static final Hashtable attHashtable = new Hashtable(77);
592
593 static {
594
595 for (int i = 0; i < Attribute.allAttributes.length; i++) {
596 attHashtable.put(Attribute.allAttributes[i].toString(),
597 Attribute.allAttributes[i]);
598 }
599 }
600
601 /**
602 * Returns the set of HTML attributes recognized.
603 * @return the set of HTML attributes recognized
604 */
605 public static Attribute[] getAllAttributeKeys() {
606 Attribute[] attributes = new Attribute[Attribute.allAttributes.length];
607 System.arraycopy(Attribute.allAttributes, 0, attributes, 0,
608 Attribute.allAttributes.length);
609 return attributes;
610 }
611
612 /**
613 * Fetches an attribute constant for a well-known attribute name
614 * (i.e. one of the attributes in the set {FACE, COMMENT, SIZE,
615 * COLOR, CLEAR, BACKGROUND, BGCOLOR, TEXT, LINK, VLINK, ALINK,
616 * WIDTH, HEIGHT, ALIGN, NAME, HREF, REL, REV, TITLE, TARGET,
617 * SHAPE, COORDS, ISMAP, NOHREF, ALT, ID, SRC, HSPACE, VSPACE,
618 * USEMAP, LOWSRC, CODEBASE, CODE, ARCHIVE, VALUE, VALUETYPE,
619 * TYPE, CLASS, STYLE, LANG, DIR, DECLARE, CLASSID, DATA, CODETYPE,
620 * STANDBY, BORDER, SHAPES, NOSHADE, COMPACT, START, ACTION, METHOD,
621 * ENCTYPE, CHECKED, MAXLENGTH, MULTIPLE, SELECTED, ROWS, COLS,
622 * DUMMY, CELLSPACING, CELLPADDING, VALIGN, HALIGN, NOWRAP, ROWSPAN,
623 * COLSPAN, PROMPT, HTTPEQUIV, CONTENT, LANGUAGE, VERSION, N,
624 * FRAMEBORDER, MARGINWIDTH, MARGINHEIGHT, SCROLLING, NORESIZE,
625 * MEDIA, ENDTAG}).
626 * If the given name does not represent one of the well-known attributes,
627 * then <code>null</code> will be returned.
628 *
629 * @param attName the <code>String</code> requested
630 * @return the <code>Attribute</code> corresponding to <code>attName</code>
631 */
632 public static Attribute getAttributeKey(String attName) {
633 Object a = attHashtable.get(attName);
634 if (a == null) {
635 return null;
636 }
637 return (Attribute) a;
638 }
639
640 }
|