Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/AttributeList.java
48534 views
/*1* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425// SAX Attribute List Interface.26// http://www.saxproject.org27// No warranty; no copyright -- use this as you will.28// $Id: AttributeList.java,v 1.3 2004/11/03 22:44:51 jsuttor Exp $2930package org.xml.sax;3132/**33* Interface for an element's attribute specifications.34*35* <blockquote>36* <em>This module, both source code and documentation, is in the37* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>38* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>39* for further information.40* </blockquote>41*42* <p>This is the original SAX1 interface for reporting an element's43* attributes. Unlike the new {@link org.xml.sax.Attributes Attributes}44* interface, it does not support Namespace-related information.</p>45*46* <p>When an attribute list is supplied as part of a47* {@link org.xml.sax.DocumentHandler#startElement startElement}48* event, the list will return valid results only during the49* scope of the event; once the event handler returns control50* to the parser, the attribute list is invalid. To save a51* persistent copy of the attribute list, use the SAX152* {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl}53* helper class.</p>54*55* <p>An attribute list includes only attributes that have been56* specified or defaulted: #IMPLIED attributes will not be included.</p>57*58* <p>There are two ways for the SAX application to obtain information59* from the AttributeList. First, it can iterate through the entire60* list:</p>61*62* <pre>63* public void startElement (String name, AttributeList atts) {64* for (int i = 0; i < atts.getLength(); i++) {65* String name = atts.getName(i);66* String type = atts.getType(i);67* String value = atts.getValue(i);68* [...]69* }70* }71* </pre>72*73* <p>(Note that the result of getLength() will be zero if there74* are no attributes.)75*76* <p>As an alternative, the application can request the value or77* type of specific attributes:</p>78*79* <pre>80* public void startElement (String name, AttributeList atts) {81* String identifier = atts.getValue("id");82* String label = atts.getValue("label");83* [...]84* }85* </pre>86*87* @deprecated This interface has been replaced by the SAX288* {@link org.xml.sax.Attributes Attributes}89* interface, which includes Namespace support.90* @since SAX 1.091* @author David Megginson92* @see org.xml.sax.DocumentHandler#startElement startElement93* @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl94*/95public interface AttributeList {969798////////////////////////////////////////////////////////////////////99// Iteration methods.100////////////////////////////////////////////////////////////////////101102103/**104* Return the number of attributes in this list.105*106* <p>The SAX parser may provide attributes in any107* arbitrary order, regardless of the order in which they were108* declared or specified. The number of attributes may be109* zero.</p>110*111* @return The number of attributes in the list.112*/113public abstract int getLength ();114115116/**117* Return the name of an attribute in this list (by position).118*119* <p>The names must be unique: the SAX parser shall not include the120* same attribute twice. Attributes without values (those declared121* #IMPLIED without a value specified in the start tag) will be122* omitted from the list.</p>123*124* <p>If the attribute name has a namespace prefix, the prefix125* will still be attached.</p>126*127* @param i The index of the attribute in the list (starting at 0).128* @return The name of the indexed attribute, or null129* if the index is out of range.130* @see #getLength131*/132public abstract String getName (int i);133134135/**136* Return the type of an attribute in the list (by position).137*138* <p>The attribute type is one of the strings "CDATA", "ID",139* "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",140* or "NOTATION" (always in upper case).</p>141*142* <p>If the parser has not read a declaration for the attribute,143* or if the parser does not report attribute types, then it must144* return the value "CDATA" as stated in the XML 1.0 Recommentation145* (clause 3.3.3, "Attribute-Value Normalization").</p>146*147* <p>For an enumerated attribute that is not a notation, the148* parser will report the type as "NMTOKEN".</p>149*150* @param i The index of the attribute in the list (starting at 0).151* @return The attribute type as a string, or152* null if the index is out of range.153* @see #getLength154* @see #getType(java.lang.String)155*/156public abstract String getType (int i);157158159/**160* Return the value of an attribute in the list (by position).161*162* <p>If the attribute value is a list of tokens (IDREFS,163* ENTITIES, or NMTOKENS), the tokens will be concatenated164* into a single string separated by whitespace.</p>165*166* @param i The index of the attribute in the list (starting at 0).167* @return The attribute value as a string, or168* null if the index is out of range.169* @see #getLength170* @see #getValue(java.lang.String)171*/172public abstract String getValue (int i);173174175176////////////////////////////////////////////////////////////////////177// Lookup methods.178////////////////////////////////////////////////////////////////////179180181/**182* Return the type of an attribute in the list (by name).183*184* <p>The return value is the same as the return value for185* getType(int).</p>186*187* <p>If the attribute name has a namespace prefix in the document,188* the application must include the prefix here.</p>189*190* @param name The name of the attribute.191* @return The attribute type as a string, or null if no192* such attribute exists.193* @see #getType(int)194*/195public abstract String getType (String name);196197198/**199* Return the value of an attribute in the list (by name).200*201* <p>The return value is the same as the return value for202* getValue(int).</p>203*204* <p>If the attribute name has a namespace prefix in the document,205* the application must include the prefix here.</p>206*207* @param name the name of the attribute to return208* @return The attribute value as a string, or null if209* no such attribute exists.210* @see #getValue(int)211*/212public abstract String getValue (String name);213214}215216// end of AttributeList.java217218219