View Javadoc

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