1 /*
   2  * Copyright (c) 2004, 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.ext;
  27 
  28 import org.xml.sax.Attributes;
  29 
  30 
  31 /**
  32  * SAX2 extension to augment the per-attribute information
  33  * provided through {@link Attributes}.
  34  * If an implementation supports this extension, the attributes
  35  * provided in {@link org.xml.sax.ContentHandler#startElement
  36  * ContentHandler.startElement() } will implement this interface,
  37  * and the <em>http://xml.org/sax/features/use-attributes2</em>
  38  * feature flag will have the value <em>true</em>.
  39  *
  40  * <p> XMLReader implementations are not required to support this
  41  * information, and it is not part of core-only SAX2 distributions.</p>
  42  *
  43  * <p>Note that if an attribute was defaulted (<em>!isSpecified()</em>)
  44  * it will of necessity also have been declared (<em>isDeclared()</em>)
  45  * in the DTD.
  46  * Similarly if an attribute's type is anything except CDATA, then it
  47  * must have been declared.
  48  * </p>
  49  *
  50  * @since 1.5, SAX 2.0 (extensions 1.1 alpha)
  51  * @author David Brownell
  52  */
  53 public interface Attributes2 extends Attributes
  54 {
  55     /**
  56      * Returns false unless the attribute was declared in the DTD.
  57      * This helps distinguish two kinds of attributes that SAX reports
  58      * as CDATA:  ones that were declared (and hence are usually valid),
  59      * and those that were not (and which are never valid).
  60      *
  61      * @param index The attribute index (zero-based).
  62      * @return true if the attribute was declared in the DTD,
  63      *          false otherwise.
  64      * @exception java.lang.ArrayIndexOutOfBoundsException When the
  65      *            supplied index does not identify an attribute.
  66      */
  67     public boolean isDeclared (int index);
  68 
  69     /**
  70      * Returns false unless the attribute was declared in the DTD.
  71      * This helps distinguish two kinds of attributes that SAX reports
  72      * as CDATA:  ones that were declared (and hence are usually valid),
  73      * and those that were not (and which are never valid).
  74      *
  75      * @param qName The XML qualified (prefixed) name.
  76      * @return true if the attribute was declared in the DTD,
  77      *          false otherwise.
  78      * @exception java.lang.IllegalArgumentException When the
  79      *            supplied name does not identify an attribute.
  80      */
  81     public boolean isDeclared (String qName);
  82 
  83     /**
  84      * Returns false unless the attribute was declared in the DTD.
  85      * This helps distinguish two kinds of attributes that SAX reports
  86      * as CDATA:  ones that were declared (and hence are usually valid),
  87      * and those that were not (and which are never valid).
  88      *
  89      * <p>Remember that since DTDs do not "understand" namespaces, the
  90      * namespace URI associated with an attribute may not have come from
  91      * the DTD.  The declaration will have applied to the attribute's
  92      * <em>qName</em>.
  93      *
  94      * @param uri The Namespace URI, or the empty string if
  95      *        the name has no Namespace URI.
  96      * @param localName The attribute's local name.
  97      * @return true if the attribute was declared in the DTD,
  98      *          false otherwise.
  99      * @exception java.lang.IllegalArgumentException When the
 100      *            supplied names do not identify an attribute.
 101      */
 102     public boolean isDeclared (String uri, String localName);
 103 
 104     /**
 105      * Returns true unless the attribute value was provided
 106      * by DTD defaulting.
 107      *
 108      * @param index The attribute index (zero-based).
 109      * @return true if the value was found in the XML text,
 110      *          false if the value was provided by DTD defaulting.
 111      * @exception java.lang.ArrayIndexOutOfBoundsException When the
 112      *            supplied index does not identify an attribute.
 113      */
 114     public boolean isSpecified (int index);
 115 
 116     /**
 117      * Returns true unless the attribute value was provided
 118      * by DTD defaulting.
 119      *
 120      * <p>Remember that since DTDs do not "understand" namespaces, the
 121      * namespace URI associated with an attribute may not have come from
 122      * the DTD.  The declaration will have applied to the attribute's
 123      * <em>qName</em>.
 124      *
 125      * @param uri The Namespace URI, or the empty string if
 126      *        the name has no Namespace URI.
 127      * @param localName The attribute's local name.
 128      * @return true if the value was found in the XML text,
 129      *          false if the value was provided by DTD defaulting.
 130      * @exception java.lang.IllegalArgumentException When the
 131      *            supplied names do not identify an attribute.
 132      */
 133     public boolean isSpecified (String uri, String localName);
 134 
 135     /**
 136      * Returns true unless the attribute value was provided
 137      * by DTD defaulting.
 138      *
 139      * @param qName The XML qualified (prefixed) name.
 140      * @return true if the value was found in the XML text,
 141      *          false if the value was provided by DTD defaulting.
 142      * @exception java.lang.IllegalArgumentException When the
 143      *            supplied name does not identify an attribute.
 144      */
 145     public boolean isSpecified (String qName);
 146 }