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