1. // LexicalHandler.java - optional handler for lexical parse events.
  2. // http://www.saxproject.org
  3. // Public Domain: no warranty.
  4. // $Id: LexicalHandler.java,v 1.1.24.1 2004/05/01 08:34:43 jsuttor Exp $
  5. package org.xml.sax.ext;
  6. import org.xml.sax.SAXException;
  7. /**
  8. * SAX2 extension handler for lexical events.
  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. * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  14. * for further information.
  15. * </blockquote>
  16. *
  17. * <p>This is an optional extension handler for SAX2 to provide
  18. * lexical information about an XML document, such as comments
  19. * and CDATA section boundaries.
  20. * XML readers are not required to recognize this handler, and it
  21. * is not part of core-only SAX2 distributions.</p>
  22. *
  23. * <p>The events in the lexical handler apply to the entire document,
  24. * not just to the document element, and all lexical handler events
  25. * must appear between the content handler's startDocument and
  26. * endDocument events.</p>
  27. *
  28. * <p>To set the LexicalHandler for an XML reader, use the
  29. * {@link org.xml.sax.XMLReader#setProperty setProperty} method
  30. * with the property name
  31. * <code>http://xml.org/sax/properties/lexical-handler</code>
  32. * and an object implementing this interface (or null) as the value.
  33. * If the reader does not report lexical events, it will throw a
  34. * {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException}
  35. * when you attempt to register the handler.</p>
  36. *
  37. * @since SAX 2.0 (extensions 1.0)
  38. * @author David Megginson
  39. * @version 2.0.1 (sax2r2)
  40. */
  41. public interface LexicalHandler
  42. {
  43. /**
  44. * Report the start of DTD declarations, if any.
  45. *
  46. * <p>This method is intended to report the beginning of the
  47. * DOCTYPE declaration; if the document has no DOCTYPE declaration,
  48. * this method will not be invoked.</p>
  49. *
  50. * <p>All declarations reported through
  51. * {@link org.xml.sax.DTDHandler DTDHandler} or
  52. * {@link org.xml.sax.ext.DeclHandler DeclHandler} events must appear
  53. * between the startDTD and {@link #endDTD endDTD} events.
  54. * Declarations are assumed to belong to the internal DTD subset
  55. * unless they appear between {@link #startEntity startEntity}
  56. * and {@link #endEntity endEntity} events. Comments and
  57. * processing instructions from the DTD should also be reported
  58. * between the startDTD and endDTD events, in their original
  59. * order of (logical) occurrence; they are not required to
  60. * appear in their correct locations relative to DTDHandler
  61. * or DeclHandler events, however.</p>
  62. *
  63. * <p>Note that the start/endDTD events will appear within
  64. * the start/endDocument events from ContentHandler and
  65. * before the first
  66. * {@link org.xml.sax.ContentHandler#startElement startElement}
  67. * event.</p>
  68. *
  69. * @param name The document type name.
  70. * @param publicId The declared public identifier for the
  71. * external DTD subset, or null if none was declared.
  72. * @param systemId The declared system identifier for the
  73. * external DTD subset, or null if none was declared.
  74. * (Note that this is not resolved against the document
  75. * base URI.)
  76. * @exception SAXException The application may raise an
  77. * exception.
  78. * @see #endDTD
  79. * @see #startEntity
  80. */
  81. public abstract void startDTD (String name, String publicId,
  82. String systemId)
  83. throws SAXException;
  84. /**
  85. * Report the end of DTD declarations.
  86. *
  87. * <p>This method is intended to report the end of the
  88. * DOCTYPE declaration; if the document has no DOCTYPE declaration,
  89. * this method will not be invoked.</p>
  90. *
  91. * @exception SAXException The application may raise an exception.
  92. * @see #startDTD
  93. */
  94. public abstract void endDTD ()
  95. throws SAXException;
  96. /**
  97. * Report the beginning of some internal and external XML entities.
  98. *
  99. * <p>The reporting of parameter entities (including
  100. * the external DTD subset) is optional, and SAX2 drivers that
  101. * report LexicalHandler events may not implement it; you can use the
  102. * <code
  103. * >http://xml.org/sax/features/lexical-handler/parameter-entities</code>
  104. * feature to query or control the reporting of parameter entities.</p>
  105. *
  106. * <p>General entities are reported with their regular names,
  107. * parameter entities have '%' prepended to their names, and
  108. * the external DTD subset has the pseudo-entity name "[dtd]".</p>
  109. *
  110. * <p>When a SAX2 driver is providing these events, all other
  111. * events must be properly nested within start/end entity
  112. * events. There is no additional requirement that events from
  113. * {@link org.xml.sax.ext.DeclHandler DeclHandler} or
  114. * {@link org.xml.sax.DTDHandler DTDHandler} be properly ordered.</p>
  115. *
  116. * <p>Note that skipped entities will be reported through the
  117. * {@link org.xml.sax.ContentHandler#skippedEntity skippedEntity}
  118. * event, which is part of the ContentHandler interface.</p>
  119. *
  120. * <p>Because of the streaming event model that SAX uses, some
  121. * entity boundaries cannot be reported under any
  122. * circumstances:</p>
  123. *
  124. * <ul>
  125. * <li>general entities within attribute values</li>
  126. * <li>parameter entities within declarations</li>
  127. * </ul>
  128. *
  129. * <p>These will be silently expanded, with no indication of where
  130. * the original entity boundaries were.</p>
  131. *
  132. * <p>Note also that the boundaries of character references (which
  133. * are not really entities anyway) are not reported.</p>
  134. *
  135. * <p>All start/endEntity events must be properly nested.
  136. *
  137. * @param name The name of the entity. If it is a parameter
  138. * entity, the name will begin with '%', and if it is the
  139. * external DTD subset, it will be "[dtd]".
  140. * @exception SAXException The application may raise an exception.
  141. * @see #endEntity
  142. * @see org.xml.sax.ext.DeclHandler#internalEntityDecl
  143. * @see org.xml.sax.ext.DeclHandler#externalEntityDecl
  144. */
  145. public abstract void startEntity (String name)
  146. throws SAXException;
  147. /**
  148. * Report the end of an entity.
  149. *
  150. * @param name The name of the entity that is ending.
  151. * @exception SAXException The application may raise an exception.
  152. * @see #startEntity
  153. */
  154. public abstract void endEntity (String name)
  155. throws SAXException;
  156. /**
  157. * Report the start of a CDATA section.
  158. *
  159. * <p>The contents of the CDATA section will be reported through
  160. * the regular {@link org.xml.sax.ContentHandler#characters
  161. * characters} event; this event is intended only to report
  162. * the boundary.</p>
  163. *
  164. * @exception SAXException The application may raise an exception.
  165. * @see #endCDATA
  166. */
  167. public abstract void startCDATA ()
  168. throws SAXException;
  169. /**
  170. * Report the end of a CDATA section.
  171. *
  172. * @exception SAXException The application may raise an exception.
  173. * @see #startCDATA
  174. */
  175. public abstract void endCDATA ()
  176. throws SAXException;
  177. /**
  178. * Report an XML comment anywhere in the document.
  179. *
  180. * <p>This callback will be used for comments inside or outside the
  181. * document element, including comments in the external DTD
  182. * subset (if read). Comments in the DTD must be properly
  183. * nested inside start/endDTD and start/endEntity events (if
  184. * used).</p>
  185. *
  186. * @param ch An array holding the characters in the comment.
  187. * @param start The starting position in the array.
  188. * @param length The number of characters to use from the array.
  189. * @exception SAXException The application may raise an exception.
  190. */
  191. public abstract void comment (char ch[], int start, int length)
  192. throws SAXException;
  193. }
  194. // end of LexicalHandler.java