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