Path: blob/master/src/java.xml/share/classes/org/xml/sax/HandlerBase.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* Default base class for handlers.29*30* <p>This class implements the default behavior for four SAX131* interfaces: EntityResolver, DTDHandler, DocumentHandler,32* and ErrorHandler. It is now obsolete, but is included in SAX2 to33* support legacy SAX1 applications. SAX2 applications should use34* the {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}35* class instead.</p>36*37* <p>Application writers can extend this class when they need to38* implement only part of an interface; parser writers can39* instantiate this class to provide default handlers when the40* application has not supplied its own.</p>41*42* <p>Note that the use of this class is optional.</p>43*44* @deprecated This class works with the deprecated45* {@link org.xml.sax.DocumentHandler DocumentHandler}46* interface. It has been replaced by the SAX247* {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}48* class.49* @since 1.4, SAX 1.050* @author David Megginson51* @see org.xml.sax.EntityResolver52* @see org.xml.sax.DTDHandler53* @see org.xml.sax.DocumentHandler54* @see org.xml.sax.ErrorHandler55*/56@Deprecated(since="1.5")57public class HandlerBase58implements EntityResolver, DTDHandler, DocumentHandler, ErrorHandler59{60/**61* Creates a {@code HandlerBase}.62*/63public HandlerBase() {}6465////////////////////////////////////////////////////////////////////66// Default implementation of the EntityResolver interface.67////////////////////////////////////////////////////////////////////6869/**70* Resolve an external entity.71*72* <p>Always return null, so that the parser will use the system73* identifier provided in the XML document. This method implements74* the SAX default behaviour: application writers can override it75* in a subclass to do special translations such as catalog lookups76* or URI redirection.</p>77*78* @param publicId The public identifer, or null if none is79* available.80* @param systemId The system identifier provided in the XML81* document.82* @return The new input source, or null to require the83* default behaviour.84* @throws org.xml.sax.SAXException Any SAX exception, possibly85* wrapping another exception.86* @see org.xml.sax.EntityResolver#resolveEntity87*/88public InputSource resolveEntity (String publicId, String systemId)89throws SAXException90{91return null;92}93949596////////////////////////////////////////////////////////////////////97// Default implementation of DTDHandler interface.98////////////////////////////////////////////////////////////////////99100101/**102* Receive notification of a notation declaration.103*104* <p>By default, do nothing. Application writers may override this105* method in a subclass if they wish to keep track of the notations106* declared in a document.</p>107*108* @param name The notation name.109* @param publicId The notation public identifier, or null if not110* available.111* @param systemId The notation system identifier.112* @see org.xml.sax.DTDHandler#notationDecl113*/114public void notationDecl (String name, String publicId, String systemId)115{116// no op117}118119120/**121* Receive notification of an unparsed entity declaration.122*123* <p>By default, do nothing. Application writers may override this124* method in a subclass to keep track of the unparsed entities125* declared in a document.</p>126*127* @param name The entity name.128* @param publicId The entity public identifier, or null if not129* available.130* @param systemId The entity system identifier.131* @param notationName The name of the associated notation.132* @see org.xml.sax.DTDHandler#unparsedEntityDecl133*/134public void unparsedEntityDecl (String name, String publicId,135String systemId, String notationName)136{137// no op138}139140141142////////////////////////////////////////////////////////////////////143// Default implementation of DocumentHandler interface.144////////////////////////////////////////////////////////////////////145146147/**148* Receive a Locator object for document events.149*150* <p>By default, do nothing. Application writers may override this151* method in a subclass if they wish to store the locator for use152* with other document events.</p>153*154* @param locator A locator for all SAX document events.155* @see org.xml.sax.DocumentHandler#setDocumentLocator156* @see org.xml.sax.Locator157*/158public void setDocumentLocator (Locator locator)159{160// no op161}162163164/**165* Receive notification of the beginning of the document.166*167* <p>By default, do nothing. Application writers may override this168* method in a subclass to take specific actions at the beginning169* of a document (such as allocating the root node of a tree or170* creating an output file).</p>171*172* @throws org.xml.sax.SAXException Any SAX exception, possibly173* wrapping another exception.174* @see org.xml.sax.DocumentHandler#startDocument175*/176public void startDocument ()177throws SAXException178{179// no op180}181182183/**184* Receive notification of the end of the document.185*186* <p>By default, do nothing. Application writers may override this187* method in a subclass to take specific actions at the end188* of a document (such as finalising a tree or closing an output189* file).</p>190*191* @throws org.xml.sax.SAXException Any SAX exception, possibly192* wrapping another exception.193* @see org.xml.sax.DocumentHandler#endDocument194*/195public void endDocument ()196throws SAXException197{198// no op199}200201202/**203* Receive notification of the start of an element.204*205* <p>By default, do nothing. Application writers may override this206* method in a subclass to take specific actions at the start of207* each element (such as allocating a new tree node or writing208* output to a file).</p>209*210* @param name The element type name.211* @param attributes The specified or defaulted attributes.212* @throws org.xml.sax.SAXException Any SAX exception, possibly213* wrapping another exception.214* @see org.xml.sax.DocumentHandler#startElement215*/216public void startElement (String name, AttributeList attributes)217throws SAXException218{219// no op220}221222223/**224* Receive notification of the end of an element.225*226* <p>By default, do nothing. Application writers may override this227* method in a subclass to take specific actions at the end of228* each element (such as finalising a tree node or writing229* output to a file).</p>230*231* @param name the element name232* @throws org.xml.sax.SAXException Any SAX exception, possibly233* wrapping another exception.234* @see org.xml.sax.DocumentHandler#endElement235*/236public void endElement (String name)237throws SAXException238{239// no op240}241242243/**244* Receive notification of character data inside an element.245*246* <p>By default, do nothing. Application writers may override this247* method to take specific actions for each chunk of character data248* (such as adding the data to a node or buffer, or printing it to249* a file).</p>250*251* @param ch The characters.252* @param start The start position in the character array.253* @param length The number of characters to use from the254* character array.255* @throws org.xml.sax.SAXException Any SAX exception, possibly256* wrapping another exception.257* @see org.xml.sax.DocumentHandler#characters258*/259public void characters (char ch[], int start, int length)260throws SAXException261{262// no op263}264265266/**267* Receive notification of ignorable whitespace in element content.268*269* <p>By default, do nothing. Application writers may override this270* method to take specific actions for each chunk of ignorable271* whitespace (such as adding data to a node or buffer, or printing272* it to a file).</p>273*274* @param ch The whitespace characters.275* @param start The start position in the character array.276* @param length The number of characters to use from the277* character array.278* @throws org.xml.sax.SAXException Any SAX exception, possibly279* wrapping another exception.280* @see org.xml.sax.DocumentHandler#ignorableWhitespace281*/282public void ignorableWhitespace (char ch[], int start, int length)283throws SAXException284{285// no op286}287288289/**290* Receive notification of a processing instruction.291*292* <p>By default, do nothing. Application writers may override this293* method in a subclass to take specific actions for each294* processing instruction, such as setting status variables or295* invoking other methods.</p>296*297* @param target The processing instruction target.298* @param data The processing instruction data, or null if299* none is supplied.300* @throws org.xml.sax.SAXException Any SAX exception, possibly301* wrapping another exception.302* @see org.xml.sax.DocumentHandler#processingInstruction303*/304public void processingInstruction (String target, String data)305throws SAXException306{307// no op308}309310311312////////////////////////////////////////////////////////////////////313// Default implementation of the ErrorHandler interface.314////////////////////////////////////////////////////////////////////315316317/**318* Receive notification of a parser warning.319*320* <p>The default implementation does nothing. Application writers321* may override this method in a subclass to take specific actions322* for each warning, such as inserting the message in a log file or323* printing it to the console.</p>324*325* @param e The warning information encoded as an exception.326* @throws org.xml.sax.SAXException Any SAX exception, possibly327* wrapping another exception.328* @see org.xml.sax.ErrorHandler#warning329* @see org.xml.sax.SAXParseException330*/331public void warning (SAXParseException e)332throws SAXException333{334// no op335}336337338/**339* Receive notification of a recoverable parser error.340*341* <p>The default implementation does nothing. Application writers342* may override this method in a subclass to take specific actions343* for each error, such as inserting the message in a log file or344* printing it to the console.</p>345*346* @param e The warning information encoded as an exception.347* @throws org.xml.sax.SAXException Any SAX exception, possibly348* wrapping another exception.349* @see org.xml.sax.ErrorHandler#warning350* @see org.xml.sax.SAXParseException351*/352public void error (SAXParseException e)353throws SAXException354{355// no op356}357358359/**360* Report a fatal XML parsing error.361*362* <p>The default implementation throws a SAXParseException.363* Application writers may override this method in a subclass if364* they need to take specific actions for each fatal error (such as365* collecting all of the errors into a single report): in any case,366* the application must stop all regular processing when this367* method is invoked, since the document is no longer reliable, and368* the parser may no longer report parsing events.</p>369*370* @param e The error information encoded as an exception.371* @throws org.xml.sax.SAXException Any SAX exception, possibly372* wrapping another exception.373* @see org.xml.sax.ErrorHandler#fatalError374* @see org.xml.sax.SAXParseException375*/376public void fatalError (SAXParseException e)377throws SAXException378{379throw e;380}381382}383384// end of HandlerBase.java385386387