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