1 /*
   2  * Copyright (c) 2000, 2017, 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 // SAX default handler base class.
  27 // http://www.saxproject.org
  28 // No warranty; no copyright -- use this as you will.
  29 // $Id: HandlerBase.java,v 1.2 2005/06/10 03:50:47 jeffsuttor Exp $
  30 
  31 package org.xml.sax;
  32 
  33 /**
  34  * Default base class for handlers.
  35  *
  36  * <blockquote>
  37  * <em>This module, both source code and documentation, is in the
  38  * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  39  * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  40  * for further information.
  41  * </blockquote>
  42  *
  43  * <p>This class implements the default behaviour for four SAX1
  44  * interfaces: EntityResolver, DTDHandler, DocumentHandler,
  45  * and ErrorHandler.  It is now obsolete, but is included in SAX2 to
  46  * support legacy SAX1 applications.  SAX2 applications should use
  47  * the {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}
  48  * class instead.</p>
  49  *
  50  * <p>Application writers can extend this class when they need to
  51  * implement only part of an interface; parser writers can
  52  * instantiate this class to provide default handlers when the
  53  * application has not supplied its own.</p>
  54  *
  55  * <p>Note that the use of this class is optional.</p>
  56  *
  57  * @deprecated This class works with the deprecated
  58  *             {@link org.xml.sax.DocumentHandler DocumentHandler}
  59  *             interface.  It has been replaced by the SAX2
  60  *             {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}
  61  *             class.
  62  * @since 1.4, SAX 1.0
  63  * @author David Megginson
  64  * @see org.xml.sax.EntityResolver
  65  * @see org.xml.sax.DTDHandler
  66  * @see org.xml.sax.DocumentHandler
  67  * @see org.xml.sax.ErrorHandler
  68  */
  69 @Deprecated(since="1.5")
  70 public class HandlerBase
  71     implements EntityResolver, DTDHandler, DocumentHandler, ErrorHandler
  72 {
  73 
  74 
  75     ////////////////////////////////////////////////////////////////////
  76     // Default implementation of the EntityResolver interface.
  77     ////////////////////////////////////////////////////////////////////
  78 
  79     /**
  80      * Resolve an external entity.
  81      *
  82      * <p>Always return null, so that the parser will use the system
  83      * identifier provided in the XML document.  This method implements
  84      * the SAX default behaviour: application writers can override it
  85      * in a subclass to do special translations such as catalog lookups
  86      * or URI redirection.</p>
  87      *
  88      * @param publicId The public identifer, or null if none is
  89      *                 available.
  90      * @param systemId The system identifier provided in the XML
  91      *                 document.
  92      * @return The new input source, or null to require the
  93      *         default behaviour.
  94      * @exception org.xml.sax.SAXException Any SAX exception, possibly
  95      *            wrapping another exception.
  96      * @see org.xml.sax.EntityResolver#resolveEntity
  97      */
  98     public InputSource resolveEntity (String publicId, String systemId)
  99         throws SAXException
 100     {
 101         return null;
 102     }
 103 
 104 
 105 
 106     ////////////////////////////////////////////////////////////////////
 107     // Default implementation of DTDHandler interface.
 108     ////////////////////////////////////////////////////////////////////
 109 
 110 
 111     /**
 112      * Receive notification of a notation declaration.
 113      *
 114      * <p>By default, do nothing.  Application writers may override this
 115      * method in a subclass if they wish to keep track of the notations
 116      * declared in a document.</p>
 117      *
 118      * @param name The notation name.
 119      * @param publicId The notation public identifier, or null if not
 120      *                 available.
 121      * @param systemId The notation system identifier.
 122      * @see org.xml.sax.DTDHandler#notationDecl
 123      */
 124     public void notationDecl (String name, String publicId, String systemId)
 125     {
 126         // no op
 127     }
 128 
 129 
 130     /**
 131      * Receive notification of an unparsed entity declaration.
 132      *
 133      * <p>By default, do nothing.  Application writers may override this
 134      * method in a subclass to keep track of the unparsed entities
 135      * declared in a document.</p>
 136      *
 137      * @param name The entity name.
 138      * @param publicId The entity public identifier, or null if not
 139      *                 available.
 140      * @param systemId The entity system identifier.
 141      * @param notationName The name of the associated notation.
 142      * @see org.xml.sax.DTDHandler#unparsedEntityDecl
 143      */
 144     public void unparsedEntityDecl (String name, String publicId,
 145                                     String systemId, String notationName)
 146     {
 147         // no op
 148     }
 149 
 150 
 151 
 152     ////////////////////////////////////////////////////////////////////
 153     // Default implementation of DocumentHandler interface.
 154     ////////////////////////////////////////////////////////////////////
 155 
 156 
 157     /**
 158      * Receive a Locator object for document events.
 159      *
 160      * <p>By default, do nothing.  Application writers may override this
 161      * method in a subclass if they wish to store the locator for use
 162      * with other document events.</p>
 163      *
 164      * @param locator A locator for all SAX document events.
 165      * @see org.xml.sax.DocumentHandler#setDocumentLocator
 166      * @see org.xml.sax.Locator
 167      */
 168     public void setDocumentLocator (Locator locator)
 169     {
 170         // no op
 171     }
 172 
 173 
 174     /**
 175      * Receive notification of the beginning of the document.
 176      *
 177      * <p>By default, do nothing.  Application writers may override this
 178      * method in a subclass to take specific actions at the beginning
 179      * of a document (such as allocating the root node of a tree or
 180      * creating an output file).</p>
 181      *
 182      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 183      *            wrapping another exception.
 184      * @see org.xml.sax.DocumentHandler#startDocument
 185      */
 186     public void startDocument ()
 187         throws SAXException
 188     {
 189         // no op
 190     }
 191 
 192 
 193     /**
 194      * Receive notification of the end of the document.
 195      *
 196      * <p>By default, do nothing.  Application writers may override this
 197      * method in a subclass to take specific actions at the end
 198      * of a document (such as finalising a tree or closing an output
 199      * file).</p>
 200      *
 201      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 202      *            wrapping another exception.
 203      * @see org.xml.sax.DocumentHandler#endDocument
 204      */
 205     public void endDocument ()
 206         throws SAXException
 207     {
 208         // no op
 209     }
 210 
 211 
 212     /**
 213      * Receive notification of the start of an element.
 214      *
 215      * <p>By default, do nothing.  Application writers may override this
 216      * method in a subclass to take specific actions at the start of
 217      * each element (such as allocating a new tree node or writing
 218      * output to a file).</p>
 219      *
 220      * @param name The element type name.
 221      * @param attributes The specified or defaulted attributes.
 222      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 223      *            wrapping another exception.
 224      * @see org.xml.sax.DocumentHandler#startElement
 225      */
 226     public void startElement (String name, AttributeList attributes)
 227         throws SAXException
 228     {
 229         // no op
 230     }
 231 
 232 
 233     /**
 234      * Receive notification of the end of an element.
 235      *
 236      * <p>By default, do nothing.  Application writers may override this
 237      * method in a subclass to take specific actions at the end of
 238      * each element (such as finalising a tree node or writing
 239      * output to a file).</p>
 240      *
 241      * @param name the element name
 242      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 243      *            wrapping another exception.
 244      * @see org.xml.sax.DocumentHandler#endElement
 245      */
 246     public void endElement (String name)
 247         throws SAXException
 248     {
 249         // no op
 250     }
 251 
 252 
 253     /**
 254      * Receive notification of character data inside an element.
 255      *
 256      * <p>By default, do nothing.  Application writers may override this
 257      * method to take specific actions for each chunk of character data
 258      * (such as adding the data to a node or buffer, or printing it to
 259      * a file).</p>
 260      *
 261      * @param ch The characters.
 262      * @param start The start position in the character array.
 263      * @param length The number of characters to use from the
 264      *               character array.
 265      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 266      *            wrapping another exception.
 267      * @see org.xml.sax.DocumentHandler#characters
 268      */
 269     public void characters (char ch[], int start, int length)
 270         throws SAXException
 271     {
 272         // no op
 273     }
 274 
 275 
 276     /**
 277      * Receive notification of ignorable whitespace in element content.
 278      *
 279      * <p>By default, do nothing.  Application writers may override this
 280      * method to take specific actions for each chunk of ignorable
 281      * whitespace (such as adding data to a node or buffer, or printing
 282      * it to a file).</p>
 283      *
 284      * @param ch The whitespace characters.
 285      * @param start The start position in the character array.
 286      * @param length The number of characters to use from the
 287      *               character array.
 288      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 289      *            wrapping another exception.
 290      * @see org.xml.sax.DocumentHandler#ignorableWhitespace
 291      */
 292     public void ignorableWhitespace (char ch[], int start, int length)
 293         throws SAXException
 294     {
 295         // no op
 296     }
 297 
 298 
 299     /**
 300      * Receive notification of a processing instruction.
 301      *
 302      * <p>By default, do nothing.  Application writers may override this
 303      * method in a subclass to take specific actions for each
 304      * processing instruction, such as setting status variables or
 305      * invoking other methods.</p>
 306      *
 307      * @param target The processing instruction target.
 308      * @param data The processing instruction data, or null if
 309      *             none is supplied.
 310      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 311      *            wrapping another exception.
 312      * @see org.xml.sax.DocumentHandler#processingInstruction
 313      */
 314     public void processingInstruction (String target, String data)
 315         throws SAXException
 316     {
 317         // no op
 318     }
 319 
 320 
 321 
 322     ////////////////////////////////////////////////////////////////////
 323     // Default implementation of the ErrorHandler interface.
 324     ////////////////////////////////////////////////////////////////////
 325 
 326 
 327     /**
 328      * Receive notification of a parser warning.
 329      *
 330      * <p>The default implementation does nothing.  Application writers
 331      * may override this method in a subclass to take specific actions
 332      * for each warning, such as inserting the message in a log file or
 333      * printing it to the console.</p>
 334      *
 335      * @param e The warning information encoded as an exception.
 336      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 337      *            wrapping another exception.
 338      * @see org.xml.sax.ErrorHandler#warning
 339      * @see org.xml.sax.SAXParseException
 340      */
 341     public void warning (SAXParseException e)
 342         throws SAXException
 343     {
 344         // no op
 345     }
 346 
 347 
 348     /**
 349      * Receive notification of a recoverable parser error.
 350      *
 351      * <p>The default implementation does nothing.  Application writers
 352      * may override this method in a subclass to take specific actions
 353      * for each error, such as inserting the message in a log file or
 354      * printing it to the console.</p>
 355      *
 356      * @param e The warning information encoded as an exception.
 357      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 358      *            wrapping another exception.
 359      * @see org.xml.sax.ErrorHandler#warning
 360      * @see org.xml.sax.SAXParseException
 361      */
 362     public void error (SAXParseException e)
 363         throws SAXException
 364     {
 365         // no op
 366     }
 367 
 368 
 369     /**
 370      * Report a fatal XML parsing error.
 371      *
 372      * <p>The default implementation throws a SAXParseException.
 373      * Application writers may override this method in a subclass if
 374      * they need to take specific actions for each fatal error (such as
 375      * collecting all of the errors into a single report): in any case,
 376      * the application must stop all regular processing when this
 377      * method is invoked, since the document is no longer reliable, and
 378      * the parser may no longer report parsing events.</p>
 379      *
 380      * @param e The error information encoded as an exception.
 381      * @exception org.xml.sax.SAXException Any SAX exception, possibly
 382      *            wrapping another exception.
 383      * @see org.xml.sax.ErrorHandler#fatalError
 384      * @see org.xml.sax.SAXParseException
 385      */
 386     public void fatalError (SAXParseException e)
 387         throws SAXException
 388     {
 389         throw e;
 390     }
 391 
 392 }
 393 
 394 // end of HandlerBase.java