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