1. // SAX default handler base class.
  2. // No warranty; no copyright -- use this as you will.
  3. // $Id: HandlerBase.java,v 1.2 2001/08/01 06:43:17 tcng Exp $
  4. package org.xml.sax;
  5. /**
  6. * Default base class for handlers.
  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 class implements the default behaviour for four SAX1
  14. * interfaces: EntityResolver, DTDHandler, DocumentHandler,
  15. * and ErrorHandler. It is now obsolete, but is included in SAX2 to
  16. * support legacy SAX1 applications. SAX2 applications should use
  17. * the {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}
  18. * class instead.</p>
  19. *
  20. * <p>Application writers can extend this class when they need to
  21. * implement only part of an interface; parser writers can
  22. * instantiate this class to provide default handlers when the
  23. * application has not supplied its own.</p>
  24. *
  25. * <p>Note that the use of this class is optional.</p>
  26. *
  27. * @deprecated This class works with the deprecated
  28. * {@link org.xml.sax.DocumentHandler DocumentHandler}
  29. * interface. It has been replaced by the SAX2
  30. * {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}
  31. * class.
  32. * @since SAX 1.0
  33. * @author David Megginson,
  34. * <a href="mailto:sax@megginson.com">sax@megginson.com</a>
  35. * @version 2.0
  36. * @see org.xml.sax.EntityResolver
  37. * @see org.xml.sax.DTDHandler
  38. * @see org.xml.sax.DocumentHandler
  39. * @see org.xml.sax.ErrorHandler
  40. */
  41. public class HandlerBase
  42. implements EntityResolver, DTDHandler, DocumentHandler, ErrorHandler
  43. {
  44. ////////////////////////////////////////////////////////////////////
  45. // Default implementation of the EntityResolver interface.
  46. ////////////////////////////////////////////////////////////////////
  47. /**
  48. * Resolve an external entity.
  49. *
  50. * <p>Always return null, so that the parser will use the system
  51. * identifier provided in the XML document. This method implements
  52. * the SAX default behaviour: application writers can override it
  53. * in a subclass to do special translations such as catalog lookups
  54. * or URI redirection.</p>
  55. *
  56. * @param publicId The public identifer, or null if none is
  57. * available.
  58. * @param systemId The system identifier provided in the XML
  59. * document.
  60. * @return The new input source, or null to require the
  61. * default behaviour.
  62. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  63. * wrapping another exception.
  64. * @see org.xml.sax.EntityResolver#resolveEntity
  65. */
  66. public InputSource resolveEntity (String publicId, String systemId)
  67. throws SAXException
  68. {
  69. return null;
  70. }
  71. ////////////////////////////////////////////////////////////////////
  72. // Default implementation of DTDHandler interface.
  73. ////////////////////////////////////////////////////////////////////
  74. /**
  75. * Receive notification of a notation declaration.
  76. *
  77. * <p>By default, do nothing. Application writers may override this
  78. * method in a subclass if they wish to keep track of the notations
  79. * declared in a document.</p>
  80. *
  81. * @param name The notation name.
  82. * @param publicId The notation public identifier, or null if not
  83. * available.
  84. * @param systemId The notation system identifier.
  85. * @see org.xml.sax.DTDHandler#notationDecl
  86. */
  87. public void notationDecl (String name, String publicId, String systemId)
  88. {
  89. // no op
  90. }
  91. /**
  92. * Receive notification of an unparsed entity declaration.
  93. *
  94. * <p>By default, do nothing. Application writers may override this
  95. * method in a subclass to keep track of the unparsed entities
  96. * declared in a document.</p>
  97. *
  98. * @param name The entity name.
  99. * @param publicId The entity public identifier, or null if not
  100. * available.
  101. * @param systemId The entity system identifier.
  102. * @param notationName The name of the associated notation.
  103. * @see org.xml.sax.DTDHandler#unparsedEntityDecl
  104. */
  105. public void unparsedEntityDecl (String name, String publicId,
  106. String systemId, String notationName)
  107. {
  108. // no op
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. // Default implementation of DocumentHandler interface.
  112. ////////////////////////////////////////////////////////////////////
  113. /**
  114. * Receive a Locator object for document events.
  115. *
  116. * <p>By default, do nothing. Application writers may override this
  117. * method in a subclass if they wish to store the locator for use
  118. * with other document events.</p>
  119. *
  120. * @param locator A locator for all SAX document events.
  121. * @see org.xml.sax.DocumentHandler#setDocumentLocator
  122. * @see org.xml.sax.Locator
  123. */
  124. public void setDocumentLocator (Locator locator)
  125. {
  126. // no op
  127. }
  128. /**
  129. * Receive notification of the beginning of the document.
  130. *
  131. * <p>By default, do nothing. Application writers may override this
  132. * method in a subclass to take specific actions at the beginning
  133. * of a document (such as allocating the root node of a tree or
  134. * creating an output file).</p>
  135. *
  136. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  137. * wrapping another exception.
  138. * @see org.xml.sax.DocumentHandler#startDocument
  139. */
  140. public void startDocument ()
  141. throws SAXException
  142. {
  143. // no op
  144. }
  145. /**
  146. * Receive notification of the end of the document.
  147. *
  148. * <p>By default, do nothing. Application writers may override this
  149. * method in a subclass to take specific actions at the beginning
  150. * of a document (such as finalising a tree or closing an output
  151. * file).</p>
  152. *
  153. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  154. * wrapping another exception.
  155. * @see org.xml.sax.DocumentHandler#endDocument
  156. */
  157. public void endDocument ()
  158. throws SAXException
  159. {
  160. // no op
  161. }
  162. /**
  163. * Receive notification of the start of an element.
  164. *
  165. * <p>By default, do nothing. Application writers may override this
  166. * method in a subclass to take specific actions at the start of
  167. * each element (such as allocating a new tree node or writing
  168. * output to a file).</p>
  169. *
  170. * @param name The element type name.
  171. * @param attributes The specified or defaulted attributes.
  172. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  173. * wrapping another exception.
  174. * @see org.xml.sax.DocumentHandler#startElement
  175. */
  176. public void startElement (String name, AttributeList attributes)
  177. throws SAXException
  178. {
  179. // no op
  180. }
  181. /**
  182. * Receive notification of the end of an element.
  183. *
  184. * <p>By default, do nothing. Application writers may override this
  185. * method in a subclass to take specific actions at the end of
  186. * each element (such as finalising a tree node or writing
  187. * output to a file).</p>
  188. *
  189. * @param name The element type name.
  190. * @param attributes The specified or defaulted attributes.
  191. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  192. * wrapping another exception.
  193. * @see org.xml.sax.DocumentHandler#endElement
  194. */
  195. public void endElement (String name)
  196. throws SAXException
  197. {
  198. // no op
  199. }
  200. /**
  201. * Receive notification of character data inside an element.
  202. *
  203. * <p>By default, do nothing. Application writers may override this
  204. * method to take specific actions for each chunk of character data
  205. * (such as adding the data to a node or buffer, or printing it to
  206. * a file).</p>
  207. *
  208. * @param ch The characters.
  209. * @param start The start position in the character array.
  210. * @param length The number of characters to use from the
  211. * character array.
  212. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  213. * wrapping another exception.
  214. * @see org.xml.sax.DocumentHandler#characters
  215. */
  216. public void characters (char ch[], int start, int length)
  217. throws SAXException
  218. {
  219. // no op
  220. }
  221. /**
  222. * Receive notification of ignorable whitespace in element content.
  223. *
  224. * <p>By default, do nothing. Application writers may override this
  225. * method to take specific actions for each chunk of ignorable
  226. * whitespace (such as adding data to a node or buffer, or printing
  227. * it to a file).</p>
  228. *
  229. * @param ch The whitespace characters.
  230. * @param start The start position in the character array.
  231. * @param length The number of characters to use from the
  232. * character array.
  233. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  234. * wrapping another exception.
  235. * @see org.xml.sax.DocumentHandler#ignorableWhitespace
  236. */
  237. public void ignorableWhitespace (char ch[], int start, int length)
  238. throws SAXException
  239. {
  240. // no op
  241. }
  242. /**
  243. * Receive notification of a processing instruction.
  244. *
  245. * <p>By default, do nothing. Application writers may override this
  246. * method in a subclass to take specific actions for each
  247. * processing instruction, such as setting status variables or
  248. * invoking other methods.</p>
  249. *
  250. * @param target The processing instruction target.
  251. * @param data The processing instruction data, or null if
  252. * none is supplied.
  253. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  254. * wrapping another exception.
  255. * @see org.xml.sax.DocumentHandler#processingInstruction
  256. */
  257. public void processingInstruction (String target, String data)
  258. throws SAXException
  259. {
  260. // no op
  261. }
  262. ////////////////////////////////////////////////////////////////////
  263. // Default implementation of the ErrorHandler interface.
  264. ////////////////////////////////////////////////////////////////////
  265. /**
  266. * Receive notification of a parser warning.
  267. *
  268. * <p>The default implementation does nothing. Application writers
  269. * may override this method in a subclass to take specific actions
  270. * for each warning, such as inserting the message in a log file or
  271. * printing it to the console.</p>
  272. *
  273. * @param e The warning information encoded as an exception.
  274. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  275. * wrapping another exception.
  276. * @see org.xml.sax.ErrorHandler#warning
  277. * @see org.xml.sax.SAXParseException
  278. */
  279. public void warning (SAXParseException e)
  280. throws SAXException
  281. {
  282. // no op
  283. }
  284. /**
  285. * Receive notification of a recoverable parser error.
  286. *
  287. * <p>The default implementation does nothing. Application writers
  288. * may override this method in a subclass to take specific actions
  289. * for each error, such as inserting the message in a log file or
  290. * printing it to the console.</p>
  291. *
  292. * @param e The warning information encoded as an exception.
  293. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  294. * wrapping another exception.
  295. * @see org.xml.sax.ErrorHandler#warning
  296. * @see org.xml.sax.SAXParseException
  297. */
  298. public void error (SAXParseException e)
  299. throws SAXException
  300. {
  301. // no op
  302. }
  303. /**
  304. * Report a fatal XML parsing error.
  305. *
  306. * <p>The default implementation throws a SAXParseException.
  307. * Application writers may override this method in a subclass if
  308. * they need to take specific actions for each fatal error (such as
  309. * collecting all of the errors into a single report): in any case,
  310. * the application must stop all regular processing when this
  311. * method is invoked, since the document is no longer reliable, and
  312. * the parser may no longer report parsing events.</p>
  313. *
  314. * @param e The error information encoded as an exception.
  315. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  316. * wrapping another exception.
  317. * @see org.xml.sax.ErrorHandler#fatalError
  318. * @see org.xml.sax.SAXParseException
  319. */
  320. public void fatalError (SAXParseException e)
  321. throws SAXException
  322. {
  323. throw e;
  324. }
  325. }
  326. // end of HandlerBase.java