1. /*
  2. * @(#)HTML.java 1.39 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.text.html;
  8. import java.io.*;
  9. import java.util.Hashtable;
  10. import javax.swing.text.AttributeSet;
  11. import javax.swing.text.StyleConstants;
  12. import javax.swing.text.StyleContext;
  13. /**
  14. * Constants used in the <code>HTMLDocument</code>. These
  15. * are basically tag and attribute definitions.
  16. *
  17. * @author Timothy Prinzing
  18. * @author Sunita Mani
  19. *
  20. * @version 1.39 01/23/03
  21. */
  22. public class HTML {
  23. /**
  24. * Typesafe enumeration for an HTML tag. Although the
  25. * set of HTML tags is a closed set, we have left the
  26. * set open so that people can add their own tag types
  27. * to their custom parser and still communicate to the
  28. * reader.
  29. */
  30. public static class Tag {
  31. /** @since 1.3 */
  32. public Tag() {}
  33. /**
  34. * Creates a new <code>Tag</code> with the specified <code>id</code>,
  35. * and with <code>causesBreak</code> and <code>isBlock</code>
  36. * set to <code>false</code>.
  37. *
  38. * @param id the id of the new tag
  39. */
  40. protected Tag(String id) {
  41. this(id, false, false);
  42. }
  43. /**
  44. * Creates a new <code>Tag</code> with the specified <code>id</code>
  45. * <code>causesBreak</code> and <code>isBlock</code> are defined
  46. * by the user.
  47. *
  48. * @param id the id of the new tag
  49. * @param causesBreak <code>true</code> if this tag
  50. * causes a break to the flow of data
  51. * @param isBlock <code>true</code> if the tag is used
  52. * to add structure to a document
  53. */
  54. protected Tag(String id, boolean causesBreak, boolean isBlock) {
  55. name = id;
  56. this.breakTag = causesBreak;
  57. this.blockTag = isBlock;
  58. }
  59. /**
  60. * Returns <code>true</code> if this tag is a block
  61. * tag, which is a tag used to add structure to a
  62. * document.
  63. *
  64. * @return <code>true</code> if this tag is a block
  65. * tag, otherwise returns <code>false</code>
  66. */
  67. public boolean isBlock() {
  68. return blockTag;
  69. }
  70. /**
  71. * Returns <code>true</code> if this tag causes a
  72. * line break to the flow of data, otherwise returns
  73. * <code>false</code>.
  74. *
  75. * @return <code>true</code> if this tag causes a
  76. * line break to the flow of data, otherwise returns
  77. * <code>false</code>
  78. */
  79. public boolean breaksFlow() {
  80. return breakTag;
  81. }
  82. /**
  83. * Returns <code>true</code> if this tag is pre-formatted,
  84. * which is true if the tag is either <code>PRE</code> or
  85. * <code>TEXTAREA</code>.
  86. *
  87. * @return <code>true</code> if this tag is pre-formatted,
  88. * otherwise returns <code>false</code>
  89. */
  90. public boolean isPreformatted() {
  91. return (this == PRE || this == TEXTAREA);
  92. }
  93. /**
  94. * Returns the string representation of the
  95. * tag.
  96. *
  97. * @return the <code>String</code> representation of the tag
  98. */
  99. public String toString() {
  100. return name;
  101. }
  102. boolean blockTag;
  103. boolean breakTag;
  104. String name;
  105. boolean unknown;
  106. // --- Tag Names -----------------------------------
  107. public static final Tag A = new Tag("a");
  108. public static final Tag ADDRESS = new Tag("address");
  109. public static final Tag APPLET = new Tag("applet");
  110. public static final Tag AREA = new Tag("area");
  111. public static final Tag B = new Tag("b");
  112. public static final Tag BASE = new Tag("base");
  113. public static final Tag BASEFONT = new Tag("basefont");
  114. public static final Tag BIG = new Tag("big");
  115. public static final Tag BLOCKQUOTE = new Tag("blockquote", true, true);
  116. public static final Tag BODY = new Tag("body", true, true);
  117. public static final Tag BR = new Tag("br", true, false);
  118. public static final Tag CAPTION = new Tag("caption");
  119. public static final Tag CENTER = new Tag("center", true, false);
  120. public static final Tag CITE = new Tag("cite");
  121. public static final Tag CODE = new Tag("code");
  122. public static final Tag DD = new Tag("dd", true, true);
  123. public static final Tag DFN = new Tag("dfn");
  124. public static final Tag DIR = new Tag("dir", true, true);
  125. public static final Tag DIV = new Tag("div", true, true);
  126. public static final Tag DL = new Tag("dl", true, true);
  127. public static final Tag DT = new Tag("dt", true, true);
  128. public static final Tag EM = new Tag("em");
  129. public static final Tag FONT = new Tag("font");
  130. public static final Tag FORM = new Tag("form", true, false);
  131. public static final Tag FRAME = new Tag("frame");
  132. public static final Tag FRAMESET = new Tag("frameset");
  133. public static final Tag H1 = new Tag("h1", true, true);
  134. public static final Tag H2 = new Tag("h2", true, true);
  135. public static final Tag H3 = new Tag("h3", true, true);
  136. public static final Tag H4 = new Tag("h4", true, true);
  137. public static final Tag H5 = new Tag("h5", true, true);
  138. public static final Tag H6 = new Tag("h6", true, true);
  139. public static final Tag HEAD = new Tag("head", true, true);
  140. public static final Tag HR = new Tag("hr", true, false);
  141. public static final Tag HTML = new Tag("html", true, false);
  142. public static final Tag I = new Tag("i");
  143. public static final Tag IMG = new Tag("img");
  144. public static final Tag INPUT = new Tag("input");
  145. public static final Tag ISINDEX = new Tag("isindex", true, false);
  146. public static final Tag KBD = new Tag("kbd");
  147. public static final Tag LI = new Tag("li", true, true);
  148. public static final Tag LINK = new Tag("link");
  149. public static final Tag MAP = new Tag("map");
  150. public static final Tag MENU = new Tag("menu", true, true);
  151. public static final Tag META = new Tag("meta");
  152. /*public*/ static final Tag NOBR = new Tag("nobr");
  153. public static final Tag NOFRAMES = new Tag("noframes", true, true);
  154. public static final Tag OBJECT = new Tag("object");
  155. public static final Tag OL = new Tag("ol", true, true);
  156. public static final Tag OPTION = new Tag("option");
  157. public static final Tag P = new Tag("p", true, true);
  158. public static final Tag PARAM = new Tag("param");
  159. public static final Tag PRE = new Tag("pre", true, true);
  160. public static final Tag SAMP = new Tag("samp");
  161. public static final Tag SCRIPT = new Tag("script");
  162. public static final Tag SELECT = new Tag("select");
  163. public static final Tag SMALL = new Tag("small");
  164. public static final Tag SPAN = new Tag("span");
  165. public static final Tag STRIKE = new Tag("strike");
  166. public static final Tag S = new Tag("s");
  167. public static final Tag STRONG = new Tag("strong");
  168. public static final Tag STYLE = new Tag("style");
  169. public static final Tag SUB = new Tag("sub");
  170. public static final Tag SUP = new Tag("sup");
  171. public static final Tag TABLE = new Tag("table", false, true);
  172. public static final Tag TD = new Tag("td", true, true);
  173. public static final Tag TEXTAREA = new Tag("textarea");
  174. public static final Tag TH = new Tag("th", true, true);
  175. public static final Tag TITLE = new Tag("title", true, true);
  176. public static final Tag TR = new Tag("tr", false, true);
  177. public static final Tag TT = new Tag("tt");
  178. public static final Tag U = new Tag("u");
  179. public static final Tag UL = new Tag("ul", true, true);
  180. public static final Tag VAR = new Tag("var");
  181. /**
  182. * All text content must be in a paragraph element.
  183. * If a paragraph didn't exist when content was
  184. * encountered, a paragraph is manufactured.
  185. * <p>
  186. * This is a tag synthesized by the HTML reader.
  187. * Since elements are identified by their tag type,
  188. * we create a some fake tag types to mark the elements
  189. * that were manufactured.
  190. */
  191. public static final Tag IMPLIED = new Tag("p-implied");
  192. /**
  193. * All text content is labeled with this tag.
  194. * <p>
  195. * This is a tag synthesized by the HTML reader.
  196. * Since elements are identified by their tag type,
  197. * we create a some fake tag types to mark the elements
  198. * that were manufactured.
  199. */
  200. public static final Tag CONTENT = new Tag("content");
  201. /**
  202. * All comments are labeled with this tag.
  203. * <p>
  204. * This is a tag synthesized by the HTML reader.
  205. * Since elements are identified by their tag type,
  206. * we create a some fake tag types to mark the elements
  207. * that were manufactured.
  208. */
  209. public static final Tag COMMENT = new Tag("comment");
  210. static final Tag allTags[] = {
  211. A, ADDRESS, APPLET, AREA, B, BASE, BASEFONT, BIG,
  212. BLOCKQUOTE, BODY, BR, CAPTION, CENTER, CITE, CODE,
  213. DD, DFN, DIR, DIV, DL, DT, EM, FONT, FORM, FRAME,
  214. FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HR, HTML,
  215. I, IMG, INPUT, ISINDEX, KBD, LI, LINK, MAP, MENU,
  216. META, NOBR, NOFRAMES, OBJECT, OL, OPTION, P, PARAM,
  217. PRE, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, S,
  218. STRONG, STYLE, SUB, SUP, TABLE, TD, TEXTAREA,
  219. TH, TITLE, TR, TT, U, UL, VAR
  220. };
  221. static {
  222. // Force HTMLs static initialize to be loaded.
  223. getTag("html");
  224. }
  225. }
  226. // There is no unique instance of UnknownTag, so we allow it to be
  227. // Serializable.
  228. public static class UnknownTag extends Tag implements Serializable {
  229. /**
  230. * Creates a new <code>UnknownTag</code> with the specified
  231. * <code>id</code>.
  232. * @param id the id of the new tag
  233. */
  234. public UnknownTag(String id) {
  235. super(id);
  236. }
  237. /**
  238. * Returns the hash code which corresponds to the string
  239. * for this tag.
  240. */
  241. public int hashCode() {
  242. return toString().hashCode();
  243. }
  244. /**
  245. * Compares this object to the specifed object.
  246. * The result is <code>true</code> if and only if the argument is not
  247. * <code>null</code> and is an <code>UnknownTag</code> object
  248. * with the same name.
  249. *
  250. * @param obj the object to compare this tag with
  251. * @return <code>true</code> if the objects are equal;
  252. * <code>false</code> otherwise
  253. */
  254. public boolean equals(Object obj) {
  255. if (obj instanceof UnknownTag) {
  256. return toString().equals(obj.toString());
  257. }
  258. return false;
  259. }
  260. private void writeObject(java.io.ObjectOutputStream s)
  261. throws IOException {
  262. s.defaultWriteObject();
  263. s.writeBoolean(blockTag);
  264. s.writeBoolean(breakTag);
  265. s.writeBoolean(unknown);
  266. s.writeObject(name);
  267. }
  268. private void readObject(ObjectInputStream s)
  269. throws ClassNotFoundException, IOException {
  270. s.defaultReadObject();
  271. blockTag = s.readBoolean();
  272. breakTag = s.readBoolean();
  273. unknown = s.readBoolean();
  274. name = (String)s.readObject();
  275. }
  276. }
  277. /**
  278. * Typesafe enumeration representing an HTML
  279. * attribute.
  280. */
  281. public static final class Attribute {
  282. /**
  283. * Creates a new <code>Attribute</code> with the specified
  284. * <code>id</code>.
  285. *
  286. * @param id the id of the new <code>Attribute</code>
  287. */
  288. Attribute(String id) {
  289. name = id;
  290. }
  291. /**
  292. * Returns the string representation of this attribute.
  293. * @return the string representation of this attribute
  294. */
  295. public String toString() {
  296. return name;
  297. }
  298. private String name;
  299. public static final Attribute SIZE = new Attribute("size");
  300. public static final Attribute COLOR = new Attribute("color");
  301. public static final Attribute CLEAR = new Attribute("clear");
  302. public static final Attribute BACKGROUND = new Attribute("background");
  303. public static final Attribute BGCOLOR = new Attribute("bgcolor");
  304. public static final Attribute TEXT = new Attribute("text");
  305. public static final Attribute LINK = new Attribute("link");
  306. public static final Attribute VLINK = new Attribute("vlink");
  307. public static final Attribute ALINK = new Attribute("alink");
  308. public static final Attribute WIDTH = new Attribute("width");
  309. public static final Attribute HEIGHT = new Attribute("height");
  310. public static final Attribute ALIGN = new Attribute("align");
  311. public static final Attribute NAME = new Attribute("name");
  312. public static final Attribute HREF = new Attribute("href");
  313. public static final Attribute REL = new Attribute("rel");
  314. public static final Attribute REV = new Attribute("rev");
  315. public static final Attribute TITLE = new Attribute("title");
  316. public static final Attribute TARGET = new Attribute("target");
  317. public static final Attribute SHAPE = new Attribute("shape");
  318. public static final Attribute COORDS = new Attribute("coords");
  319. public static final Attribute ISMAP = new Attribute("ismap");
  320. public static final Attribute NOHREF = new Attribute("nohref");
  321. public static final Attribute ALT = new Attribute("alt");
  322. public static final Attribute ID = new Attribute("id");
  323. public static final Attribute SRC = new Attribute("src");
  324. public static final Attribute HSPACE = new Attribute("hspace");
  325. public static final Attribute VSPACE = new Attribute("vspace");
  326. public static final Attribute USEMAP = new Attribute("usemap");
  327. public static final Attribute LOWSRC = new Attribute("lowsrc");
  328. public static final Attribute CODEBASE = new Attribute("codebase");
  329. public static final Attribute CODE = new Attribute("code");
  330. public static final Attribute ARCHIVE = new Attribute("archive");
  331. public static final Attribute VALUE = new Attribute("value");
  332. public static final Attribute VALUETYPE = new Attribute("valuetype");
  333. public static final Attribute TYPE = new Attribute("type");
  334. public static final Attribute CLASS = new Attribute("class");
  335. public static final Attribute STYLE = new Attribute("style");
  336. public static final Attribute LANG = new Attribute("lang");
  337. public static final Attribute FACE = new Attribute("face");
  338. public static final Attribute DIR = new Attribute("dir");
  339. public static final Attribute DECLARE = new Attribute("declare");
  340. public static final Attribute CLASSID = new Attribute("classid");
  341. public static final Attribute DATA = new Attribute("data");
  342. public static final Attribute CODETYPE = new Attribute("codetype");
  343. public static final Attribute STANDBY = new Attribute("standby");
  344. public static final Attribute BORDER = new Attribute("border");
  345. public static final Attribute SHAPES = new Attribute("shapes");
  346. public static final Attribute NOSHADE = new Attribute("noshade");
  347. public static final Attribute COMPACT = new Attribute("compact");
  348. public static final Attribute START = new Attribute("start");
  349. public static final Attribute ACTION = new Attribute("action");
  350. public static final Attribute METHOD = new Attribute("method");
  351. public static final Attribute ENCTYPE = new Attribute("enctype");
  352. public static final Attribute CHECKED = new Attribute("checked");
  353. public static final Attribute MAXLENGTH = new Attribute("maxlength");
  354. public static final Attribute MULTIPLE = new Attribute("multiple");
  355. public static final Attribute SELECTED = new Attribute("selected");
  356. public static final Attribute ROWS = new Attribute("rows");
  357. public static final Attribute COLS = new Attribute("cols");
  358. public static final Attribute DUMMY = new Attribute("dummy");
  359. public static final Attribute CELLSPACING = new Attribute("cellspacing");
  360. public static final Attribute CELLPADDING = new Attribute("cellpadding");
  361. public static final Attribute VALIGN = new Attribute("valign");
  362. public static final Attribute HALIGN = new Attribute("halign");
  363. public static final Attribute NOWRAP = new Attribute("nowrap");
  364. public static final Attribute ROWSPAN = new Attribute("rowspan");
  365. public static final Attribute COLSPAN = new Attribute("colspan");
  366. public static final Attribute PROMPT = new Attribute("prompt");
  367. public static final Attribute HTTPEQUIV = new Attribute("http-equiv");
  368. public static final Attribute CONTENT = new Attribute("content");
  369. public static final Attribute LANGUAGE = new Attribute("language");
  370. public static final Attribute VERSION = new Attribute("version");
  371. public static final Attribute N = new Attribute("n");
  372. public static final Attribute FRAMEBORDER = new Attribute("frameborder");
  373. public static final Attribute MARGINWIDTH = new Attribute("marginwidth");
  374. public static final Attribute MARGINHEIGHT = new Attribute("marginheight");
  375. public static final Attribute SCROLLING = new Attribute("scrolling");
  376. public static final Attribute NORESIZE = new Attribute("noresize");
  377. public static final Attribute ENDTAG = new Attribute("endtag");
  378. public static final Attribute COMMENT = new Attribute("comment");
  379. static final Attribute MEDIA = new Attribute("media");
  380. static final Attribute allAttributes[] = {
  381. FACE,
  382. COMMENT,
  383. SIZE,
  384. COLOR,
  385. CLEAR,
  386. BACKGROUND,
  387. BGCOLOR,
  388. TEXT,
  389. LINK,
  390. VLINK,
  391. ALINK,
  392. WIDTH,
  393. HEIGHT,
  394. ALIGN,
  395. NAME,
  396. HREF,
  397. REL,
  398. REV,
  399. TITLE,
  400. TARGET,
  401. SHAPE,
  402. COORDS,
  403. ISMAP,
  404. NOHREF,
  405. ALT,
  406. ID,
  407. SRC,
  408. HSPACE,
  409. VSPACE,
  410. USEMAP,
  411. LOWSRC,
  412. CODEBASE,
  413. CODE,
  414. ARCHIVE,
  415. VALUE,
  416. VALUETYPE,
  417. TYPE,
  418. CLASS,
  419. STYLE,
  420. LANG,
  421. DIR,
  422. DECLARE,
  423. CLASSID,
  424. DATA,
  425. CODETYPE,
  426. STANDBY,
  427. BORDER,
  428. SHAPES,
  429. NOSHADE,
  430. COMPACT,
  431. START,
  432. ACTION,
  433. METHOD,
  434. ENCTYPE,
  435. CHECKED,
  436. MAXLENGTH,
  437. MULTIPLE,
  438. SELECTED,
  439. ROWS,
  440. COLS,
  441. DUMMY,
  442. CELLSPACING,
  443. CELLPADDING,
  444. VALIGN,
  445. HALIGN,
  446. NOWRAP,
  447. ROWSPAN,
  448. COLSPAN,
  449. PROMPT,
  450. HTTPEQUIV,
  451. CONTENT,
  452. LANGUAGE,
  453. VERSION,
  454. N,
  455. FRAMEBORDER,
  456. MARGINWIDTH,
  457. MARGINHEIGHT,
  458. SCROLLING,
  459. NORESIZE,
  460. MEDIA,
  461. ENDTAG
  462. };
  463. }
  464. // The secret to 73, is that, given that the Hashtable contents
  465. // never change once the static initialization happens, the initial size
  466. // that the hashtable grew to was determined, and then that very size
  467. // is used.
  468. //
  469. private static final Hashtable tagHashtable = new Hashtable(73);
  470. /** Maps from StyleConstant key to HTML.Tag. */
  471. private static final Hashtable scMapping = new Hashtable(8);
  472. static {
  473. for (int i = 0; i < Tag.allTags.length; i++ ) {
  474. tagHashtable.put(Tag.allTags[i].toString(), Tag.allTags[i]);
  475. StyleContext.registerStaticAttributeKey(Tag.allTags[i]);
  476. }
  477. StyleContext.registerStaticAttributeKey(Tag.IMPLIED);
  478. StyleContext.registerStaticAttributeKey(Tag.CONTENT);
  479. StyleContext.registerStaticAttributeKey(Tag.COMMENT);
  480. for (int i = 0; i < Attribute.allAttributes.length; i++) {
  481. StyleContext.registerStaticAttributeKey(Attribute.
  482. allAttributes[i]);
  483. }
  484. scMapping.put(StyleConstants.Bold, Tag.B);
  485. scMapping.put(StyleConstants.Italic, Tag.I);
  486. scMapping.put(StyleConstants.Underline, Tag.U);
  487. scMapping.put(StyleConstants.StrikeThrough, Tag.STRIKE);
  488. scMapping.put(StyleConstants.Superscript, Tag.SUP);
  489. scMapping.put(StyleConstants.Subscript, Tag.SUB);
  490. scMapping.put(StyleConstants.FontFamily, Tag.FONT);
  491. scMapping.put(StyleConstants.FontSize, Tag.FONT);
  492. }
  493. /**
  494. * Returns the set of actual HTML tags that
  495. * are recognized by the default HTML reader.
  496. * This set does not include tags that are
  497. * manufactured by the reader.
  498. */
  499. public static Tag[] getAllTags() {
  500. Tag[] tags = new Tag[Tag.allTags.length];
  501. System.arraycopy(Tag.allTags, 0, tags, 0, Tag.allTags.length);
  502. return tags;
  503. }
  504. /**
  505. * Fetches a tag constant for a well-known tag name (i.e. one of
  506. * the tags in the set {A, ADDRESS, APPLET, AREA, B,
  507. * BASE, BASEFONT, BIG,
  508. * BLOCKQUOTE, BODY, BR, CAPTION, CENTER, CITE, CODE,
  509. * DD, DFN, DIR, DIV, DL, DT, EM, FONT, FORM, FRAME,
  510. * FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HR, HTML,
  511. * I, IMG, INPUT, ISINDEX, KBD, LI, LINK, MAP, MENU,
  512. * META, NOBR, NOFRAMES, OBJECT, OL, OPTION, P, PARAM,
  513. * PRE, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, S,
  514. * STRONG, STYLE, SUB, SUP, TABLE, TD, TEXTAREA,
  515. * TH, TITLE, TR, TT, U, UL, VAR}. If the given
  516. * name does not represent one of the well-known tags, then
  517. * <code>null</code> will be returned.
  518. *
  519. * @param tagName the <code>String</code> name requested
  520. * @return a tag constant corresponding to the <code>tagName</code>,
  521. * or <code>null</code> if not found
  522. */
  523. public static Tag getTag(String tagName) {
  524. Object t = tagHashtable.get(tagName);
  525. return (t == null ? null : (Tag)t);
  526. }
  527. /**
  528. * Returns the HTML <code>Tag</code> associated with the
  529. * <code>StyleConstants</code> key <code>sc</code>.
  530. * If no matching <code>Tag</code> is found, returns
  531. * <code>null</code>.
  532. *
  533. * @param sc the <code>StyleConstants</code> key
  534. * @return tag which corresponds to <code>sc</code>, or
  535. * <code>null</code> if not found
  536. */
  537. static Tag getTagForStyleConstantsKey(StyleConstants sc) {
  538. return (Tag)scMapping.get(sc);
  539. }
  540. /**
  541. * Fetches an integer attribute value. Attribute values
  542. * are stored as a string, and this is a convenience method
  543. * to convert to an actual integer.
  544. *
  545. * @param attr the set of attributes to use to try to fetch a value
  546. * @param key the key to use to fetch the value
  547. * @param def the default value to use if the attribute isn't
  548. * defined or there is an error converting to an integer
  549. */
  550. public static int getIntegerAttributeValue(AttributeSet attr,
  551. Attribute key, int def) {
  552. int value = def;
  553. String istr = (String) attr.getAttribute(key);
  554. if (istr != null) {
  555. try {
  556. value = Integer.valueOf(istr).intValue();
  557. } catch (NumberFormatException e) {
  558. value = def;
  559. }
  560. }
  561. return value;
  562. }
  563. // This is used in cases where the value for the attribute has not
  564. // been specified.
  565. //
  566. public static final String NULL_ATTRIBUTE_VALUE = "#DEFAULT";
  567. // size determined similar to size of tagHashtable
  568. private static final Hashtable attHashtable = new Hashtable(77);
  569. static {
  570. for (int i = 0; i < Attribute.allAttributes.length; i++ ) {
  571. attHashtable.put(Attribute.allAttributes[i].toString(), Attribute.allAttributes[i]);
  572. }
  573. }
  574. /**
  575. * Returns the set of HTML attributes recognized.
  576. * @return the set of HTML attributes recognized
  577. */
  578. public static Attribute[] getAllAttributeKeys() {
  579. Attribute[] attributes = new Attribute[Attribute.allAttributes.length];
  580. System.arraycopy(Attribute.allAttributes, 0,
  581. attributes, 0, Attribute.allAttributes.length);
  582. return attributes;
  583. }
  584. /**
  585. * Fetches an attribute constant for a well-known attribute name
  586. * (i.e. one of the attributes in the set {FACE, COMMENT, SIZE,
  587. * COLOR, CLEAR, BACKGROUND, BGCOLOR, TEXT, LINK, VLINK, ALINK,
  588. * WIDTH, HEIGHT, ALIGN, NAME, HREF, REL, REV, TITLE, TARGET,
  589. * SHAPE, COORDS, ISMAP, NOHREF, ALT, ID, SRC, HSPACE, VSPACE,
  590. * USEMAP, LOWSRC, CODEBASE, CODE, ARCHIVE, VALUE, VALUETYPE,
  591. * TYPE, CLASS, STYLE, LANG, DIR, DECLARE, CLASSID, DATA, CODETYPE,
  592. * STANDBY, BORDER, SHAPES, NOSHADE, COMPACT, START, ACTION, METHOD,
  593. * ENCTYPE, CHECKED, MAXLENGTH, MULTIPLE, SELECTED, ROWS, COLS,
  594. * DUMMY, CELLSPACING, CELLPADDING, VALIGN, HALIGN, NOWRAP, ROWSPAN,
  595. * COLSPAN, PROMPT, HTTPEQUIV, CONTENT, LANGUAGE, VERSION, N,
  596. * FRAMEBORDER, MARGINWIDTH, MARGINHEIGHT, SCROLLING, NORESIZE,
  597. * MEDIA, ENDTAG}).
  598. * If the given name does not represent one of the well-known attributes,
  599. * then <code>null</code> will be returned.
  600. *
  601. * @param attName the <code>String</code> requested
  602. * @return the <code>Attribute</code> corresponding to <code>attName</code>
  603. */
  604. public static Attribute getAttributeKey(String attName) {
  605. Object a = attHashtable.get(attName);
  606. if (a == null) {
  607. return null;
  608. }
  609. return (Attribute)a;
  610. }
  611. }