1. /*
  2. * @(#)AttributeList.java 1.6 00/02/02
  3. *
  4. * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.text.html.parser;
  11. import java.util.Vector;
  12. import java.util.Hashtable;
  13. import java.util.Enumeration;
  14. import java.io.*;
  15. /**
  16. * This class defines the attributes of an SGML element
  17. * as described in a DTD using the ATTLIST construct.
  18. * An AttributeList can be obtained from the Element
  19. * class using the getAttributes() method.
  20. * <p>
  21. * It is actually an element in a linked list. Use the
  22. * getNext() method repeatedly to enumerate all the attributes
  23. * of an element.
  24. *
  25. * @see Element
  26. * @author Arthur Van Hoff
  27. * @version 1.6 02/02/00
  28. *
  29. */
  30. public final
  31. class AttributeList implements DTDConstants, Serializable {
  32. public String name;
  33. public int type;
  34. public Vector values;
  35. public int modifier;
  36. public String value;
  37. public AttributeList next;
  38. AttributeList() {
  39. }
  40. /**
  41. * Create an attribute list element.
  42. */
  43. public AttributeList(String name) {
  44. this.name = name;
  45. }
  46. /**
  47. * Create an attribute list element.
  48. */
  49. public AttributeList(String name, int type, int modifier, String value, Vector values, AttributeList next) {
  50. this.name = name;
  51. this.type = type;
  52. this.modifier = modifier;
  53. this.value = value;
  54. this.values = values;
  55. this.next = next;
  56. }
  57. /**
  58. * @return attribute name
  59. */
  60. public String getName() {
  61. return name;
  62. }
  63. /**
  64. * @return attribute type
  65. * @see DTDConstants
  66. */
  67. public int getType() {
  68. return type;
  69. }
  70. /**
  71. * @return attribute modifer
  72. * @see DTDConstants
  73. */
  74. public int getModifier() {
  75. return modifier;
  76. }
  77. /**
  78. * @return possible attribute values
  79. */
  80. public Enumeration getValues() {
  81. return (values != null) ? values.elements() : null;
  82. }
  83. /**
  84. * @return default attribute value
  85. */
  86. public String getValue() {
  87. return value;
  88. }
  89. /**
  90. * @return the next attribute in the list
  91. */
  92. public AttributeList getNext() {
  93. return next;
  94. }
  95. /**
  96. * @return string representation
  97. */
  98. public String toString() {
  99. return name;
  100. }
  101. /**
  102. * Create a hashtable of attribute types.
  103. */
  104. static Hashtable attributeTypes = new Hashtable();
  105. static void defineAttributeType(String nm, int val) {
  106. Integer num = new Integer(val);
  107. attributeTypes.put(nm, num);
  108. attributeTypes.put(num, nm);
  109. }
  110. static {
  111. defineAttributeType("CDATA", CDATA);
  112. defineAttributeType("ENTITY", ENTITY);
  113. defineAttributeType("ENTITIES", ENTITIES);
  114. defineAttributeType("ID", ID);
  115. defineAttributeType("IDREF", IDREF);
  116. defineAttributeType("IDREFS", IDREFS);
  117. defineAttributeType("NAME", NAME);
  118. defineAttributeType("NAMES", NAMES);
  119. defineAttributeType("NMTOKEN", NMTOKEN);
  120. defineAttributeType("NMTOKENS", NMTOKENS);
  121. defineAttributeType("NOTATION", NOTATION);
  122. defineAttributeType("NUMBER", NUMBER);
  123. defineAttributeType("NUMBERS", NUMBERS);
  124. defineAttributeType("NUTOKEN", NUTOKEN);
  125. defineAttributeType("NUTOKENS", NUTOKENS);
  126. attributeTypes.put("fixed", new Integer(FIXED));
  127. attributeTypes.put("required", new Integer(REQUIRED));
  128. attributeTypes.put("current", new Integer(CURRENT));
  129. attributeTypes.put("conref", new Integer(CONREF));
  130. attributeTypes.put("implied", new Integer(IMPLIED));
  131. }
  132. public static int name2type(String nm) {
  133. Integer i = (Integer)attributeTypes.get(nm);
  134. return (i == null) ? CDATA : i.intValue();
  135. }
  136. public static String type2name(int tp) {
  137. return (String)attributeTypes.get(new Integer(tp));
  138. }
  139. }