1 /*
   2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package org.xml.sax;
  27 
  28 /**
  29  * Interface for an element's attribute specifications.
  30  *
  31  * <p>This is the original SAX1 interface for reporting an element's
  32  * attributes.  Unlike the new {@link org.xml.sax.Attributes Attributes}
  33  * interface, it does not support Namespace-related information.
  34  *
  35  * <p>When an attribute list is supplied as part of a
  36  * {@link org.xml.sax.DocumentHandler#startElement startElement}
  37  * event, the list will return valid results only during the
  38  * scope of the event; once the event handler returns control
  39  * to the parser, the attribute list is invalid.  To save a
  40  * persistent copy of the attribute list, use the SAX1
  41  * {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
  42  * helper class.
  43  *
  44  * <p>An attribute list includes only attributes that have been
  45  * specified or defaulted: #IMPLIED attributes will not be included.
  46  *
  47  * <p>There are two ways for the SAX application to obtain information
  48  * from the AttributeList.  First, it can iterate through the entire
  49  * list:
  50  *
  51  * <pre>{@code
  52  * public void startElement (String name, AttributeList atts) {
  53  *   for (int i = 0; i < atts.getLength(); i++) {
  54  *     String name = atts.getName(i);
  55  *     String type = atts.getType(i);
  56  *     String value = atts.getValue(i);
  57  *     [...]
  58  *   }
  59  * }
  60  * }</pre>
  61  *
  62  * <p>(Note that the result of getLength() will be zero if there
  63  * are no attributes.)
  64  *
  65  * <p>As an alternative, the application can request the value or
  66  * type of specific attributes:
  67  *
  68  * <pre>
  69  * public void startElement (String name, AttributeList atts) {
  70  *   String identifier = atts.getValue("id");
  71  *   String label = atts.getValue("label");
  72  *   [...]
  73  * }
  74  * </pre>
  75  *
  76  * @deprecated This interface has been replaced by the SAX2
  77  *             {@link org.xml.sax.Attributes Attributes}
  78  *             interface, which includes Namespace support.
  79  * @since 1.4, SAX 1.0
  80  * @author David Megginson
  81  * @see org.xml.sax.DocumentHandler#startElement startElement
  82  * @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl
  83  */
  84 @Deprecated(since="1.5")
  85 public interface AttributeList {
  86 
  87 
  88     ////////////////////////////////////////////////////////////////////
  89     // Iteration methods.
  90     ////////////////////////////////////////////////////////////////////
  91 
  92 
  93     /**
  94      * Return the number of attributes in this list.
  95      *
  96      * <p>The SAX parser may provide attributes in any
  97      * arbitrary order, regardless of the order in which they were
  98      * declared or specified.  The number of attributes may be
  99      * zero.
 100      *
 101      * @return The number of attributes in the list.
 102      */
 103     public abstract int getLength ();
 104 
 105 
 106     /**
 107      * Return the name of an attribute in this list (by position).
 108      *
 109      * <p>The names must be unique: the SAX parser shall not include the
 110      * same attribute twice.  Attributes without values (those declared
 111      * #IMPLIED without a value specified in the start tag) will be
 112      * omitted from the list.
 113      *
 114      * <p>If the attribute name has a namespace prefix, the prefix
 115      * will still be attached.
 116      *
 117      * @param i The index of the attribute in the list (starting at 0).
 118      * @return The name of the indexed attribute, or null
 119      *         if the index is out of range.
 120      * @see #getLength
 121      */
 122     public abstract String getName (int i);
 123 
 124 
 125     /**
 126      * Return the type of an attribute in the list (by position).
 127      *
 128      * <p>The attribute type is one of the strings "CDATA", "ID",
 129      * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
 130      * or "NOTATION" (always in upper case).
 131      *
 132      * <p>If the parser has not read a declaration for the attribute,
 133      * or if the parser does not report attribute types, then it must
 134      * return the value "CDATA" as stated in the XML 1.0 Recommentation
 135      * (clause 3.3.3, "Attribute-Value Normalization").
 136      *
 137      * <p>For an enumerated attribute that is not a notation, the
 138      * parser will report the type as "NMTOKEN".
 139      *
 140      * @param i The index of the attribute in the list (starting at 0).
 141      * @return The attribute type as a string, or
 142      *         null if the index is out of range.
 143      * @see #getLength
 144      * @see #getType(java.lang.String)
 145      */
 146     public abstract String getType (int i);
 147 
 148 
 149     /**
 150      * Return the value of an attribute in the list (by position).
 151      *
 152      * <p>If the attribute value is a list of tokens (IDREFS,
 153      * ENTITIES, or NMTOKENS), the tokens will be concatenated
 154      * into a single string separated by whitespace.
 155      *
 156      * @param i The index of the attribute in the list (starting at 0).
 157      * @return The attribute value as a string, or
 158      *         null if the index is out of range.
 159      * @see #getLength
 160      * @see #getValue(java.lang.String)
 161      */
 162     public abstract String getValue (int i);
 163 
 164 
 165 
 166     ////////////////////////////////////////////////////////////////////
 167     // Lookup methods.
 168     ////////////////////////////////////////////////////////////////////
 169 
 170 
 171     /**
 172      * Return the type of an attribute in the list (by name).
 173      *
 174      * <p>The return value is the same as the return value for
 175      * getType(int).
 176      *
 177      * <p>If the attribute name has a namespace prefix in the document,
 178      * the application must include the prefix here.
 179      *
 180      * @param name The name of the attribute.
 181      * @return The attribute type as a string, or null if no
 182      *         such attribute exists.
 183      * @see #getType(int)
 184      */
 185     public abstract String getType (String name);
 186 
 187 
 188     /**
 189      * Return the value of an attribute in the list (by name).
 190      *
 191      * <p>The return value is the same as the return value for
 192      * getValue(int).
 193      *
 194      * <p>If the attribute name has a namespace prefix in the document,
 195      * the application must include the prefix here.
 196      *
 197      * @param name the name of the attribute to return
 198      * @return The attribute value as a string, or null if
 199      *         no such attribute exists.
 200      * @see #getValue(int)
 201      */
 202     public abstract String getValue (String name);
 203 
 204 }
 205 
 206 // end of AttributeList.java