1. // SAX error handler.
  2. // http://www.saxproject.org
  3. // No warranty; no copyright -- use this as you will.
  4. // $Id: ErrorHandler.java,v 1.1.24.1 2004/05/01 08:34:39 jsuttor Exp $
  5. package org.xml.sax;
  6. /**
  7. * Basic interface for SAX error handlers.
  8. *
  9. * <blockquote>
  10. * <em>This module, both source code and documentation, is in the
  11. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  12. * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  13. * for further information.
  14. * </blockquote>
  15. *
  16. * <p>If a SAX application needs to implement customized error
  17. * handling, it must implement this interface and then register an
  18. * instance with the XML reader using the
  19. * {@link org.xml.sax.XMLReader#setErrorHandler setErrorHandler}
  20. * method. The parser will then report all errors and warnings
  21. * through this interface.</p>
  22. *
  23. * <p><strong>WARNING:</strong> If an application does <em>not</em>
  24. * register an ErrorHandler, XML parsing errors will go unreported,
  25. * except that <em>SAXParseException</em>s will be thrown for fatal errors.
  26. * In order to detect validity errors, an ErrorHandler that does something
  27. * with {@link #error error()} calls must be registered.</p>
  28. *
  29. * <p>For XML processing errors, a SAX driver must use this interface
  30. * in preference to throwing an exception: it is up to the application
  31. * to decide whether to throw an exception for different types of
  32. * errors and warnings. Note, however, that there is no requirement that
  33. * the parser continue to report additional errors after a call to
  34. * {@link #fatalError fatalError}. In other words, a SAX driver class
  35. * may throw an exception after reporting any fatalError.
  36. * Also parsers may throw appropriate exceptions for non-XML errors.
  37. * For example, {@link XMLReader#parse XMLReader.parse()} would throw
  38. * an IOException for errors accessing entities or the document.</p>
  39. *
  40. * @since SAX 1.0
  41. * @author David Megginson
  42. * @version 2.0.1+ (sax2r3pre1)
  43. * @see org.xml.sax.XMLReader#setErrorHandler
  44. * @see org.xml.sax.SAXParseException
  45. */
  46. public interface ErrorHandler {
  47. /**
  48. * Receive notification of a warning.
  49. *
  50. * <p>SAX parsers will use this method to report conditions that
  51. * are not errors or fatal errors as defined by the XML
  52. * recommendation. The default behaviour is to take no
  53. * action.</p>
  54. *
  55. * <p>The SAX parser must continue to provide normal parsing events
  56. * after invoking this method: it should still be possible for the
  57. * application to process the document through to the end.</p>
  58. *
  59. * <p>Filters may use this method to report other, non-XML warnings
  60. * as well.</p>
  61. *
  62. * @param exception The warning information encapsulated in a
  63. * SAX parse exception.
  64. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  65. * wrapping another exception.
  66. * @see org.xml.sax.SAXParseException
  67. */
  68. public abstract void warning (SAXParseException exception)
  69. throws SAXException;
  70. /**
  71. * Receive notification of a recoverable error.
  72. *
  73. * <p>This corresponds to the definition of "error" in section 1.2
  74. * of the W3C XML 1.0 Recommendation. For example, a validating
  75. * parser would use this callback to report the violation of a
  76. * validity constraint. The default behaviour is to take no
  77. * action.</p>
  78. *
  79. * <p>The SAX parser must continue to provide normal parsing
  80. * events after invoking this method: it should still be possible
  81. * for the application to process the document through to the end.
  82. * If the application cannot do so, then the parser should report
  83. * a fatal error even if the XML recommendation does not require
  84. * it to do so.</p>
  85. *
  86. * <p>Filters may use this method to report other, non-XML errors
  87. * as well.</p>
  88. *
  89. * @param exception The error information encapsulated in a
  90. * SAX parse exception.
  91. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  92. * wrapping another exception.
  93. * @see org.xml.sax.SAXParseException
  94. */
  95. public abstract void error (SAXParseException exception)
  96. throws SAXException;
  97. /**
  98. * Receive notification of a non-recoverable error.
  99. *
  100. * <p><strong>There is an apparent contradiction between the
  101. * documentation for this method and the documentation for {@link
  102. * org.xml.sax.ContentHandler#endDocument}. Until this ambiguity
  103. * is resolved in a future major release, clients should make no
  104. * assumptions about whether endDocument() will or will not be
  105. * invoked when the parser has reported a fatalError() or thrown
  106. * an exception.</strong></p>
  107. *
  108. * <p>This corresponds to the definition of "fatal error" in
  109. * section 1.2 of the W3C XML 1.0 Recommendation. For example, a
  110. * parser would use this callback to report the violation of a
  111. * well-formedness constraint.</p>
  112. *
  113. * <p>The application must assume that the document is unusable
  114. * after the parser has invoked this method, and should continue
  115. * (if at all) only for the sake of collecting additional error
  116. * messages: in fact, SAX parsers are free to stop reporting any
  117. * other events once this method has been invoked.</p>
  118. *
  119. * @param exception The error information encapsulated in a
  120. * SAX parse exception.
  121. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  122. * wrapping another exception.
  123. * @see org.xml.sax.SAXParseException
  124. */
  125. public abstract void fatalError (SAXParseException exception)
  126. throws SAXException;
  127. }
  128. // end of ErrorHandler.java