Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/ext/LexicalHandler.java
48576 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// LexicalHandler.java - optional handler for lexical parse events.26// http://www.saxproject.org27// Public Domain: no warranty.28// $Id: LexicalHandler.java,v 1.2 2004/11/03 22:49:08 jsuttor Exp $2930package org.xml.sax.ext;3132import org.xml.sax.SAXException;3334/**35* SAX2 extension handler for lexical events.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 is an optional extension handler for SAX2 to provide45* lexical information about an XML document, such as comments46* and CDATA section boundaries.47* XML readers are not required to recognize this handler, and it48* is not part of core-only SAX2 distributions.</p>49*50* <p>The events in the lexical handler apply to the entire document,51* not just to the document element, and all lexical handler events52* must appear between the content handler's startDocument and53* endDocument events.</p>54*55* <p>To set the LexicalHandler for an XML reader, use the56* {@link org.xml.sax.XMLReader#setProperty setProperty} method57* with the property name58* <code>http://xml.org/sax/properties/lexical-handler</code>59* and an object implementing this interface (or null) as the value.60* If the reader does not report lexical events, it will throw a61* {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException}62* when you attempt to register the handler.</p>63*64* @since SAX 2.0 (extensions 1.0)65* @author David Megginson66*/67public interface LexicalHandler68{6970/**71* Report the start of DTD declarations, if any.72*73* <p>This method is intended to report the beginning of the74* DOCTYPE declaration; if the document has no DOCTYPE declaration,75* this method will not be invoked.</p>76*77* <p>All declarations reported through78* {@link org.xml.sax.DTDHandler DTDHandler} or79* {@link org.xml.sax.ext.DeclHandler DeclHandler} events must appear80* between the startDTD and {@link #endDTD endDTD} events.81* Declarations are assumed to belong to the internal DTD subset82* unless they appear between {@link #startEntity startEntity}83* and {@link #endEntity endEntity} events. Comments and84* processing instructions from the DTD should also be reported85* between the startDTD and endDTD events, in their original86* order of (logical) occurrence; they are not required to87* appear in their correct locations relative to DTDHandler88* or DeclHandler events, however.</p>89*90* <p>Note that the start/endDTD events will appear within91* the start/endDocument events from ContentHandler and92* before the first93* {@link org.xml.sax.ContentHandler#startElement startElement}94* event.</p>95*96* @param name The document type name.97* @param publicId The declared public identifier for the98* external DTD subset, or null if none was declared.99* @param systemId The declared system identifier for the100* external DTD subset, or null if none was declared.101* (Note that this is not resolved against the document102* base URI.)103* @exception SAXException The application may raise an104* exception.105* @see #endDTD106* @see #startEntity107*/108public abstract void startDTD (String name, String publicId,109String systemId)110throws SAXException;111112113/**114* Report the end of DTD declarations.115*116* <p>This method is intended to report the end of the117* DOCTYPE declaration; if the document has no DOCTYPE declaration,118* this method will not be invoked.</p>119*120* @exception SAXException The application may raise an exception.121* @see #startDTD122*/123public abstract void endDTD ()124throws SAXException;125126127/**128* Report the beginning of some internal and external XML entities.129*130* <p>The reporting of parameter entities (including131* the external DTD subset) is optional, and SAX2 drivers that132* report LexicalHandler events may not implement it; you can use the133* <code134* >http://xml.org/sax/features/lexical-handler/parameter-entities</code>135* feature to query or control the reporting of parameter entities.</p>136*137* <p>General entities are reported with their regular names,138* parameter entities have '%' prepended to their names, and139* the external DTD subset has the pseudo-entity name "[dtd]".</p>140*141* <p>When a SAX2 driver is providing these events, all other142* events must be properly nested within start/end entity143* events. There is no additional requirement that events from144* {@link org.xml.sax.ext.DeclHandler DeclHandler} or145* {@link org.xml.sax.DTDHandler DTDHandler} be properly ordered.</p>146*147* <p>Note that skipped entities will be reported through the148* {@link org.xml.sax.ContentHandler#skippedEntity skippedEntity}149* event, which is part of the ContentHandler interface.</p>150*151* <p>Because of the streaming event model that SAX uses, some152* entity boundaries cannot be reported under any153* circumstances:</p>154*155* <ul>156* <li>general entities within attribute values</li>157* <li>parameter entities within declarations</li>158* </ul>159*160* <p>These will be silently expanded, with no indication of where161* the original entity boundaries were.</p>162*163* <p>Note also that the boundaries of character references (which164* are not really entities anyway) are not reported.</p>165*166* <p>All start/endEntity events must be properly nested.167*168* @param name The name of the entity. If it is a parameter169* entity, the name will begin with '%', and if it is the170* external DTD subset, it will be "[dtd]".171* @exception SAXException The application may raise an exception.172* @see #endEntity173* @see org.xml.sax.ext.DeclHandler#internalEntityDecl174* @see org.xml.sax.ext.DeclHandler#externalEntityDecl175*/176public abstract void startEntity (String name)177throws SAXException;178179180/**181* Report the end of an entity.182*183* @param name The name of the entity that is ending.184* @exception SAXException The application may raise an exception.185* @see #startEntity186*/187public abstract void endEntity (String name)188throws SAXException;189190191/**192* Report the start of a CDATA section.193*194* <p>The contents of the CDATA section will be reported through195* the regular {@link org.xml.sax.ContentHandler#characters196* characters} event; this event is intended only to report197* the boundary.</p>198*199* @exception SAXException The application may raise an exception.200* @see #endCDATA201*/202public abstract void startCDATA ()203throws SAXException;204205206/**207* Report the end of a CDATA section.208*209* @exception SAXException The application may raise an exception.210* @see #startCDATA211*/212public abstract void endCDATA ()213throws SAXException;214215216/**217* Report an XML comment anywhere in the document.218*219* <p>This callback will be used for comments inside or outside the220* document element, including comments in the external DTD221* subset (if read). Comments in the DTD must be properly222* nested inside start/endDTD and start/endEntity events (if223* used).</p>224*225* @param ch An array holding the characters in the comment.226* @param start The starting position in the array.227* @param length The number of characters to use from the array.228* @exception SAXException The application may raise an exception.229*/230public abstract void comment (char ch[], int start, int length)231throws SAXException;232233}234235// end of LexicalHandler.java236237238