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