1. // DefaultHandler.java - default implementation of the core handlers.
  2. // Written by David Megginson, sax@megginson.com
  3. // NO WARRANTY! This class is in the public domain.
  4. // $Id: DefaultHandler.java,v 1.1.2.1 2001/11/15 19:46:10 edwingo Exp $
  5. package org.xml.sax.helpers;
  6. import java.io.IOException;
  7. import org.xml.sax.InputSource;
  8. import org.xml.sax.Locator;
  9. import org.xml.sax.Attributes;
  10. import org.xml.sax.EntityResolver;
  11. import org.xml.sax.DTDHandler;
  12. import org.xml.sax.ContentHandler;
  13. import org.xml.sax.ErrorHandler;
  14. import org.xml.sax.SAXException;
  15. import org.xml.sax.SAXParseException;
  16. /**
  17. * Default base class for SAX2 event handlers.
  18. *
  19. * <blockquote>
  20. * <em>This module, both source code and documentation, is in the
  21. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  22. * </blockquote>
  23. *
  24. * <p>This class is available as a convenience base class for SAX2
  25. * applications: it provides default implementations for all of the
  26. * callbacks in the four core SAX2 handler classes:</p>
  27. *
  28. * <ul>
  29. * <li>{@link org.xml.sax.EntityResolver EntityResolver}</li>
  30. * <li>{@link org.xml.sax.DTDHandler DTDHandler}</li>
  31. * <li>{@link org.xml.sax.ContentHandler ContentHandler}</li>
  32. * <li>{@link org.xml.sax.ErrorHandler ErrorHandler}</li>
  33. * </ul>
  34. *
  35. * <p>Application writers can extend this class when they need to
  36. * implement only part of an interface; parser writers can
  37. * instantiate this class to provide default handlers when the
  38. * application has not supplied its own.</p>
  39. *
  40. * <p>This class replaces the deprecated SAX1
  41. * {@link org.xml.sax.HandlerBase HandlerBase} class.</p>
  42. *
  43. * @since SAX 2.0
  44. * @author David Megginson,
  45. * <a href="mailto:sax@megginson.com">sax@megginson.com</a>
  46. * @version 2.0r2pre w/ JAXP 1.1 signatures
  47. * @see org.xml.sax.EntityResolver
  48. * @see org.xml.sax.DTDHandler
  49. * @see org.xml.sax.ContentHandler
  50. * @see org.xml.sax.ErrorHandler
  51. */
  52. public class DefaultHandler
  53. implements EntityResolver, DTDHandler, ContentHandler, ErrorHandler
  54. {
  55. ////////////////////////////////////////////////////////////////////
  56. // Default implementation of the EntityResolver interface.
  57. ////////////////////////////////////////////////////////////////////
  58. /**
  59. * Resolve an external entity.
  60. *
  61. * <p>Always return null, so that the parser will use the system
  62. * identifier provided in the XML document. This method implements
  63. * the SAX default behaviour: application writers can override it
  64. * in a subclass to do special translations such as catalog lookups
  65. * or URI redirection.</p>
  66. *
  67. * @param publicId The public identifer, or null if none is
  68. * available.
  69. * @param systemId The system identifier provided in the XML
  70. * document.
  71. * @return The new input source, or null to require the
  72. * default behaviour.
  73. * @exception java.io.IOException If there is an error setting
  74. * up the new input source.
  75. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  76. * wrapping another exception.
  77. * @see org.xml.sax.EntityResolver#resolveEntity
  78. */
  79. public InputSource resolveEntity (String publicId, String systemId)
  80. // throws IOException, SAXException
  81. throws SAXException
  82. {
  83. return null;
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Default implementation of DTDHandler interface.
  87. ////////////////////////////////////////////////////////////////////
  88. /**
  89. * Receive notification of a notation declaration.
  90. *
  91. * <p>By default, do nothing. Application writers may override this
  92. * method in a subclass if they wish to keep track of the notations
  93. * declared in a document.</p>
  94. *
  95. * @param name The notation name.
  96. * @param publicId The notation public identifier, or null if not
  97. * available.
  98. * @param systemId The notation system identifier.
  99. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  100. * wrapping another exception.
  101. * @see org.xml.sax.DTDHandler#notationDecl
  102. */
  103. public void notationDecl (String name, String publicId, String systemId)
  104. throws SAXException
  105. {
  106. // no op
  107. }
  108. /**
  109. * Receive notification of an unparsed entity declaration.
  110. *
  111. * <p>By default, do nothing. Application writers may override this
  112. * method in a subclass to keep track of the unparsed entities
  113. * declared in a document.</p>
  114. *
  115. * @param name The entity name.
  116. * @param publicId The entity public identifier, or null if not
  117. * available.
  118. * @param systemId The entity system identifier.
  119. * @param notationName The name of the associated notation.
  120. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  121. * wrapping another exception.
  122. * @see org.xml.sax.DTDHandler#unparsedEntityDecl
  123. */
  124. public void unparsedEntityDecl (String name, String publicId,
  125. String systemId, String notationName)
  126. throws SAXException
  127. {
  128. // no op
  129. }
  130. ////////////////////////////////////////////////////////////////////
  131. // Default implementation of ContentHandler interface.
  132. ////////////////////////////////////////////////////////////////////
  133. /**
  134. * Receive a Locator object for document events.
  135. *
  136. * <p>By default, do nothing. Application writers may override this
  137. * method in a subclass if they wish to store the locator for use
  138. * with other document events.</p>
  139. *
  140. * @param locator A locator for all SAX document events.
  141. * @see org.xml.sax.ContentHandler#setDocumentLocator
  142. * @see org.xml.sax.Locator
  143. */
  144. public void setDocumentLocator (Locator locator)
  145. {
  146. // no op
  147. }
  148. /**
  149. * Receive notification of the beginning of the document.
  150. *
  151. * <p>By default, do nothing. Application writers may override this
  152. * method in a subclass to take specific actions at the beginning
  153. * of a document (such as allocating the root node of a tree or
  154. * creating an output file).</p>
  155. *
  156. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  157. * wrapping another exception.
  158. * @see org.xml.sax.ContentHandler#startDocument
  159. */
  160. public void startDocument ()
  161. throws SAXException
  162. {
  163. // no op
  164. }
  165. /**
  166. * Receive notification of the end of the document.
  167. *
  168. * <p>By default, do nothing. Application writers may override this
  169. * method in a subclass to take specific actions at the end
  170. * of a document (such as finalising a tree or closing an output
  171. * file).</p>
  172. *
  173. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  174. * wrapping another exception.
  175. * @see org.xml.sax.ContentHandler#endDocument
  176. */
  177. public void endDocument ()
  178. throws SAXException
  179. {
  180. // no op
  181. }
  182. /**
  183. * Receive notification of the start of a Namespace mapping.
  184. *
  185. * <p>By default, do nothing. Application writers may override this
  186. * method in a subclass to take specific actions at the start of
  187. * each Namespace prefix scope (such as storing the prefix mapping).</p>
  188. *
  189. * @param prefix The Namespace prefix being declared.
  190. * @param uri The Namespace URI mapped to the prefix.
  191. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  192. * wrapping another exception.
  193. * @see org.xml.sax.ContentHandler#startPrefixMapping
  194. */
  195. public void startPrefixMapping (String prefix, String uri)
  196. throws SAXException
  197. {
  198. // no op
  199. }
  200. /**
  201. * Receive notification of the end of a Namespace mapping.
  202. *
  203. * <p>By default, do nothing. Application writers may override this
  204. * method in a subclass to take specific actions at the end of
  205. * each prefix mapping.</p>
  206. *
  207. * @param prefix The Namespace prefix being declared.
  208. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  209. * wrapping another exception.
  210. * @see org.xml.sax.ContentHandler#endPrefixMapping
  211. */
  212. public void endPrefixMapping (String prefix)
  213. throws SAXException
  214. {
  215. // no op
  216. }
  217. /**
  218. * Receive notification of the start of an element.
  219. *
  220. * <p>By default, do nothing. Application writers may override this
  221. * method in a subclass to take specific actions at the start of
  222. * each element (such as allocating a new tree node or writing
  223. * output to a file).</p>
  224. *
  225. * @param name The element type name.
  226. * @param attributes The specified or defaulted attributes.
  227. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  228. * wrapping another exception.
  229. * @see org.xml.sax.ContentHandler#startElement
  230. */
  231. public void startElement (String uri, String localName,
  232. String qName, Attributes attributes)
  233. throws SAXException
  234. {
  235. // no op
  236. }
  237. /**
  238. * Receive notification of the end of an element.
  239. *
  240. * <p>By default, do nothing. Application writers may override this
  241. * method in a subclass to take specific actions at the end of
  242. * each element (such as finalising a tree node or writing
  243. * output to a file).</p>
  244. *
  245. * @param name The element type name.
  246. * @param attributes The specified or defaulted attributes.
  247. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  248. * wrapping another exception.
  249. * @see org.xml.sax.ContentHandler#endElement
  250. */
  251. public void endElement (String uri, String localName, String qName)
  252. throws SAXException
  253. {
  254. // no op
  255. }
  256. /**
  257. * Receive notification of character data inside an element.
  258. *
  259. * <p>By default, do nothing. Application writers may override this
  260. * method to take specific actions for each chunk of character data
  261. * (such as adding the data to a node or buffer, or printing it to
  262. * a file).</p>
  263. *
  264. * @param ch The characters.
  265. * @param start The start position in the character array.
  266. * @param length The number of characters to use from the
  267. * character array.
  268. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  269. * wrapping another exception.
  270. * @see org.xml.sax.ContentHandler#characters
  271. */
  272. public void characters (char ch[], int start, int length)
  273. throws SAXException
  274. {
  275. // no op
  276. }
  277. /**
  278. * Receive notification of ignorable whitespace in element content.
  279. *
  280. * <p>By default, do nothing. Application writers may override this
  281. * method to take specific actions for each chunk of ignorable
  282. * whitespace (such as adding data to a node or buffer, or printing
  283. * it to a file).</p>
  284. *
  285. * @param ch The whitespace characters.
  286. * @param start The start position in the character array.
  287. * @param length The number of characters to use from the
  288. * character array.
  289. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  290. * wrapping another exception.
  291. * @see org.xml.sax.ContentHandler#ignorableWhitespace
  292. */
  293. public void ignorableWhitespace (char ch[], int start, int length)
  294. throws SAXException
  295. {
  296. // no op
  297. }
  298. /**
  299. * Receive notification of a processing instruction.
  300. *
  301. * <p>By default, do nothing. Application writers may override this
  302. * method in a subclass to take specific actions for each
  303. * processing instruction, such as setting status variables or
  304. * invoking other methods.</p>
  305. *
  306. * @param target The processing instruction target.
  307. * @param data The processing instruction data, or null if
  308. * none is supplied.
  309. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  310. * wrapping another exception.
  311. * @see org.xml.sax.ContentHandler#processingInstruction
  312. */
  313. public void processingInstruction (String target, String data)
  314. throws SAXException
  315. {
  316. // no op
  317. }
  318. /**
  319. * Receive notification of a skipped entity.
  320. *
  321. * <p>By default, do nothing. Application writers may override this
  322. * method in a subclass to take specific actions for each
  323. * processing instruction, such as setting status variables or
  324. * invoking other methods.</p>
  325. *
  326. * @param name The name of the skipped entity.
  327. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  328. * wrapping another exception.
  329. * @see org.xml.sax.ContentHandler#processingInstruction
  330. */
  331. public void skippedEntity (String name)
  332. throws SAXException
  333. {
  334. // no op
  335. }
  336. ////////////////////////////////////////////////////////////////////
  337. // Default implementation of the ErrorHandler interface.
  338. ////////////////////////////////////////////////////////////////////
  339. /**
  340. * Receive notification of a parser warning.
  341. *
  342. * <p>The default implementation does nothing. Application writers
  343. * may override this method in a subclass to take specific actions
  344. * for each warning, such as inserting the message in a log file or
  345. * printing it to the console.</p>
  346. *
  347. * @param e The warning information encoded as an exception.
  348. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  349. * wrapping another exception.
  350. * @see org.xml.sax.ErrorHandler#warning
  351. * @see org.xml.sax.SAXParseException
  352. */
  353. public void warning (SAXParseException e)
  354. throws SAXException
  355. {
  356. // no op
  357. }
  358. /**
  359. * Receive notification of a recoverable parser error.
  360. *
  361. * <p>The default implementation does nothing. Application writers
  362. * may override this method in a subclass to take specific actions
  363. * for each error, such as inserting the message in a log file or
  364. * printing it to the console.</p>
  365. *
  366. * @param e The warning information encoded as an exception.
  367. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  368. * wrapping another exception.
  369. * @see org.xml.sax.ErrorHandler#warning
  370. * @see org.xml.sax.SAXParseException
  371. */
  372. public void error (SAXParseException e)
  373. throws SAXException
  374. {
  375. // no op
  376. }
  377. /**
  378. * Report a fatal XML parsing error.
  379. *
  380. * <p>The default implementation throws a SAXParseException.
  381. * Application writers may override this method in a subclass if
  382. * they need to take specific actions for each fatal error (such as
  383. * collecting all of the errors into a single report): in any case,
  384. * the application must stop all regular processing when this
  385. * method is invoked, since the document is no longer reliable, and
  386. * the parser may no longer report parsing events.</p>
  387. *
  388. * @param e The error information encoded as an exception.
  389. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  390. * wrapping another exception.
  391. * @see org.xml.sax.ErrorHandler#fatalError
  392. * @see org.xml.sax.SAXParseException
  393. */
  394. public void fatalError (SAXParseException e)
  395. throws SAXException
  396. {
  397. throw e;
  398. }
  399. }
  400. // end of DefaultHandler.java