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.ext;
  27 
  28 import org.xml.sax.SAXException;
  29 
  30 
  31 /**
  32  * SAX2 extension handler for DTD declaration events.
  33  *
  34  * <p>This is an optional extension handler for SAX2 to provide more
  35  * complete information about DTD declarations in an XML document.
  36  * XML readers are not required to recognize this handler, and it
  37  * is not part of core-only SAX2 distributions.</p>
  38  *
  39  * <p>Note that data-related DTD declarations (unparsed entities and
  40  * notations) are already reported through the {@link
  41  * org.xml.sax.DTDHandler DTDHandler} interface.</p>
  42  *
  43  * <p>If you are using the declaration handler together with a lexical
  44  * handler, all of the events will occur between the
  45  * {@link org.xml.sax.ext.LexicalHandler#startDTD startDTD} and the
  46  * {@link org.xml.sax.ext.LexicalHandler#endDTD endDTD} events.</p>
  47  *
  48  * <p>To set the DeclHandler for an XML reader, use the
  49  * {@link org.xml.sax.XMLReader#setProperty setProperty} method
  50  * with the property name
  51  * <code>http://xml.org/sax/properties/declaration-handler</code>
  52  * and an object implementing this interface (or null) as the value.
  53  * If the reader does not report declaration events, it will throw a
  54  * {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException}
  55  * when you attempt to register the handler.</p>
  56  *
  57  * @since 1.4, SAX 2.0 (extensions 1.0)
  58  * @author David Megginson
  59  */
  60 public interface DeclHandler
  61 {
  62 
  63     /**
  64      * Report an element type declaration.
  65      *
  66      * <p>The content model will consist of the string "EMPTY", the
  67      * string "ANY", or a parenthesised group, optionally followed
  68      * by an occurrence indicator.  The model will be normalized so
  69      * that all parameter entities are fully resolved and all whitespace
  70      * is removed,and will include the enclosing parentheses.  Other
  71      * normalization (such as removing redundant parentheses or
  72      * simplifying occurrence indicators) is at the discretion of the
  73      * parser.</p>
  74      *
  75      * @param name The element type name.
  76      * @param model The content model as a normalized string.
  77      * @exception SAXException The application may raise an exception.
  78      */
  79     public abstract void elementDecl (String name, String model)
  80         throws SAXException;
  81 
  82 
  83     /**
  84      * Report an attribute type declaration.
  85      *
  86      * <p>Only the effective (first) declaration for an attribute will
  87      * be reported.  The type will be one of the strings "CDATA",
  88      * "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY",
  89      * "ENTITIES", a parenthesized token group with
  90      * the separator "|" and all whitespace removed, or the word
  91      * "NOTATION" followed by a space followed by a parenthesized
  92      * token group with all whitespace removed.</p>
  93      *
  94      * <p>The value will be the value as reported to applications,
  95      * appropriately normalized and with entity and character
  96      * references expanded.  </p>
  97      *
  98      * @param eName The name of the associated element.
  99      * @param aName The name of the attribute.
 100      * @param type A string representing the attribute type.
 101      * @param mode A string representing the attribute defaulting mode
 102      *        ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
 103      *        none of these applies.
 104      * @param value A string representing the attribute's default value,
 105      *        or null if there is none.
 106      * @exception SAXException The application may raise an exception.
 107      */
 108     public abstract void attributeDecl (String eName,
 109                                         String aName,
 110                                         String type,
 111                                         String mode,
 112                                         String value)
 113         throws SAXException;
 114 
 115 
 116     /**
 117      * Report an internal entity declaration.
 118      *
 119      * <p>Only the effective (first) declaration for each entity
 120      * will be reported.  All parameter entities in the value
 121      * will be expanded, but general entities will not.</p>
 122      *
 123      * @param name The name of the entity.  If it is a parameter
 124      *        entity, the name will begin with '%'.
 125      * @param value The replacement text of the entity.
 126      * @exception SAXException The application may raise an exception.
 127      * @see #externalEntityDecl
 128      * @see org.xml.sax.DTDHandler#unparsedEntityDecl
 129      */
 130     public abstract void internalEntityDecl (String name, String value)
 131         throws SAXException;
 132 
 133 
 134     /**
 135      * Report a parsed external entity declaration.
 136      *
 137      * <p>Only the effective (first) declaration for each entity
 138      * will be reported.</p>
 139      *
 140      * <p>If the system identifier is a URL, the parser must resolve it
 141      * fully before passing it to the application.</p>
 142      *
 143      * @param name The name of the entity.  If it is a parameter
 144      *        entity, the name will begin with '%'.
 145      * @param publicId The entity's public identifier, or null if none
 146      *        was given.
 147      * @param systemId The entity's system identifier.
 148      * @exception SAXException The application may raise an exception.
 149      * @see #internalEntityDecl
 150      * @see org.xml.sax.DTDHandler#unparsedEntityDecl
 151      */
 152     public abstract void externalEntityDecl (String name, String publicId,
 153                                              String systemId)
 154         throws SAXException;
 155 
 156 }
 157 
 158 // end of DeclHandler.java