1. // Attributes.java - attribute list with Namespace support
  2. // http://www.saxproject.org
  3. // Written by David Megginson
  4. // NO WARRANTY! This class is in the public domain.
  5. // $Id: Attributes.java,v 1.1.24.1 2004/05/01 08:34:39 jsuttor Exp $
  6. package org.xml.sax;
  7. /**
  8. * Interface for a list of XML attributes.
  9. *
  10. * <blockquote>
  11. * <em>This module, both source code and documentation, is in the
  12. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  13. * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  14. * for further information.
  15. * </blockquote>
  16. *
  17. * <p>This interface allows access to a list of attributes in
  18. * three different ways:</p>
  19. *
  20. * <ol>
  21. * <li>by attribute index;</li>
  22. * <li>by Namespace-qualified name; or</li>
  23. * <li>by qualified (prefixed) name.</li>
  24. * </ol>
  25. *
  26. * <p>The list will not contain attributes that were declared
  27. * #IMPLIED but not specified in the start tag. It will also not
  28. * contain attributes used as Namespace declarations (xmlns*) unless
  29. * the <code>http://xml.org/sax/features/namespace-prefixes</code>
  30. * feature is set to <var>true</var> (it is <var>false</var> by
  31. * default).
  32. * Because SAX2 conforms to the original "Namespaces in XML"
  33. * recommendation, it normally does not
  34. * give namespace declaration attributes a namespace URI.
  35. * </p>
  36. *
  37. * <p>Some SAX2 parsers may support using an optional feature flag
  38. * (<code>http://xml.org/sax/features/xmlns-uris</code>) to request
  39. * that those attributes be given URIs, conforming to a later
  40. * backwards-incompatible revision of that recommendation. (The
  41. * attribute's "local name" will be the prefix, or "xmlns" when
  42. * defining a default element namespace.) For portability, handler
  43. * code should always resolve that conflict, rather than requiring
  44. * parsers that can change the setting of that feature flag. </p>
  45. *
  46. * <p>If the namespace-prefixes feature (see above) is
  47. * <var>false</var>, access by qualified name may not be available; if
  48. * the <code>http://xml.org/sax/features/namespaces</code> feature is
  49. * <var>false</var>, access by Namespace-qualified names may not be
  50. * available.</p>
  51. *
  52. * <p>This interface replaces the now-deprecated SAX1 {@link
  53. * org.xml.sax.AttributeList AttributeList} interface, which does not
  54. * contain Namespace support. In addition to Namespace support, it
  55. * adds the <var>getIndex</var> methods (below).</p>
  56. *
  57. * <p>The order of attributes in the list is unspecified, and will
  58. * vary from implementation to implementation.</p>
  59. *
  60. * @since SAX 2.0
  61. * @author David Megginson
  62. * @version 2.0.1 (sax2r2)
  63. * @see org.xml.sax.helpers.AttributesImpl
  64. * @see org.xml.sax.ext.DeclHandler#attributeDecl
  65. */
  66. public interface Attributes
  67. {
  68. ////////////////////////////////////////////////////////////////////
  69. // Indexed access.
  70. ////////////////////////////////////////////////////////////////////
  71. /**
  72. * Return the number of attributes in the list.
  73. *
  74. * <p>Once you know the number of attributes, you can iterate
  75. * through the list.</p>
  76. *
  77. * @return The number of attributes in the list.
  78. * @see #getURI(int)
  79. * @see #getLocalName(int)
  80. * @see #getQName(int)
  81. * @see #getType(int)
  82. * @see #getValue(int)
  83. */
  84. public abstract int getLength ();
  85. /**
  86. * Look up an attribute's Namespace URI by index.
  87. *
  88. * @param index The attribute index (zero-based).
  89. * @return The Namespace URI, or the empty string if none
  90. * is available, or null if the index is out of
  91. * range.
  92. * @see #getLength
  93. */
  94. public abstract String getURI (int index);
  95. /**
  96. * Look up an attribute's local name by index.
  97. *
  98. * @param index The attribute index (zero-based).
  99. * @return The local name, or the empty string if Namespace
  100. * processing is not being performed, or null
  101. * if the index is out of range.
  102. * @see #getLength
  103. */
  104. public abstract String getLocalName (int index);
  105. /**
  106. * Look up an attribute's XML qualified (prefixed) name by index.
  107. *
  108. * @param index The attribute index (zero-based).
  109. * @return The XML qualified name, or the empty string
  110. * if none is available, or null if the index
  111. * is out of range.
  112. * @see #getLength
  113. */
  114. public abstract String getQName (int index);
  115. /**
  116. * Look up an attribute's type by index.
  117. *
  118. * <p>The attribute type is one of the strings "CDATA", "ID",
  119. * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
  120. * or "NOTATION" (always in upper case).</p>
  121. *
  122. * <p>If the parser has not read a declaration for the attribute,
  123. * or if the parser does not report attribute types, then it must
  124. * return the value "CDATA" as stated in the XML 1.0 Recommendation
  125. * (clause 3.3.3, "Attribute-Value Normalization").</p>
  126. *
  127. * <p>For an enumerated attribute that is not a notation, the
  128. * parser will report the type as "NMTOKEN".</p>
  129. *
  130. * @param index The attribute index (zero-based).
  131. * @return The attribute's type as a string, or null if the
  132. * index is out of range.
  133. * @see #getLength
  134. */
  135. public abstract String getType (int index);
  136. /**
  137. * Look up an attribute's value by index.
  138. *
  139. * <p>If the attribute value is a list of tokens (IDREFS,
  140. * ENTITIES, or NMTOKENS), the tokens will be concatenated
  141. * into a single string with each token separated by a
  142. * single space.</p>
  143. *
  144. * @param index The attribute index (zero-based).
  145. * @return The attribute's value as a string, or null if the
  146. * index is out of range.
  147. * @see #getLength
  148. */
  149. public abstract String getValue (int index);
  150. ////////////////////////////////////////////////////////////////////
  151. // Name-based query.
  152. ////////////////////////////////////////////////////////////////////
  153. /**
  154. * Look up the index of an attribute by Namespace name.
  155. *
  156. * @param uri The Namespace URI, or the empty string if
  157. * the name has no Namespace URI.
  158. * @param localName The attribute's local name.
  159. * @return The index of the attribute, or -1 if it does not
  160. * appear in the list.
  161. */
  162. public int getIndex (String uri, String localName);
  163. /**
  164. * Look up the index of an attribute by XML qualified (prefixed) name.
  165. *
  166. * @param qName The qualified (prefixed) name.
  167. * @return The index of the attribute, or -1 if it does not
  168. * appear in the list.
  169. */
  170. public int getIndex (String qName);
  171. /**
  172. * Look up an attribute's type by Namespace name.
  173. *
  174. * <p>See {@link #getType(int) getType(int)} for a description
  175. * of the possible types.</p>
  176. *
  177. * @param uri The Namespace URI, or the empty String if the
  178. * name has no Namespace URI.
  179. * @param localName The local name of the attribute.
  180. * @return The attribute type as a string, or null if the
  181. * attribute is not in the list or if Namespace
  182. * processing is not being performed.
  183. */
  184. public abstract String getType (String uri, String localName);
  185. /**
  186. * Look up an attribute's type by XML qualified (prefixed) name.
  187. *
  188. * <p>See {@link #getType(int) getType(int)} for a description
  189. * of the possible types.</p>
  190. *
  191. * @param qName The XML qualified name.
  192. * @return The attribute type as a string, or null if the
  193. * attribute is not in the list or if qualified names
  194. * are not available.
  195. */
  196. public abstract String getType (String qName);
  197. /**
  198. * Look up an attribute's value by Namespace name.
  199. *
  200. * <p>See {@link #getValue(int) getValue(int)} for a description
  201. * of the possible values.</p>
  202. *
  203. * @param uri The Namespace URI, or the empty String if the
  204. * name has no Namespace URI.
  205. * @param localName The local name of the attribute.
  206. * @return The attribute value as a string, or null if the
  207. * attribute is not in the list.
  208. */
  209. public abstract String getValue (String uri, String localName);
  210. /**
  211. * Look up an attribute's value by XML qualified (prefixed) name.
  212. *
  213. * <p>See {@link #getValue(int) getValue(int)} for a description
  214. * of the possible values.</p>
  215. *
  216. * @param qName The XML qualified name.
  217. * @return The attribute value as a string, or null if the
  218. * attribute is not in the list or if qualified names
  219. * are not available.
  220. */
  221. public abstract String getValue (String qName);
  222. }
  223. // end of Attributes.java