1. // SAX parser interface.
  2. // No warranty; no copyright -- use this as you will.
  3. // $Id: Parser.java,v 1.1 2001/05/20 03:12:56 curcuru Exp $
  4. package org.xml.sax;
  5. import java.io.IOException;
  6. import java.util.Locale;
  7. /**
  8. * Basic interface for SAX (Simple API for XML) parsers.
  9. *
  10. * <blockquote>
  11. * <em>This module, both source code and documentation, is in the
  12. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  13. * </blockquote>
  14. *
  15. * <p>This was the main event supplier interface for SAX1; it has
  16. * been replaced in SAX2 by {@link org.xml.sax.XMLReader XMLReader},
  17. * which includes Namespace support and sophisticated configurability
  18. * and extensibility.</p>
  19. *
  20. * <p>All SAX1 parsers must implement this basic interface: it allows
  21. * applications to register handlers for different types of events
  22. * and to initiate a parse from a URI, or a character stream.</p>
  23. *
  24. * <p>All SAX1 parsers must also implement a zero-argument constructor
  25. * (though other constructors are also allowed).</p>
  26. *
  27. * <p>SAX1 parsers are reusable but not re-entrant: the application
  28. * may reuse a parser object (possibly with a different input source)
  29. * once the first parse has completed successfully, but it may not
  30. * invoke the parse() methods recursively within a parse.</p>
  31. *
  32. * @deprecated This interface has been replaced by the SAX2
  33. * {@link org.xml.sax.XMLReader XMLReader}
  34. * interface, which includes Namespace support.
  35. * @since SAX 1.0
  36. * @author David Megginson,
  37. * <a href="mailto:sax@megginson.com">sax@megginson.com</a>
  38. * @version 2.0r2pre
  39. * @see org.xml.sax.EntityResolver
  40. * @see org.xml.sax.DTDHandler
  41. * @see org.xml.sax.DocumentHandler
  42. * @see org.xml.sax.ErrorHandler
  43. * @see org.xml.sax.HandlerBase
  44. * @see org.xml.sax.InputSource
  45. */
  46. public interface Parser
  47. {
  48. /**
  49. * Allow an application to request a locale for errors and warnings.
  50. *
  51. * <p>SAX parsers are not required to provide localisation for errors
  52. * and warnings; if they cannot support the requested locale,
  53. * however, they must throw a SAX exception. Applications may
  54. * not request a locale change in the middle of a parse.</p>
  55. *
  56. * @param locale A Java Locale object.
  57. * @exception org.xml.sax.SAXException Throws an exception
  58. * (using the previous or default locale) if the
  59. * requested locale is not supported.
  60. * @see org.xml.sax.SAXException
  61. * @see org.xml.sax.SAXParseException
  62. */
  63. public abstract void setLocale (Locale locale)
  64. throws SAXException;
  65. /**
  66. * Allow an application to register a custom entity resolver.
  67. *
  68. * <p>If the application does not register an entity resolver, the
  69. * SAX parser will resolve system identifiers and open connections
  70. * to entities itself (this is the default behaviour implemented in
  71. * HandlerBase).</p>
  72. *
  73. * <p>Applications may register a new or different entity resolver
  74. * in the middle of a parse, and the SAX parser must begin using
  75. * the new resolver immediately.</p>
  76. *
  77. * @param resolver The object for resolving entities.
  78. * @see EntityResolver
  79. * @see HandlerBase
  80. */
  81. public abstract void setEntityResolver (EntityResolver resolver);
  82. /**
  83. * Allow an application to register a DTD event handler.
  84. *
  85. * <p>If the application does not register a DTD handler, all DTD
  86. * events reported by the SAX parser will be silently
  87. * ignored (this is the default behaviour implemented by
  88. * HandlerBase).</p>
  89. *
  90. * <p>Applications may register a new or different
  91. * handler in the middle of a parse, and the SAX parser must
  92. * begin using the new handler immediately.</p>
  93. *
  94. * @param handler The DTD handler.
  95. * @see DTDHandler
  96. * @see HandlerBase
  97. */
  98. public abstract void setDTDHandler (DTDHandler handler);
  99. /**
  100. * Allow an application to register a document event handler.
  101. *
  102. * <p>If the application does not register a document handler, all
  103. * document events reported by the SAX parser will be silently
  104. * ignored (this is the default behaviour implemented by
  105. * HandlerBase).</p>
  106. *
  107. * <p>Applications may register a new or different handler in the
  108. * middle of a parse, and the SAX parser must begin using the new
  109. * handler immediately.</p>
  110. *
  111. * @param handler The document handler.
  112. * @see DocumentHandler
  113. * @see HandlerBase
  114. */
  115. public abstract void setDocumentHandler (DocumentHandler handler);
  116. /**
  117. * Allow an application to register an error event handler.
  118. *
  119. * <p>If the application does not register an error event handler,
  120. * all error events reported by the SAX parser will be silently
  121. * ignored, except for fatalError, which will throw a SAXException
  122. * (this is the default behaviour implemented by HandlerBase).</p>
  123. *
  124. * <p>Applications may register a new or different handler in the
  125. * middle of a parse, and the SAX parser must begin using the new
  126. * handler immediately.</p>
  127. *
  128. * @param handler The error handler.
  129. * @see ErrorHandler
  130. * @see SAXException
  131. * @see HandlerBase
  132. */
  133. public abstract void setErrorHandler (ErrorHandler handler);
  134. /**
  135. * Parse an XML document.
  136. *
  137. * <p>The application can use this method to instruct the SAX parser
  138. * to begin parsing an XML document from any valid input
  139. * source (a character stream, a byte stream, or a URI).</p>
  140. *
  141. * <p>Applications may not invoke this method while a parse is in
  142. * progress (they should create a new Parser instead for each
  143. * additional XML document). Once a parse is complete, an
  144. * application may reuse the same Parser object, possibly with a
  145. * different input source.</p>
  146. *
  147. * @param source The input source for the top-level of the
  148. * XML document.
  149. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  150. * wrapping another exception.
  151. * @exception java.io.IOException An IO exception from the parser,
  152. * possibly from a byte stream or character stream
  153. * supplied by the application.
  154. * @see org.xml.sax.InputSource
  155. * @see #parse(java.lang.String)
  156. * @see #setEntityResolver
  157. * @see #setDTDHandler
  158. * @see #setDocumentHandler
  159. * @see #setErrorHandler
  160. */
  161. public abstract void parse (InputSource source)
  162. throws SAXException, IOException;
  163. /**
  164. * Parse an XML document from a system identifier (URI).
  165. *
  166. * <p>This method is a shortcut for the common case of reading a
  167. * document from a system identifier. It is the exact
  168. * equivalent of the following:</p>
  169. *
  170. * <pre>
  171. * parse(new InputSource(systemId));
  172. * </pre>
  173. *
  174. * <p>If the system identifier is a URL, it must be fully resolved
  175. * by the application before it is passed to the parser.</p>
  176. *
  177. * @param systemId The system identifier (URI).
  178. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  179. * wrapping another exception.
  180. * @exception java.io.IOException An IO exception from the parser,
  181. * possibly from a byte stream or character stream
  182. * supplied by the application.
  183. * @see #parse(org.xml.sax.InputSource)
  184. */
  185. public abstract void parse (String systemId)
  186. throws SAXException, IOException;
  187. }
  188. // end of Parser.java