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