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