1. // SAX document handler.
  2. // No warranty; no copyright -- use this as you will.
  3. // $Id: DocumentHandler.java,v 1.1 2001/05/20 03:12:56 curcuru Exp $
  4. package org.xml.sax;
  5. /**
  6. * Receive notification of general document events.
  7. *
  8. * <blockquote>
  9. * <em>This module, both source code and documentation, is in the
  10. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  11. * </blockquote>
  12. *
  13. * <p>This was the main event-handling interface for SAX1; in
  14. * SAX2, it has been replaced by {@link org.xml.sax.ContentHandler
  15. * ContentHandler}, which provides Namespace support and reporting
  16. * of skipped entities. This interface is included in SAX2 only
  17. * to support legacy SAX1 applications.</p>
  18. *
  19. * <p>The order of events in this interface is very important, and
  20. * mirrors the order of information in the document itself. For
  21. * example, all of an element's content (character data, processing
  22. * instructions, and/or subelements) will appear, in order, between
  23. * the startElement event and the corresponding endElement event.</p>
  24. *
  25. * <p>Application writers who do not want to implement the entire
  26. * interface can derive a class from HandlerBase, which implements
  27. * the default functionality; parser writers can instantiate
  28. * HandlerBase to obtain a default handler. The application can find
  29. * the location of any document event using the Locator interface
  30. * supplied by the Parser through the setDocumentLocator method.</p>
  31. *
  32. * @deprecated This interface has been replaced by the SAX2
  33. * {@link org.xml.sax.ContentHandler ContentHandler}
  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.Parser#setDocumentHandler
  40. * @see org.xml.sax.Locator
  41. * @see org.xml.sax.HandlerBase
  42. */
  43. public interface DocumentHandler {
  44. /**
  45. * Receive an object for locating the origin of SAX document events.
  46. *
  47. * <p>SAX parsers are strongly encouraged (though not absolutely
  48. * required) to supply a locator: if it does so, it must supply
  49. * the locator to the application by invoking this method before
  50. * invoking any of the other methods in the DocumentHandler
  51. * interface.</p>
  52. *
  53. * <p>The locator allows the application to determine the end
  54. * position of any document-related event, even if the parser is
  55. * not reporting an error. Typically, the application will
  56. * use this information for reporting its own errors (such as
  57. * character content that does not match an application's
  58. * business rules). The information returned by the locator
  59. * is probably not sufficient for use with a search engine.</p>
  60. *
  61. * <p>Note that the locator will return correct information only
  62. * during the invocation of the events in this interface. The
  63. * application should not attempt to use it at any other time.</p>
  64. *
  65. * @param locator An object that can return the location of
  66. * any SAX document event.
  67. * @see org.xml.sax.Locator
  68. */
  69. public abstract void setDocumentLocator (Locator locator);
  70. /**
  71. * Receive notification of the beginning of a document.
  72. *
  73. * <p>The SAX parser will invoke this method only once, before any
  74. * other methods in this interface or in DTDHandler (except for
  75. * setDocumentLocator).</p>
  76. *
  77. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  78. * wrapping another exception.
  79. */
  80. public abstract void startDocument ()
  81. throws SAXException;
  82. /**
  83. * Receive notification of the end of a document.
  84. *
  85. * <p>The SAX parser will invoke this method only once, and it will
  86. * be the last method invoked during the parse. The parser shall
  87. * not invoke this method until it has either abandoned parsing
  88. * (because of an unrecoverable error) or reached the end of
  89. * input.</p>
  90. *
  91. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  92. * wrapping another exception.
  93. */
  94. public abstract void endDocument ()
  95. throws SAXException;
  96. /**
  97. * Receive notification of the beginning of an element.
  98. *
  99. * <p>The Parser will invoke this method at the beginning of every
  100. * element in the XML document; there will be a corresponding
  101. * endElement() event for every startElement() event (even when the
  102. * element is empty). All of the element's content will be
  103. * reported, in order, before the corresponding endElement()
  104. * event.</p>
  105. *
  106. * <p>If the element name has a namespace prefix, the prefix will
  107. * still be attached. Note that the attribute list provided will
  108. * contain only attributes with explicit values (specified or
  109. * defaulted): #IMPLIED attributes will be omitted.</p>
  110. *
  111. * @param name The element type name.
  112. * @param atts The attributes attached to the element, if any.
  113. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  114. * wrapping another exception.
  115. * @see #endElement
  116. * @see org.xml.sax.AttributeList
  117. */
  118. public abstract void startElement (String name, AttributeList atts)
  119. throws SAXException;
  120. /**
  121. * Receive notification of the end of an element.
  122. *
  123. * <p>The SAX parser will invoke this method at the end of every
  124. * element in the XML document; there will be a corresponding
  125. * startElement() event for every endElement() event (even when the
  126. * element is empty).</p>
  127. *
  128. * <p>If the element name has a namespace prefix, the prefix will
  129. * still be attached to the name.</p>
  130. *
  131. * @param name The element type name
  132. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  133. * wrapping another exception.
  134. */
  135. public abstract void endElement (String name)
  136. throws SAXException;
  137. /**
  138. * Receive notification of character data.
  139. *
  140. * <p>The Parser will call this method to report each chunk of
  141. * character data. SAX parsers may return all contiguous character
  142. * data in a single chunk, or they may split it into several
  143. * chunks; however, all of the characters in any single event
  144. * must come from the same external entity, so that the Locator
  145. * provides useful information.</p>
  146. *
  147. * <p>The application must not attempt to read from the array
  148. * outside of the specified range.</p>
  149. *
  150. * <p>Note that some parsers will report whitespace using the
  151. * ignorableWhitespace() method rather than this one (validating
  152. * parsers must do so).</p>
  153. *
  154. * @param ch The characters from the XML document.
  155. * @param start The start position in the array.
  156. * @param length The number of characters to read from the array.
  157. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  158. * wrapping another exception.
  159. * @see #ignorableWhitespace
  160. * @see org.xml.sax.Locator
  161. */
  162. public abstract void characters (char ch[], int start, int length)
  163. throws SAXException;
  164. /**
  165. * Receive notification of ignorable whitespace in element content.
  166. *
  167. * <p>Validating Parsers must use this method to report each chunk
  168. * of ignorable whitespace (see the W3C XML 1.0 recommendation,
  169. * section 2.10): non-validating parsers may also use this method
  170. * if they are capable of parsing and using content models.</p>
  171. *
  172. * <p>SAX parsers may return all contiguous whitespace in a single
  173. * chunk, or they may split it into several chunks; however, all of
  174. * the characters in any single event must come from the same
  175. * external entity, so that the Locator provides useful
  176. * information.</p>
  177. *
  178. * <p>The application must not attempt to read from the array
  179. * outside of the specified range.</p>
  180. *
  181. * @param ch The characters from the XML document.
  182. * @param start The start position in the array.
  183. * @param length The number of characters to read from the array.
  184. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  185. * wrapping another exception.
  186. * @see #characters
  187. */
  188. public abstract void ignorableWhitespace (char ch[], int start, int length)
  189. throws SAXException;
  190. /**
  191. * Receive notification of a processing instruction.
  192. *
  193. * <p>The Parser will invoke this method once for each processing
  194. * instruction found: note that processing instructions may occur
  195. * before or after the main document element.</p>
  196. *
  197. * <p>A SAX parser should never report an XML declaration (XML 1.0,
  198. * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
  199. * using this method.</p>
  200. *
  201. * @param target The processing instruction target.
  202. * @param data The processing instruction data, or null if
  203. * none was supplied.
  204. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  205. * wrapping another exception.
  206. */
  207. public abstract void processingInstruction (String target, String data)
  208. throws SAXException;
  209. }
  210. // end of DocumentHandler.java