Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/helpers/DefaultHandler.java
48576 views
/*1* Copyright (c) 2000, 2006, 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// DefaultHandler.java - default implementation of the core handlers.26// http://www.saxproject.org27// Written by David Megginson28// NO WARRANTY! This class is in the public domain.29// $Id: DefaultHandler.java,v 1.3 2006/04/13 02:06:32 jeffsuttor Exp $3031package org.xml.sax.helpers;3233import java.io.IOException;3435import org.xml.sax.InputSource;36import org.xml.sax.Locator;37import org.xml.sax.Attributes;38import org.xml.sax.EntityResolver;39import org.xml.sax.DTDHandler;40import org.xml.sax.ContentHandler;41import org.xml.sax.ErrorHandler;42import org.xml.sax.SAXException;43import org.xml.sax.SAXParseException;444546/**47* Default base class for SAX2 event handlers.48*49* <blockquote>50* <em>This module, both source code and documentation, is in the51* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>52* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>53* for further information.54* </blockquote>55*56* <p>This class is available as a convenience base class for SAX257* applications: it provides default implementations for all of the58* callbacks in the four core SAX2 handler classes:</p>59*60* <ul>61* <li>{@link org.xml.sax.EntityResolver EntityResolver}</li>62* <li>{@link org.xml.sax.DTDHandler DTDHandler}</li>63* <li>{@link org.xml.sax.ContentHandler ContentHandler}</li>64* <li>{@link org.xml.sax.ErrorHandler ErrorHandler}</li>65* </ul>66*67* <p>Application writers can extend this class when they need to68* implement only part of an interface; parser writers can69* instantiate this class to provide default handlers when the70* application has not supplied its own.</p>71*72* <p>This class replaces the deprecated SAX173* {@link org.xml.sax.HandlerBase HandlerBase} class.</p>74*75* @since SAX 2.076* @author David Megginson,77* @see org.xml.sax.EntityResolver78* @see org.xml.sax.DTDHandler79* @see org.xml.sax.ContentHandler80* @see org.xml.sax.ErrorHandler81*/82public class DefaultHandler83implements EntityResolver, DTDHandler, ContentHandler, ErrorHandler84{858687////////////////////////////////////////////////////////////////////88// Default implementation of the EntityResolver interface.89////////////////////////////////////////////////////////////////////9091/**92* Resolve an external entity.93*94* <p>Always return null, so that the parser will use the system95* identifier provided in the XML document. This method implements96* the SAX default behaviour: application writers can override it97* in a subclass to do special translations such as catalog lookups98* or URI redirection.</p>99*100* @param publicId The public identifier, or null if none is101* available.102* @param systemId The system identifier provided in the XML103* document.104* @return The new input source, or null to require the105* default behaviour.106* @exception java.io.IOException If there is an error setting107* up the new input source.108* @exception org.xml.sax.SAXException Any SAX exception, possibly109* wrapping another exception.110* @see org.xml.sax.EntityResolver#resolveEntity111*/112public InputSource resolveEntity (String publicId, String systemId)113throws IOException, SAXException114{115return null;116}117118119120////////////////////////////////////////////////////////////////////121// Default implementation of DTDHandler interface.122////////////////////////////////////////////////////////////////////123124125/**126* Receive notification of a notation declaration.127*128* <p>By default, do nothing. Application writers may override this129* method in a subclass if they wish to keep track of the notations130* declared in a document.</p>131*132* @param name The notation name.133* @param publicId The notation public identifier, or null if not134* available.135* @param systemId The notation system identifier.136* @exception org.xml.sax.SAXException Any SAX exception, possibly137* wrapping another exception.138* @see org.xml.sax.DTDHandler#notationDecl139*/140public void notationDecl (String name, String publicId, String systemId)141throws SAXException142{143// no op144}145146147/**148* Receive notification of an unparsed entity declaration.149*150* <p>By default, do nothing. Application writers may override this151* method in a subclass to keep track of the unparsed entities152* declared in a document.</p>153*154* @param name The entity name.155* @param publicId The entity public identifier, or null if not156* available.157* @param systemId The entity system identifier.158* @param notationName The name of the associated notation.159* @exception org.xml.sax.SAXException Any SAX exception, possibly160* wrapping another exception.161* @see org.xml.sax.DTDHandler#unparsedEntityDecl162*/163public void unparsedEntityDecl (String name, String publicId,164String systemId, String notationName)165throws SAXException166{167// no op168}169170171172////////////////////////////////////////////////////////////////////173// Default implementation of ContentHandler interface.174////////////////////////////////////////////////////////////////////175176177/**178* Receive a Locator object for document events.179*180* <p>By default, do nothing. Application writers may override this181* method in a subclass if they wish to store the locator for use182* with other document events.</p>183*184* @param locator A locator for all SAX document events.185* @see org.xml.sax.ContentHandler#setDocumentLocator186* @see org.xml.sax.Locator187*/188public void setDocumentLocator (Locator locator)189{190// no op191}192193194/**195* Receive notification of the beginning of the document.196*197* <p>By default, do nothing. Application writers may override this198* method in a subclass to take specific actions at the beginning199* of a document (such as allocating the root node of a tree or200* creating an output file).</p>201*202* @exception org.xml.sax.SAXException Any SAX exception, possibly203* wrapping another exception.204* @see org.xml.sax.ContentHandler#startDocument205*/206public void startDocument ()207throws SAXException208{209// no op210}211212213/**214* Receive notification of the end of the document.215*216* <p>By default, do nothing. Application writers may override this217* method in a subclass to take specific actions at the end218* of a document (such as finalising a tree or closing an output219* file).</p>220*221* @exception org.xml.sax.SAXException Any SAX exception, possibly222* wrapping another exception.223* @see org.xml.sax.ContentHandler#endDocument224*/225public void endDocument ()226throws SAXException227{228// no op229}230231232/**233* Receive notification of the start of a Namespace mapping.234*235* <p>By default, do nothing. Application writers may override this236* method in a subclass to take specific actions at the start of237* each Namespace prefix scope (such as storing the prefix mapping).</p>238*239* @param prefix The Namespace prefix being declared.240* @param uri The Namespace URI mapped to the prefix.241* @exception org.xml.sax.SAXException Any SAX exception, possibly242* wrapping another exception.243* @see org.xml.sax.ContentHandler#startPrefixMapping244*/245public void startPrefixMapping (String prefix, String uri)246throws SAXException247{248// no op249}250251252/**253* Receive notification of the end of a Namespace mapping.254*255* <p>By default, do nothing. Application writers may override this256* method in a subclass to take specific actions at the end of257* each prefix mapping.</p>258*259* @param prefix The Namespace prefix being declared.260* @exception org.xml.sax.SAXException Any SAX exception, possibly261* wrapping another exception.262* @see org.xml.sax.ContentHandler#endPrefixMapping263*/264public void endPrefixMapping (String prefix)265throws SAXException266{267// no op268}269270271/**272* Receive notification of the start of an element.273*274* <p>By default, do nothing. Application writers may override this275* method in a subclass to take specific actions at the start of276* each element (such as allocating a new tree node or writing277* output to a file).</p>278*279* @param uri The Namespace URI, or the empty string if the280* element has no Namespace URI or if Namespace281* processing is not being performed.282* @param localName The local name (without prefix), or the283* empty string if Namespace processing is not being284* performed.285* @param qName The qualified name (with prefix), or the286* empty string if qualified names are not available.287* @param attributes The attributes attached to the element. If288* there are no attributes, it shall be an empty289* Attributes object.290* @exception org.xml.sax.SAXException Any SAX exception, possibly291* wrapping another exception.292* @see org.xml.sax.ContentHandler#startElement293*/294public void startElement (String uri, String localName,295String qName, Attributes attributes)296throws SAXException297{298// no op299}300301302/**303* Receive notification of the end of an element.304*305* <p>By default, do nothing. Application writers may override this306* method in a subclass to take specific actions at the end of307* each element (such as finalising a tree node or writing308* output to a file).</p>309*310* @param uri The Namespace URI, or the empty string if the311* element has no Namespace URI or if Namespace312* processing is not being performed.313* @param localName The local name (without prefix), or the314* empty string if Namespace processing is not being315* performed.316* @param qName The qualified name (with prefix), or the317* empty string if qualified names are not available.318* @exception org.xml.sax.SAXException Any SAX exception, possibly319* wrapping another exception.320* @see org.xml.sax.ContentHandler#endElement321*/322public void endElement (String uri, String localName, String qName)323throws SAXException324{325// no op326}327328329/**330* Receive notification of character data inside an element.331*332* <p>By default, do nothing. Application writers may override this333* method to take specific actions for each chunk of character data334* (such as adding the data to a node or buffer, or printing it to335* a file).</p>336*337* @param ch The characters.338* @param start The start position in the character array.339* @param length The number of characters to use from the340* character array.341* @exception org.xml.sax.SAXException Any SAX exception, possibly342* wrapping another exception.343* @see org.xml.sax.ContentHandler#characters344*/345public void characters (char ch[], int start, int length)346throws SAXException347{348// no op349}350351352/**353* Receive notification of ignorable whitespace in element content.354*355* <p>By default, do nothing. Application writers may override this356* method to take specific actions for each chunk of ignorable357* whitespace (such as adding data to a node or buffer, or printing358* it to a file).</p>359*360* @param ch The whitespace characters.361* @param start The start position in the character array.362* @param length The number of characters to use from the363* character array.364* @exception org.xml.sax.SAXException Any SAX exception, possibly365* wrapping another exception.366* @see org.xml.sax.ContentHandler#ignorableWhitespace367*/368public void ignorableWhitespace (char ch[], int start, int length)369throws SAXException370{371// no op372}373374375/**376* Receive notification of a processing instruction.377*378* <p>By default, do nothing. Application writers may override this379* method in a subclass to take specific actions for each380* processing instruction, such as setting status variables or381* invoking other methods.</p>382*383* @param target The processing instruction target.384* @param data The processing instruction data, or null if385* none is supplied.386* @exception org.xml.sax.SAXException Any SAX exception, possibly387* wrapping another exception.388* @see org.xml.sax.ContentHandler#processingInstruction389*/390public void processingInstruction (String target, String data)391throws SAXException392{393// no op394}395396397/**398* Receive notification of a skipped entity.399*400* <p>By default, do nothing. Application writers may override this401* method in a subclass to take specific actions for each402* processing instruction, such as setting status variables or403* invoking other methods.</p>404*405* @param name The name of the skipped entity.406* @exception org.xml.sax.SAXException Any SAX exception, possibly407* wrapping another exception.408* @see org.xml.sax.ContentHandler#processingInstruction409*/410public void skippedEntity (String name)411throws SAXException412{413// no op414}415416417418////////////////////////////////////////////////////////////////////419// Default implementation of the ErrorHandler interface.420////////////////////////////////////////////////////////////////////421422423/**424* Receive notification of a parser warning.425*426* <p>The default implementation does nothing. Application writers427* may override this method in a subclass to take specific actions428* for each warning, such as inserting the message in a log file or429* printing it to the console.</p>430*431* @param e The warning information encoded as an exception.432* @exception org.xml.sax.SAXException Any SAX exception, possibly433* wrapping another exception.434* @see org.xml.sax.ErrorHandler#warning435* @see org.xml.sax.SAXParseException436*/437public void warning (SAXParseException e)438throws SAXException439{440// no op441}442443444/**445* Receive notification of a recoverable parser error.446*447* <p>The default implementation does nothing. Application writers448* may override this method in a subclass to take specific actions449* for each error, such as inserting the message in a log file or450* printing it to the console.</p>451*452* @param e The error information encoded as an exception.453* @exception org.xml.sax.SAXException Any SAX exception, possibly454* wrapping another exception.455* @see org.xml.sax.ErrorHandler#warning456* @see org.xml.sax.SAXParseException457*/458public void error (SAXParseException e)459throws SAXException460{461// no op462}463464465/**466* Report a fatal XML parsing error.467*468* <p>The default implementation throws a SAXParseException.469* Application writers may override this method in a subclass if470* they need to take specific actions for each fatal error (such as471* collecting all of the errors into a single report): in any case,472* the application must stop all regular processing when this473* method is invoked, since the document is no longer reliable, and474* the parser may no longer report parsing events.</p>475*476* @param e The error information encoded as an exception.477* @exception org.xml.sax.SAXException Any SAX exception, possibly478* wrapping another exception.479* @see org.xml.sax.ErrorHandler#fatalError480* @see org.xml.sax.SAXParseException481*/482public void fatalError (SAXParseException e)483throws SAXException484{485throw e;486}487488}489490// end of DefaultHandler.java491492493