001// SAX Attribute List Interface.
002// http://www.saxproject.org
003// No warranty; no copyright -- use this as you will.
004// $Id: AttributeList.java,v 1.1 2004/12/23 22:38:42 mark Exp $
005
006package org.xml.sax;
007
008/**
009 * Interface for an element's attribute specifications.
010 *
011 * <blockquote>
012 * <em>This module, both source code and documentation, is in the
013 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
014 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
015 * for further information.
016 * </blockquote>
017 *
018 * <p>This is the original SAX1 interface for reporting an element's
019 * attributes.  Unlike the new {@link org.xml.sax.Attributes Attributes}
020 * interface, it does not support Namespace-related information.</p>
021 *
022 * <p>When an attribute list is supplied as part of a
023 * {@link org.xml.sax.DocumentHandler#startElement startElement}
024 * event, the list will return valid results only during the
025 * scope of the event; once the event handler returns control
026 * to the parser, the attribute list is invalid.  To save a
027 * persistent copy of the attribute list, use the SAX1
028 * {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
029 * helper class.</p>
030 *
031 * <p>An attribute list includes only attributes that have been
032 * specified or defaulted: #IMPLIED attributes will not be included.</p>
033 *
034 * <p>There are two ways for the SAX application to obtain information
035 * from the AttributeList.  First, it can iterate through the entire
036 * list:</p>
037 *
038 * <pre>
039 * public void startElement (String name, AttributeList atts) {
040 *   for (int i = 0; i < atts.getLength(); i++) {
041 *     String name = atts.getName(i);
042 *     String type = atts.getType(i);
043 *     String value = atts.getValue(i);
044 *     [...]
045 *   }
046 * }
047 * </pre>
048 *
049 * <p>(Note that the result of getLength() will be zero if there
050 * are no attributes.)
051 *
052 * <p>As an alternative, the application can request the value or
053 * type of specific attributes:</p>
054 *
055 * <pre>
056 * public void startElement (String name, AttributeList atts) {
057 *   String identifier = atts.getValue("id");
058 *   String label = atts.getValue("label");
059 *   [...]
060 * }
061 * </pre>
062 *
063 * @deprecated This interface has been replaced by the SAX2
064 *             {@link org.xml.sax.Attributes Attributes}
065 *             interface, which includes Namespace support.
066 * @since SAX 1.0
067 * @author David Megginson
068 * @version 2.0.1 (sax2r2)
069 * @see org.xml.sax.DocumentHandler#startElement startElement
070 * @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl
071 */
072public interface AttributeList {
073
074
075    ////////////////////////////////////////////////////////////////////
076    // Iteration methods.
077    ////////////////////////////////////////////////////////////////////
078
079
080    /**
081     * Return the number of attributes in this list.
082     *
083     * <p>The SAX parser may provide attributes in any
084     * arbitrary order, regardless of the order in which they were
085     * declared or specified.  The number of attributes may be
086     * zero.</p>
087     *
088     * @return The number of attributes in the list.
089     */
090    public abstract int getLength ();
091
092
093    /**
094     * Return the name of an attribute in this list (by position).
095     *
096     * <p>The names must be unique: the SAX parser shall not include the
097     * same attribute twice.  Attributes without values (those declared
098     * #IMPLIED without a value specified in the start tag) will be
099     * omitted from the list.</p>
100     *
101     * <p>If the attribute name has a namespace prefix, the prefix
102     * will still be attached.</p>
103     *
104     * @param i The index of the attribute in the list (starting at 0).
105     * @return The name of the indexed attribute, or null
106     *         if the index is out of range.
107     * @see #getLength
108     */
109    public abstract String getName (int i);
110
111
112    /**
113     * Return the type of an attribute in the list (by position).
114     *
115     * <p>The attribute type is one of the strings "CDATA", "ID",
116     * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
117     * or "NOTATION" (always in upper case).</p>
118     *
119     * <p>If the parser has not read a declaration for the attribute,
120     * or if the parser does not report attribute types, then it must
121     * return the value "CDATA" as stated in the XML 1.0 Recommentation
122     * (clause 3.3.3, "Attribute-Value Normalization").</p>
123     *
124     * <p>For an enumerated attribute that is not a notation, the
125     * parser will report the type as "NMTOKEN".</p>
126     *
127     * @param i The index of the attribute in the list (starting at 0).
128     * @return The attribute type as a string, or
129     *         null if the index is out of range.
130     * @see #getLength
131     * @see #getType(java.lang.String)
132     */
133    public abstract String getType (int i);
134
135
136    /**
137     * Return the value of an attribute in the list (by position).
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 separated by whitespace.</p>
142     *
143     * @param i The index of the attribute in the list (starting at 0).
144     * @return The attribute value as a string, or
145     *         null if the index is out of range.
146     * @see #getLength
147     * @see #getValue(java.lang.String)
148     */
149    public abstract String getValue (int i);
150
151
152
153    ////////////////////////////////////////////////////////////////////
154    // Lookup methods.
155    ////////////////////////////////////////////////////////////////////
156
157
158    /**
159     * Return the type of an attribute in the list (by name).
160     *
161     * <p>The return value is the same as the return value for
162     * getType(int).</p>
163     *
164     * <p>If the attribute name has a namespace prefix in the document,
165     * the application must include the prefix here.</p>
166     *
167     * @param name The name of the attribute.
168     * @return The attribute type as a string, or null if no
169     *         such attribute exists.
170     * @see #getType(int)
171     */
172    public abstract String getType (String name);
173
174
175    /**
176     * Return the value of an attribute in the list (by name).
177     *
178     * <p>The return value is the same as the return value for
179     * getValue(int).</p>
180     *
181     * <p>If the attribute name has a namespace prefix in the document,
182     * the application must include the prefix here.</p>
183     *
184     * @param name the name of the attribute to return
185     * @return The attribute value as a string, or null if
186     *         no such attribute exists.
187     * @see #getValue(int)
188     */
189    public abstract String getValue (String name);
190
191}
192
193// end of AttributeList.java