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