View Javadoc

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   
5   // $Id$
6   
7   package org.xml.sax.helpers;
8   
9   import org.xml.sax.Attributes;
10  import org.xml.sax.InputSource;
11  import org.xml.sax.Locator;
12  import org.xml.sax.SAXException;
13  import org.xml.sax.SAXParseException;
14  
15  
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.0
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  
54  	public DefaultHandler()	{
55  		
56  	}
57      /***
58       * Resolve an external entity.
59       *
60       * <p>Always return null, so that the parser will use the system
61       * identifier provided in the XML document.  This method implements
62       * the SAX default behaviour: application writers can override it
63       * in a subclass to do special translations such as catalog lookups
64       * or URI redirection.</p>
65       *
66       * @param publicId The public identifer, or null if none is
67       *                 available.
68       * @param systemId The system identifier provided in the XML 
69       *                 document.
70       * @return The new input source, or null to require the
71       *         default behaviour.
72       * @exception org.xml.sax.SAXException Any SAX exception, possibly
73       *            wrapping another exception.
74       * @see org.xml.sax.EntityResolver#resolveEntity
75       */
76      public InputSource resolveEntity (String publicId, String systemId)
77  	throws SAXException
78      {
79  	return null;
80      }
81      
82      /***
83       * Receive notification of a notation declaration.
84       *
85       * <p>By default, do nothing.  Application writers may override this
86       * method in a subclass if they wish to keep track of the notations
87       * declared in a document.</p>
88       *
89       * @param name The notation name.
90       * @param publicId The notation public identifier, or null if not
91       *                 available.
92       * @param systemId The notation system identifier.
93       * @exception org.xml.sax.SAXException Any SAX exception, possibly
94       *            wrapping another exception.
95       * @see org.xml.sax.DTDHandler#notationDecl
96       */
97      public void notationDecl (String name, String publicId, String systemId)
98  	throws SAXException
99      {
100 	// no op
101     }
102     
103     
104     /***
105      * Receive notification of an unparsed entity declaration.
106      *
107      * <p>By default, do nothing.  Application writers may override this
108      * method in a subclass to keep track of the unparsed entities
109      * declared in a document.</p>
110      *
111      * @param name The entity name.
112      * @param publicId The entity public identifier, or null if not
113      *                 available.
114      * @param systemId The entity system identifier.
115      * @param notationName The name of the associated notation.
116      * @exception org.xml.sax.SAXException Any SAX exception, possibly
117      *            wrapping another exception.
118      * @see org.xml.sax.DTDHandler#unparsedEntityDecl
119      */
120     public void unparsedEntityDecl (String name, String publicId,
121 				    String systemId, String notationName)
122 	throws SAXException
123     {
124 	// no op
125     }
126     
127     /***
128      * Receive a Locator object for document events.
129      *
130      * <p>By default, do nothing.  Application writers may override this
131      * method in a subclass if they wish to store the locator for use
132      * with other document events.</p>
133      *
134      * @param locator A locator for all SAX document events.
135      * @see org.xml.sax.ContentHandler#setDocumentLocator
136      * @see org.xml.sax.Locator
137      */
138     public void setDocumentLocator (Locator locator)
139     {
140 	// no op
141     }
142     
143     
144     /***
145      * Receive notification of the beginning of the document.
146      *
147      * <p>By default, do nothing.  Application writers may override this
148      * method in a subclass to take specific actions at the beginning
149      * of a document (such as allocating the root node of a tree or
150      * creating an output file).</p>
151      *
152      * @exception org.xml.sax.SAXException Any SAX exception, possibly
153      *            wrapping another exception.
154      * @see org.xml.sax.ContentHandler#startDocument
155      */
156     public void startDocument ()
157 	throws SAXException
158     {
159 	// no op
160     }
161     
162     
163     /***
164      * Receive notification of the end of the document.
165      *
166      * <p>By default, do nothing.  Application writers may override this
167      * method in a subclass to take specific actions at the end
168      * of a document (such as finalising a tree or closing an output
169      * file).</p>
170      *
171      * @exception org.xml.sax.SAXException Any SAX exception, possibly
172      *            wrapping another exception.
173      * @see org.xml.sax.ContentHandler#endDocument
174      */
175     public void endDocument ()
176 	throws SAXException
177     {
178 	// no op
179     }
180 
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 
202     /***
203      * Receive notification of the end of a Namespace mapping.
204      *
205      * <p>By default, do nothing.  Application writers may override this
206      * method in a subclass to take specific actions at the end of
207      * each prefix mapping.</p>
208      *
209      * @param prefix The Namespace prefix being declared.
210      * @exception org.xml.sax.SAXException Any SAX exception, possibly
211      *            wrapping another exception.
212      * @see org.xml.sax.ContentHandler#endPrefixMapping
213      */
214     public void endPrefixMapping (String prefix)
215 	throws SAXException
216     {
217 	// no op
218     }
219     
220     
221     /***
222      * Receive notification of the start of an element.
223      *
224      * <p>By default, do nothing.  Application writers may override this
225      * method in a subclass to take specific actions at the start of
226      * each element (such as allocating a new tree node or writing
227      * output to a file).</p>
228      *
229      * @param name The element type name.
230      * @param attributes The specified or defaulted attributes.
231      * @exception org.xml.sax.SAXException Any SAX exception, possibly
232      *            wrapping another exception.
233      * @see org.xml.sax.ContentHandler#startElement
234      */
235     public void startElement (String uri, String localName,
236 			      String qName, Attributes attributes)
237 	throws SAXException
238     {
239 	// no op
240     }
241     
242     
243     /***
244      * Receive notification of the end of an element.
245      *
246      * <p>By default, do nothing.  Application writers may override this
247      * method in a subclass to take specific actions at the end of
248      * each element (such as finalising a tree node or writing
249      * output to a file).</p>
250      *
251      * @param name The element type name.
252      * @param attributes The specified or defaulted attributes.
253      * @exception org.xml.sax.SAXException Any SAX exception, possibly
254      *            wrapping another exception.
255      * @see org.xml.sax.ContentHandler#endElement
256      */
257     public void endElement (String uri, String localName, String qName)
258 	throws SAXException
259     {
260 	// no op
261     }
262     
263     
264     /***
265      * Receive notification of character data inside an element.
266      *
267      * <p>By default, do nothing.  Application writers may override this
268      * method to take specific actions for each chunk of character data
269      * (such as adding the data to a node or buffer, or printing it to
270      * a file).</p>
271      *
272      * @param ch The characters.
273      * @param start The start position in the character array.
274      * @param length The number of characters to use from the
275      *               character array.
276      * @exception org.xml.sax.SAXException Any SAX exception, possibly
277      *            wrapping another exception.
278      * @see org.xml.sax.ContentHandler#characters
279      */
280     public void characters (char ch[], int start, int length)
281 	throws SAXException
282     {
283 	// no op
284     }
285     
286     
287     /***
288      * Receive notification of ignorable whitespace in element content.
289      *
290      * <p>By default, do nothing.  Application writers may override this
291      * method to take specific actions for each chunk of ignorable
292      * whitespace (such as adding data to a node or buffer, or printing
293      * it to a file).</p>
294      *
295      * @param ch The whitespace characters.
296      * @param start The start position in the character array.
297      * @param length The number of characters to use from the
298      *               character array.
299      * @exception org.xml.sax.SAXException Any SAX exception, possibly
300      *            wrapping another exception.
301      * @see org.xml.sax.ContentHandler#ignorableWhitespace
302      */
303     public void ignorableWhitespace (char ch[], int start, int length)
304 	throws SAXException
305     {
306 	// no op
307     }
308     
309     
310     /***
311      * Receive notification of a processing instruction.
312      *
313      * <p>By default, do nothing.  Application writers may override this
314      * method in a subclass to take specific actions for each
315      * processing instruction, such as setting status variables or
316      * invoking other methods.</p>
317      *
318      * @param target The processing instruction target.
319      * @param data The processing instruction data, or null if
320      *             none is supplied.
321      * @exception org.xml.sax.SAXException Any SAX exception, possibly
322      *            wrapping another exception.
323      * @see org.xml.sax.ContentHandler#processingInstruction
324      */
325     public void processingInstruction (String target, String data)
326 	throws SAXException
327     {
328 	// no op
329     }
330 
331 
332     /***
333      * Receive notification of a skipped entity.
334      *
335      * <p>By default, do nothing.  Application writers may override this
336      * method in a subclass to take specific actions for each
337      * processing instruction, such as setting status variables or
338      * invoking other methods.</p>
339      *
340      * @param name The name of the skipped entity.
341      * @exception org.xml.sax.SAXException Any SAX exception, possibly
342      *            wrapping another exception.
343      * @see org.xml.sax.ContentHandler#processingInstruction
344      */
345     public void skippedEntity (String name)
346 	throws SAXException
347     {
348 	// no op
349     }
350     
351     /***
352      * Receive notification of a parser warning.
353      *
354      * <p>The default implementation does nothing.  Application writers
355      * may override this method in a subclass to take specific actions
356      * for each warning, such as inserting the message in a log file or
357      * printing it to the console.</p>
358      *
359      * @param e The warning information encoded as an exception.
360      * @exception org.xml.sax.SAXException Any SAX exception, possibly
361      *            wrapping another exception.
362      * @see org.xml.sax.ErrorHandler#warning
363      * @see org.xml.sax.SAXParseException
364      */
365     public void warning (SAXParseException e)
366 	throws SAXException
367     {
368 	// no op
369     }
370     
371     
372     /***
373      * Receive notification of a recoverable parser error.
374      *
375      * <p>The default implementation does nothing.  Application writers
376      * may override this method in a subclass to take specific actions
377      * for each error, such as inserting the message in a log file or
378      * printing it to the console.</p>
379      *
380      * @param e The warning information encoded as an exception.
381      * @exception org.xml.sax.SAXException Any SAX exception, possibly
382      *            wrapping another exception.
383      * @see org.xml.sax.ErrorHandler#warning
384      * @see org.xml.sax.SAXParseException
385      */
386     public void error (SAXParseException e)
387 	throws SAXException
388     {
389 	// no op
390     }
391     
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 }