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