001: // SAX Attribute List Interface.
002: // No warranty; no copyright -- use this as you will.
003: // $Id: AttributeList.java,v 1.1 2004/12/05 04:06:21 csilva Exp $
004:
005: package org.xml.sax;
006:
007: /**
008: * Interface for an element's attribute specifications.
009: *
010: * <p>The SAX parser implements this interface and passes an instance
011: * to the SAX application as the second argument of each startElement
012: * event.</p>
013: *
014: * <p>The instance provided will return valid results only during the
015: * scope of the startElement invocation (to save it for future
016: * use, the application must make a copy: the AttributeListImpl
017: * helper class provides a convenient constructor for doing so).</p>
018: *
019: * <p>An AttributeList includes only attributes that have been
020: * specified or defaulted: #IMPLIED attributes will not be included.</p>
021: *
022: * <p>There are two ways for the SAX application to obtain information
023: * from the AttributeList. First, it can iterate through the entire
024: * list:</p>
025: *
026: * <pre>
027: * public void startElement (String name, AttributeList atts) {
028: * for (int i = 0; i < atts.getLength(); i++) {
029: * String name = atts.getName(i);
030: * String type = atts.getType(i);
031: * String value = atts.getValue(i);
032: * [...]
033: * }
034: * }
035: * </pre>
036: *
037: * <p>(Note that the result of getLength() will be zero if there
038: * are no attributes.)
039: *
040: * <p>As an alternative, the application can request the value or
041: * type of specific attributes:</p>
042: *
043: * <pre>
044: * public void startElement (String name, AttributeList atts) {
045: * String identifier = atts.getValue("id");
046: * String label = atts.getValue("label");
047: * [...]
048: * }
049: * </pre>
050: *
051: * <p>The AttributeListImpl helper class provides a convenience
052: * implementation for use by parser or application writers.</p>
053: *
054: * @author David Megginson (ak117@freenet.carleton.ca)
055: * @version 1.0
056: * @see org.xml.sax.DocumentHandler#startElement
057: * @see org.xml.sax.helpers.AttributeListImpl
058: */
059: public interface AttributeList {
060:
061: /**
062: * Return the number of attributes in this list.
063: *
064: * <p>The SAX parser may provide attributes in any
065: * arbitrary order, regardless of the order in which they were
066: * declared or specified. The number of attributes may be
067: * zero.</p>
068: *
069: * @return The number of attributes in the list.
070: */
071: public abstract int getLength();
072:
073: /**
074: * Return the name of an attribute in this list (by position).
075: *
076: * <p>The names must be unique: the SAX parser shall not include the
077: * same attribute twice. Attributes without values (those declared
078: * #IMPLIED without a value specified in the start tag) will be
079: * omitted from the list.</p>
080: *
081: * <p>If the attribute name has a namespace prefix, the prefix
082: * will still be attached.</p>
083: *
084: * @param i The index of the attribute in the list (starting at 0).
085: * @return The name of the indexed attribute, or null
086: * if the index is out of range.
087: * @see #getLength
088: */
089: public abstract String getName(int i);
090:
091: /**
092: * Return the type of an attribute in the list (by position).
093: *
094: * <p>The attribute type is one of the strings "CDATA", "ID",
095: * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
096: * or "NOTATION" (always in upper case).</p>
097: *
098: * <p>If the parser has not read a declaration for the attribute,
099: * or if the parser does not report attribute types, then it must
100: * return the value "CDATA" as stated in the XML 1.0 Recommentation
101: * (clause 3.3.3, "Attribute-Value Normalization").</p>
102: *
103: * <p>For an enumerated attribute that is not a notation, the
104: * parser will report the type as "NMTOKEN".</p>
105: *
106: * @param i The index of the attribute in the list (starting at 0).
107: * @return The attribute type as a string, or
108: * null if the index is out of range.
109: * @see #getLength
110: * @see #getType(java.lang.String)
111: */
112: public abstract String getType(int i);
113:
114: /**
115: * Return the value of an attribute in the list (by position).
116: *
117: * <p>If the attribute value is a list of tokens (IDREFS,
118: * ENTITIES, or NMTOKENS), the tokens will be concatenated
119: * into a single string separated by whitespace.</p>
120: *
121: * @param i The index of the attribute in the list (starting at 0).
122: * @return The attribute value as a string, or
123: * null if the index is out of range.
124: * @see #getLength
125: * @see #getValue(java.lang.String)
126: */
127: public abstract String getValue(int i);
128:
129: /**
130: * Return the type of an attribute in the list (by name).
131: *
132: * <p>The return value is the same as the return value for
133: * getType(int).</p>
134: *
135: * <p>If the attribute name has a namespace prefix in the document,
136: * the application must include the prefix here.</p>
137: *
138: * @param name The name of the attribute.
139: * @return The attribute type as a string, or null if no
140: * such attribute exists.
141: * @see #getType(int)
142: */
143: public abstract String getType(String name);
144:
145: /**
146: * Return the value of an attribute in the list (by name).
147: *
148: * <p>The return value is the same as the return value for
149: * getValue(int).</p>
150: *
151: * <p>If the attribute name has a namespace prefix in the document,
152: * the application must include the prefix here.</p>
153: *
154: * @param i The index of the attribute in the list.
155: * @return The attribute value as a string, or null if
156: * no such attribute exists.
157: * @see #getValue(int)
158: */
159: public abstract String getValue(String name);
160:
161: }
|