1. // SAX Attribute List Interface.
  2. // http://www.saxproject.org
  3. // No warranty; no copyright -- use this as you will.
  4. // $Id: AttributeList.java,v 1.2.22.1 2004/05/01 08:34:38 jsuttor Exp $
  5. package org.xml.sax;
  6. /**
  7. * Interface for an element's attribute specifications.
  8. *
  9. * <blockquote>
  10. * <em>This module, both source code and documentation, is in the
  11. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  12. * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  13. * for further information.
  14. * </blockquote>
  15. *
  16. * <p>This is the original SAX1 interface for reporting an element's
  17. * attributes. Unlike the new {@link org.xml.sax.Attributes Attributes}
  18. * interface, it does not support Namespace-related information.</p>
  19. *
  20. * <p>When an attribute list is supplied as part of a
  21. * {@link org.xml.sax.DocumentHandler#startElement startElement}
  22. * event, the list will return valid results only during the
  23. * scope of the event; once the event handler returns control
  24. * to the parser, the attribute list is invalid. To save a
  25. * persistent copy of the attribute list, use the SAX1
  26. * {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
  27. * helper class.</p>
  28. *
  29. * <p>An attribute list includes only attributes that have been
  30. * specified or defaulted: #IMPLIED attributes will not be included.</p>
  31. *
  32. * <p>There are two ways for the SAX application to obtain information
  33. * from the AttributeList. First, it can iterate through the entire
  34. * list:</p>
  35. *
  36. * <pre>
  37. * public void startElement (String name, AttributeList atts) {
  38. * for (int i = 0; i < atts.getLength(); i++) {
  39. * String name = atts.getName(i);
  40. * String type = atts.getType(i);
  41. * String value = atts.getValue(i);
  42. * [...]
  43. * }
  44. * }
  45. * </pre>
  46. *
  47. * <p>(Note that the result of getLength() will be zero if there
  48. * are no attributes.)
  49. *
  50. * <p>As an alternative, the application can request the value or
  51. * type of specific attributes:</p>
  52. *
  53. * <pre>
  54. * public void startElement (String name, AttributeList atts) {
  55. * String identifier = atts.getValue("id");
  56. * String label = atts.getValue("label");
  57. * [...]
  58. * }
  59. * </pre>
  60. *
  61. * @deprecated This interface has been replaced by the SAX2
  62. * {@link org.xml.sax.Attributes Attributes}
  63. * interface, which includes Namespace support.
  64. * @since SAX 1.0
  65. * @author David Megginson
  66. * @version 2.0.1 (sax2r2)
  67. * @see org.xml.sax.DocumentHandler#startElement startElement
  68. * @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl
  69. */
  70. public interface AttributeList {
  71. ////////////////////////////////////////////////////////////////////
  72. // Iteration methods.
  73. ////////////////////////////////////////////////////////////////////
  74. /**
  75. * Return the number of attributes in this list.
  76. *
  77. * <p>The SAX parser may provide attributes in any
  78. * arbitrary order, regardless of the order in which they were
  79. * declared or specified. The number of attributes may be
  80. * zero.</p>
  81. *
  82. * @return The number of attributes in the list.
  83. */
  84. public abstract int getLength ();
  85. /**
  86. * Return the name of an attribute in this list (by position).
  87. *
  88. * <p>The names must be unique: the SAX parser shall not include the
  89. * same attribute twice. Attributes without values (those declared
  90. * #IMPLIED without a value specified in the start tag) will be
  91. * omitted from the list.</p>
  92. *
  93. * <p>If the attribute name has a namespace prefix, the prefix
  94. * will still be attached.</p>
  95. *
  96. * @param i The index of the attribute in the list (starting at 0).
  97. * @return The name of the indexed attribute, or null
  98. * if the index is out of range.
  99. * @see #getLength
  100. */
  101. public abstract String getName (int i);
  102. /**
  103. * Return the type of an attribute in the list (by position).
  104. *
  105. * <p>The attribute type is one of the strings "CDATA", "ID",
  106. * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
  107. * or "NOTATION" (always in upper case).</p>
  108. *
  109. * <p>If the parser has not read a declaration for the attribute,
  110. * or if the parser does not report attribute types, then it must
  111. * return the value "CDATA" as stated in the XML 1.0 Recommentation
  112. * (clause 3.3.3, "Attribute-Value Normalization").</p>
  113. *
  114. * <p>For an enumerated attribute that is not a notation, the
  115. * parser will report the type as "NMTOKEN".</p>
  116. *
  117. * @param i The index of the attribute in the list (starting at 0).
  118. * @return The attribute type as a string, or
  119. * null if the index is out of range.
  120. * @see #getLength
  121. * @see #getType(java.lang.String)
  122. */
  123. public abstract String getType (int i);
  124. /**
  125. * Return the value of an attribute in the list (by position).
  126. *
  127. * <p>If the attribute value is a list of tokens (IDREFS,
  128. * ENTITIES, or NMTOKENS), the tokens will be concatenated
  129. * into a single string separated by whitespace.</p>
  130. *
  131. * @param i The index of the attribute in the list (starting at 0).
  132. * @return The attribute value as a string, or
  133. * null if the index is out of range.
  134. * @see #getLength
  135. * @see #getValue(java.lang.String)
  136. */
  137. public abstract String getValue (int i);
  138. ////////////////////////////////////////////////////////////////////
  139. // Lookup methods.
  140. ////////////////////////////////////////////////////////////////////
  141. /**
  142. * Return the type of an attribute in the list (by name).
  143. *
  144. * <p>The return value is the same as the return value for
  145. * getType(int).</p>
  146. *
  147. * <p>If the attribute name has a namespace prefix in the document,
  148. * the application must include the prefix here.</p>
  149. *
  150. * @param name The name of the attribute.
  151. * @return The attribute type as a string, or null if no
  152. * such attribute exists.
  153. * @see #getType(int)
  154. */
  155. public abstract String getType (String name);
  156. /**
  157. * Return the value of an attribute in the list (by name).
  158. *
  159. * <p>The return value is the same as the return value for
  160. * getValue(int).</p>
  161. *
  162. * <p>If the attribute name has a namespace prefix in the document,
  163. * the application must include the prefix here.</p>
  164. *
  165. * @param name the name of the attribute to return
  166. * @return The attribute value as a string, or null if
  167. * no such attribute exists.
  168. * @see #getValue(int)
  169. */
  170. public abstract String getValue (String name);
  171. }
  172. // end of AttributeList.java