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