Path: blob/master/src/java.xml/share/classes/org/xml/sax/DocumentHandler.java
40948 views
/*1* Copyright (c) 2000, 2020, 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;2627/**28* Receive notification of general document events.29*30* <p>This was the main event-handling interface for SAX1; in31* SAX2, it has been replaced by {@link org.xml.sax.ContentHandler32* ContentHandler}, which provides Namespace support and reporting33* of skipped entities. This interface is included in SAX2 only34* to support legacy SAX1 applications.</p>35*36* <p>The order of events in this interface is very important, and37* mirrors the order of information in the document itself. For38* example, all of an element's content (character data, processing39* instructions, and/or subelements) will appear, in order, between40* the startElement event and the corresponding endElement event.</p>41*42* <p>Application writers who do not want to implement the entire43* interface can derive a class from HandlerBase, which implements44* the default functionality; parser writers can instantiate45* HandlerBase to obtain a default handler. The application can find46* the location of any document event using the Locator interface47* supplied by the Parser through the setDocumentLocator method.</p>48*49* @deprecated This interface has been replaced by the SAX250* {@link org.xml.sax.ContentHandler ContentHandler}51* interface, which includes Namespace support.52* @since 1.4, SAX 1.053* @author David Megginson54* @see org.xml.sax.Parser#setDocumentHandler55* @see org.xml.sax.Locator56* @see org.xml.sax.HandlerBase57*/58@Deprecated(since="1.5")59public interface DocumentHandler {606162/**63* Receive an object for locating the origin of SAX document events.64*65* <p>SAX parsers are strongly encouraged (though not absolutely66* required) to supply a locator: if it does so, it must supply67* the locator to the application by invoking this method before68* invoking any of the other methods in the DocumentHandler69* interface.</p>70*71* <p>The locator allows the application to determine the end72* position of any document-related event, even if the parser is73* not reporting an error. Typically, the application will74* use this information for reporting its own errors (such as75* character content that does not match an application's76* business rules). The information returned by the locator77* is probably not sufficient for use with a search engine.</p>78*79* <p>Note that the locator will return correct information only80* during the invocation of the events in this interface. The81* application should not attempt to use it at any other time.</p>82*83* @param locator An object that can return the location of84* any SAX document event.85* @see org.xml.sax.Locator86*/87public abstract void setDocumentLocator (Locator locator);888990/**91* Receive notification of the beginning of a document.92*93* <p>The SAX parser will invoke this method only once, before any94* other methods in this interface or in DTDHandler (except for95* setDocumentLocator).</p>96*97* @throws org.xml.sax.SAXException Any SAX exception, possibly98* wrapping another exception.99*/100public abstract void startDocument ()101throws SAXException;102103104/**105* Receive notification of the end of a document.106*107* <p>The SAX parser will invoke this method only once, and it will108* be the last method invoked during the parse. The parser shall109* not invoke this method until it has either abandoned parsing110* (because of an unrecoverable error) or reached the end of111* input.</p>112*113* @throws org.xml.sax.SAXException Any SAX exception, possibly114* wrapping another exception.115*/116public abstract void endDocument ()117throws SAXException;118119120/**121* Receive notification of the beginning of an element.122*123* <p>The Parser will invoke this method at the beginning of every124* element in the XML document; there will be a corresponding125* endElement() event for every startElement() event (even when the126* element is empty). All of the element's content will be127* reported, in order, before the corresponding endElement()128* event.</p>129*130* <p>If the element name has a namespace prefix, the prefix will131* still be attached. Note that the attribute list provided will132* contain only attributes with explicit values (specified or133* defaulted): #IMPLIED attributes will be omitted.</p>134*135* @param name The element type name.136* @param atts The attributes attached to the element, if any.137* @throws org.xml.sax.SAXException Any SAX exception, possibly138* wrapping another exception.139* @see #endElement140* @see org.xml.sax.AttributeList141*/142public abstract void startElement (String name, AttributeList atts)143throws SAXException;144145146/**147* Receive notification of the end of an element.148*149* <p>The SAX parser will invoke this method at the end of every150* element in the XML document; there will be a corresponding151* startElement() event for every endElement() event (even when the152* element is empty).</p>153*154* <p>If the element name has a namespace prefix, the prefix will155* still be attached to the name.</p>156*157* @param name The element type name158* @throws org.xml.sax.SAXException Any SAX exception, possibly159* wrapping another exception.160*/161public abstract void endElement (String name)162throws SAXException;163164165/**166* Receive notification of character data.167*168* <p>The Parser will call this method to report each chunk of169* character data. SAX parsers may return all contiguous character170* data in a single chunk, or they may split it into several171* chunks; however, all of the characters in any single event172* must come from the same external entity, so that the Locator173* provides useful information.</p>174*175* <p>The application must not attempt to read from the array176* outside of the specified range.</p>177*178* <p>Note that some parsers will report whitespace using the179* ignorableWhitespace() method rather than this one (validating180* parsers must do so).</p>181*182* @param ch The characters from the XML document.183* @param start The start position in the array.184* @param length The number of characters to read from the array.185* @throws org.xml.sax.SAXException Any SAX exception, possibly186* wrapping another exception.187* @see #ignorableWhitespace188* @see org.xml.sax.Locator189*/190public abstract void characters (char ch[], int start, int length)191throws SAXException;192193194/**195* Receive notification of ignorable whitespace in element content.196*197* <p>Validating Parsers must use this method to report each chunk198* of ignorable whitespace (see the W3C XML 1.0 recommendation,199* section 2.10): non-validating parsers may also use this method200* if they are capable of parsing and using content models.</p>201*202* <p>SAX parsers may return all contiguous whitespace in a single203* chunk, or they may split it into several chunks; however, all of204* the characters in any single event must come from the same205* external entity, so that the Locator provides useful206* information.</p>207*208* <p>The application must not attempt to read from the array209* outside of the specified range.</p>210*211* @param ch The characters from the XML document.212* @param start The start position in the array.213* @param length The number of characters to read from the array.214* @throws org.xml.sax.SAXException Any SAX exception, possibly215* wrapping another exception.216* @see #characters217*/218public abstract void ignorableWhitespace (char ch[], int start, int length)219throws SAXException;220221222/**223* Receive notification of a processing instruction.224*225* <p>The Parser will invoke this method once for each processing226* instruction found: note that processing instructions may occur227* before or after the main document element.</p>228*229* <p>A SAX parser should never report an XML declaration (XML 1.0,230* section 2.8) or a text declaration (XML 1.0, section 4.3.1)231* using this method.</p>232*233* @param target The processing instruction target.234* @param data The processing instruction data, or null if235* none was supplied.236* @throws org.xml.sax.SAXException Any SAX exception, possibly237* wrapping another exception.238*/239public abstract void processingInstruction (String target, String data)240throws SAXException;241242}243244// end of DocumentHandler.java245246247