Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/Attributes.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// Attributes.java - attribute list with Namespace support26// http://www.saxproject.org27// Written by David Megginson28// NO WARRANTY! This class is in the public domain.29// $Id: Attributes.java,v 1.2 2004/11/03 22:44:51 jsuttor Exp $3031package org.xml.sax;323334/**35* Interface for a list of XML attributes.36*37* <blockquote>38* <em>This module, both source code and documentation, is in the39* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>40* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>41* for further information.42* </blockquote>43*44* <p>This interface allows access to a list of attributes in45* three different ways:</p>46*47* <ol>48* <li>by attribute index;</li>49* <li>by Namespace-qualified name; or</li>50* <li>by qualified (prefixed) name.</li>51* </ol>52*53* <p>The list will not contain attributes that were declared54* #IMPLIED but not specified in the start tag. It will also not55* contain attributes used as Namespace declarations (xmlns*) unless56* the <code>http://xml.org/sax/features/namespace-prefixes</code>57* feature is set to <var>true</var> (it is <var>false</var> by58* default).59* Because SAX2 conforms to the original "Namespaces in XML"60* recommendation, it normally does not61* give namespace declaration attributes a namespace URI.62* </p>63*64* <p>Some SAX2 parsers may support using an optional feature flag65* (<code>http://xml.org/sax/features/xmlns-uris</code>) to request66* that those attributes be given URIs, conforming to a later67* backwards-incompatible revision of that recommendation. (The68* attribute's "local name" will be the prefix, or "xmlns" when69* defining a default element namespace.) For portability, handler70* code should always resolve that conflict, rather than requiring71* parsers that can change the setting of that feature flag. </p>72*73* <p>If the namespace-prefixes feature (see above) is74* <var>false</var>, access by qualified name may not be available; if75* the <code>http://xml.org/sax/features/namespaces</code> feature is76* <var>false</var>, access by Namespace-qualified names may not be77* available.</p>78*79* <p>This interface replaces the now-deprecated SAX1 {@link80* org.xml.sax.AttributeList AttributeList} interface, which does not81* contain Namespace support. In addition to Namespace support, it82* adds the <var>getIndex</var> methods (below).</p>83*84* <p>The order of attributes in the list is unspecified, and will85* vary from implementation to implementation.</p>86*87* @since SAX 2.088* @author David Megginson89* @see org.xml.sax.helpers.AttributesImpl90* @see org.xml.sax.ext.DeclHandler#attributeDecl91*/92public interface Attributes93{949596////////////////////////////////////////////////////////////////////97// Indexed access.98////////////////////////////////////////////////////////////////////99100101/**102* Return the number of attributes in the list.103*104* <p>Once you know the number of attributes, you can iterate105* through the list.</p>106*107* @return The number of attributes in the list.108* @see #getURI(int)109* @see #getLocalName(int)110* @see #getQName(int)111* @see #getType(int)112* @see #getValue(int)113*/114public abstract int getLength ();115116117/**118* Look up an attribute's Namespace URI by index.119*120* @param index The attribute index (zero-based).121* @return The Namespace URI, or the empty string if none122* is available, or null if the index is out of123* range.124* @see #getLength125*/126public abstract String getURI (int index);127128129/**130* Look up an attribute's local name by index.131*132* @param index The attribute index (zero-based).133* @return The local name, or the empty string if Namespace134* processing is not being performed, or null135* if the index is out of range.136* @see #getLength137*/138public abstract String getLocalName (int index);139140141/**142* Look up an attribute's XML qualified (prefixed) name by index.143*144* @param index The attribute index (zero-based).145* @return The XML qualified name, or the empty string146* if none is available, or null if the index147* is out of range.148* @see #getLength149*/150public abstract String getQName (int index);151152153/**154* Look up an attribute's type by index.155*156* <p>The attribute type is one of the strings "CDATA", "ID",157* "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",158* or "NOTATION" (always in upper case).</p>159*160* <p>If the parser has not read a declaration for the attribute,161* or if the parser does not report attribute types, then it must162* return the value "CDATA" as stated in the XML 1.0 Recommendation163* (clause 3.3.3, "Attribute-Value Normalization").</p>164*165* <p>For an enumerated attribute that is not a notation, the166* parser will report the type as "NMTOKEN".</p>167*168* @param index The attribute index (zero-based).169* @return The attribute's type as a string, or null if the170* index is out of range.171* @see #getLength172*/173public abstract String getType (int index);174175176/**177* Look up an attribute's value by index.178*179* <p>If the attribute value is a list of tokens (IDREFS,180* ENTITIES, or NMTOKENS), the tokens will be concatenated181* into a single string with each token separated by a182* single space.</p>183*184* @param index The attribute index (zero-based).185* @return The attribute's value as a string, or null if the186* index is out of range.187* @see #getLength188*/189public abstract String getValue (int index);190191192193////////////////////////////////////////////////////////////////////194// Name-based query.195////////////////////////////////////////////////////////////////////196197198/**199* Look up the index of an attribute by Namespace name.200*201* @param uri The Namespace URI, or the empty string if202* the name has no Namespace URI.203* @param localName The attribute's local name.204* @return The index of the attribute, or -1 if it does not205* appear in the list.206*/207public int getIndex (String uri, String localName);208209210/**211* Look up the index of an attribute by XML qualified (prefixed) name.212*213* @param qName The qualified (prefixed) name.214* @return The index of the attribute, or -1 if it does not215* appear in the list.216*/217public int getIndex (String qName);218219220/**221* Look up an attribute's type by Namespace name.222*223* <p>See {@link #getType(int) getType(int)} for a description224* of the possible types.</p>225*226* @param uri The Namespace URI, or the empty String if the227* name has no Namespace URI.228* @param localName The local name of the attribute.229* @return The attribute type as a string, or null if the230* attribute is not in the list or if Namespace231* processing is not being performed.232*/233public abstract String getType (String uri, String localName);234235236/**237* Look up an attribute's type by XML qualified (prefixed) name.238*239* <p>See {@link #getType(int) getType(int)} for a description240* of the possible types.</p>241*242* @param qName The XML qualified name.243* @return The attribute type as a string, or null if the244* attribute is not in the list or if qualified names245* are not available.246*/247public abstract String getType (String qName);248249250/**251* Look up an attribute's value by Namespace name.252*253* <p>See {@link #getValue(int) getValue(int)} for a description254* of the possible values.</p>255*256* @param uri The Namespace URI, or the empty String if the257* name has no Namespace URI.258* @param localName The local name of the attribute.259* @return The attribute value as a string, or null if the260* attribute is not in the list.261*/262public abstract String getValue (String uri, String localName);263264265/**266* Look up an attribute's value by XML qualified (prefixed) name.267*268* <p>See {@link #getValue(int) getValue(int)} for a description269* of the possible values.</p>270*271* @param qName The XML qualified name.272* @return The attribute value as a string, or null if the273* attribute is not in the list or if qualified names274* are not available.275*/276public abstract String getValue (String qName);277278}279280// end of Attributes.java281282283