Path: blob/master/src/java.xml/share/classes/org/xml/sax/Attributes.java
40948 views
/*1* Copyright (c) 2000, 2019, 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*/2425package org.xml.sax;262728/**29* Interface for a list of XML attributes.30*31* <p>This interface allows access to a list of attributes in32* three different ways:</p>33*34* <ol>35* <li>by attribute index;</li>36* <li>by Namespace-qualified name; or</li>37* <li>by qualified (prefixed) name.</li>38* </ol>39*40* <p>The list will not contain attributes that were declared41* #IMPLIED but not specified in the start tag. It will also not42* contain attributes used as Namespace declarations (xmlns*) unless43* the <code>http://xml.org/sax/features/namespace-prefixes</code>44* feature is set to <var>true</var> (it is <var>false</var> by45* default).46* Because SAX2 conforms to the original "Namespaces in XML"47* recommendation, it normally does not48* give namespace declaration attributes a namespace URI.49* </p>50*51* <p>Some SAX2 parsers may support using an optional feature flag52* (<code>http://xml.org/sax/features/xmlns-uris</code>) to request53* that those attributes be given URIs, conforming to a later54* backwards-incompatible revision of that recommendation. (The55* attribute's "local name" will be the prefix, or "xmlns" when56* defining a default element namespace.) For portability, handler57* code should always resolve that conflict, rather than requiring58* parsers that can change the setting of that feature flag. </p>59*60* <p>If the namespace-prefixes feature (see above) is61* <var>false</var>, access by qualified name may not be available; if62* the <code>http://xml.org/sax/features/namespaces</code> feature is63* <var>false</var>, access by Namespace-qualified names may not be64* available.</p>65*66* <p>This interface replaces the now-deprecated SAX1 {@link67* org.xml.sax.AttributeList AttributeList} interface, which does not68* contain Namespace support. In addition to Namespace support, it69* adds the <var>getIndex</var> methods (below).</p>70*71* <p>The order of attributes in the list is unspecified, and will72* vary from implementation to implementation.</p>73*74* @since 1.4, SAX 2.075* @author David Megginson76* @see org.xml.sax.helpers.AttributesImpl77* @see org.xml.sax.ext.DeclHandler#attributeDecl78*/79public interface Attributes80{818283////////////////////////////////////////////////////////////////////84// Indexed access.85////////////////////////////////////////////////////////////////////868788/**89* Return the number of attributes in the list.90*91* <p>Once you know the number of attributes, you can iterate92* through the list.</p>93*94* @return The number of attributes in the list.95* @see #getURI(int)96* @see #getLocalName(int)97* @see #getQName(int)98* @see #getType(int)99* @see #getValue(int)100*/101public abstract int getLength ();102103104/**105* Look up an attribute's Namespace URI by index.106*107* @param index The attribute index (zero-based).108* @return The Namespace URI, or the empty string if none109* is available, or null if the index is out of110* range.111* @see #getLength112*/113public abstract String getURI (int index);114115116/**117* Look up an attribute's local name by index.118*119* @param index The attribute index (zero-based).120* @return The local name, or the empty string if Namespace121* processing is not being performed, or null122* if the index is out of range.123* @see #getLength124*/125public abstract String getLocalName (int index);126127128/**129* Look up an attribute's XML qualified (prefixed) name by index.130*131* @param index The attribute index (zero-based).132* @return The XML qualified name, or the empty string133* if none is available, or null if the index134* is out of range.135* @see #getLength136*/137public abstract String getQName (int index);138139140/**141* Look up an attribute's type by index.142*143* <p>The attribute type is one of the strings "CDATA", "ID",144* "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",145* or "NOTATION" (always in upper case).</p>146*147* <p>If the parser has not read a declaration for the attribute,148* or if the parser does not report attribute types, then it must149* return the value "CDATA" as stated in the XML 1.0 Recommendation150* (clause 3.3.3, "Attribute-Value Normalization").</p>151*152* <p>For an enumerated attribute that is not a notation, the153* parser will report the type as "NMTOKEN".</p>154*155* @param index The attribute index (zero-based).156* @return The attribute's type as a string, or null if the157* index is out of range.158* @see #getLength159*/160public abstract String getType (int index);161162163/**164* Look up an attribute's value by index.165*166* <p>If the attribute value is a list of tokens (IDREFS,167* ENTITIES, or NMTOKENS), the tokens will be concatenated168* into a single string with each token separated by a169* single space.</p>170*171* @param index The attribute index (zero-based).172* @return The attribute's value as a string, or null if the173* index is out of range.174* @see #getLength175*/176public abstract String getValue (int index);177178179180////////////////////////////////////////////////////////////////////181// Name-based query.182////////////////////////////////////////////////////////////////////183184185/**186* Look up the index of an attribute by Namespace name.187*188* @param uri The Namespace URI, or the empty string if189* the name has no Namespace URI.190* @param localName The attribute's local name.191* @return The index of the attribute, or -1 if it does not192* appear in the list.193*/194public int getIndex (String uri, String localName);195196197/**198* Look up the index of an attribute by XML qualified (prefixed) name.199*200* @param qName The qualified (prefixed) name.201* @return The index of the attribute, or -1 if it does not202* appear in the list.203*/204public int getIndex (String qName);205206207/**208* Look up an attribute's type by Namespace name.209*210* <p>See {@link #getType(int) getType(int)} for a description211* of the possible types.</p>212*213* @param uri The Namespace URI, or the empty String if the214* name has no Namespace URI.215* @param localName The local name of the attribute.216* @return The attribute type as a string, or null if the217* attribute is not in the list or if Namespace218* processing is not being performed.219*/220public abstract String getType (String uri, String localName);221222223/**224* Look up an attribute's type by XML qualified (prefixed) name.225*226* <p>See {@link #getType(int) getType(int)} for a description227* of the possible types.</p>228*229* @param qName The XML qualified name.230* @return The attribute type as a string, or null if the231* attribute is not in the list or if qualified names232* are not available.233*/234public abstract String getType (String qName);235236237/**238* Look up an attribute's value by Namespace name.239*240* <p>See {@link #getValue(int) getValue(int)} for a description241* of the possible values.</p>242*243* @param uri The Namespace URI, or the empty String if the244* name has no Namespace URI.245* @param localName The local name of the attribute.246* @return The attribute value as a string, or null if the247* attribute is not in the list.248*/249public abstract String getValue (String uri, String localName);250251252/**253* Look up an attribute's value by XML qualified (prefixed) name.254*255* <p>See {@link #getValue(int) getValue(int)} for a description256* of the possible values.</p>257*258* @param qName The XML qualified name.259* @return The attribute value as a string, or null if the260* attribute is not in the list or if qualified names261* are not available.262*/263public abstract String getValue (String qName);264265}266267// end of Attributes.java268269270