001: // DefaultHandler.java - default implementation of the core handlers.
002: // http://www.saxproject.org
003: // Written by David Megginson
004: // NO WARRANTY! This class is in the public domain.
005:
006: // $Id: DefaultHandler.java,v 1.1.1.1 2002/05/03 23:29:42 yuvalo Exp $
007:
008: package org.xml.sax.helpers;
009:
010: import java.io.IOException;
011:
012: import org.xml.sax.InputSource;
013: import org.xml.sax.Locator;
014: import org.xml.sax.Attributes;
015: import org.xml.sax.EntityResolver;
016: import org.xml.sax.DTDHandler;
017: import org.xml.sax.ContentHandler;
018: import org.xml.sax.ErrorHandler;
019: import org.xml.sax.SAXException;
020: import org.xml.sax.SAXParseException;
021:
022: /**
023: * Default base class for SAX2 event handlers.
024: *
025: * <blockquote>
026: * <em>This module, both source code and documentation, is in the
027: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
028: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
029: * for further information.
030: * </blockquote>
031: *
032: * <p>This class is available as a convenience base class for SAX2
033: * applications: it provides default implementations for all of the
034: * callbacks in the four core SAX2 handler classes:</p>
035: *
036: * <ul>
037: * <li>{@link org.xml.sax.EntityResolver EntityResolver}</li>
038: * <li>{@link org.xml.sax.DTDHandler DTDHandler}</li>
039: * <li>{@link org.xml.sax.ContentHandler ContentHandler}</li>
040: * <li>{@link org.xml.sax.ErrorHandler ErrorHandler}</li>
041: * </ul>
042: *
043: * <p>Application writers can extend this class when they need to
044: * implement only part of an interface; parser writers can
045: * instantiate this class to provide default handlers when the
046: * application has not supplied its own.</p>
047: *
048: * <p>This class replaces the deprecated SAX1
049: * {@link org.xml.sax.HandlerBase HandlerBase} class.</p>
050: *
051: * @since SAX 2.0
052: * @author David Megginson,
053: * @version 2.0.1 (sax2r2)
054: * @see org.xml.sax.EntityResolver
055: * @see org.xml.sax.DTDHandler
056: * @see org.xml.sax.ContentHandler
057: * @see org.xml.sax.ErrorHandler
058: */
059: public class DefaultHandler implements EntityResolver, DTDHandler,
060: ContentHandler, ErrorHandler {
061:
062: ////////////////////////////////////////////////////////////////////
063: // Default implementation of the EntityResolver interface.
064: ////////////////////////////////////////////////////////////////////
065:
066: /**
067: * Resolve an external entity.
068: *
069: * <p>Always return null, so that the parser will use the system
070: * identifier provided in the XML document. This method implements
071: * the SAX default behaviour: application writers can override it
072: * in a subclass to do special translations such as catalog lookups
073: * or URI redirection.</p>
074: *
075: * @param publicId The public identifer, or null if none is
076: * available.
077: * @param systemId The system identifier provided in the XML
078: * document.
079: * @return The new input source, or null to require the
080: * default behaviour.
081: * @exception java.io.IOException If there is an error setting
082: * up the new input source.
083: * @exception org.xml.sax.SAXException Any SAX exception, possibly
084: * wrapping another exception.
085: * @see org.xml.sax.EntityResolver#resolveEntity
086: */
087: public InputSource resolveEntity(String publicId, String systemId)
088: throws IOException, SAXException {
089: return null;
090: }
091:
092: ////////////////////////////////////////////////////////////////////
093: // Default implementation of DTDHandler interface.
094: ////////////////////////////////////////////////////////////////////
095:
096: /**
097: * Receive notification of a notation declaration.
098: *
099: * <p>By default, do nothing. Application writers may override this
100: * method in a subclass if they wish to keep track of the notations
101: * declared in a document.</p>
102: *
103: * @param name The notation name.
104: * @param publicId The notation public identifier, or null if not
105: * available.
106: * @param systemId The notation system identifier.
107: * @exception org.xml.sax.SAXException Any SAX exception, possibly
108: * wrapping another exception.
109: * @see org.xml.sax.DTDHandler#notationDecl
110: */
111: public void notationDecl(String name, String publicId,
112: String systemId) throws SAXException {
113: // no op
114: }
115:
116: /**
117: * Receive notification of an unparsed entity declaration.
118: *
119: * <p>By default, do nothing. Application writers may override this
120: * method in a subclass to keep track of the unparsed entities
121: * declared in a document.</p>
122: *
123: * @param name The entity name.
124: * @param publicId The entity public identifier, or null if not
125: * available.
126: * @param systemId The entity system identifier.
127: * @param notationName The name of the associated notation.
128: * @exception org.xml.sax.SAXException Any SAX exception, possibly
129: * wrapping another exception.
130: * @see org.xml.sax.DTDHandler#unparsedEntityDecl
131: */
132: public void unparsedEntityDecl(String name, String publicId,
133: String systemId, String notationName) throws SAXException {
134: // no op
135: }
136:
137: ////////////////////////////////////////////////////////////////////
138: // Default implementation of ContentHandler interface.
139: ////////////////////////////////////////////////////////////////////
140:
141: /**
142: * Receive a Locator object for document events.
143: *
144: * <p>By default, do nothing. Application writers may override this
145: * method in a subclass if they wish to store the locator for use
146: * with other document events.</p>
147: *
148: * @param locator A locator for all SAX document events.
149: * @see org.xml.sax.ContentHandler#setDocumentLocator
150: * @see org.xml.sax.Locator
151: */
152: public void setDocumentLocator(Locator locator) {
153: // no op
154: }
155:
156: /**
157: * Receive notification of the beginning of the document.
158: *
159: * <p>By default, do nothing. Application writers may override this
160: * method in a subclass to take specific actions at the beginning
161: * of a document (such as allocating the root node of a tree or
162: * creating an output file).</p>
163: *
164: * @exception org.xml.sax.SAXException Any SAX exception, possibly
165: * wrapping another exception.
166: * @see org.xml.sax.ContentHandler#startDocument
167: */
168: public void startDocument() throws SAXException {
169: // no op
170: }
171:
172: /**
173: * Receive notification of the end of the document.
174: *
175: * <p>By default, do nothing. Application writers may override this
176: * method in a subclass to take specific actions at the end
177: * of a document (such as finalising a tree or closing an output
178: * file).</p>
179: *
180: * @exception org.xml.sax.SAXException Any SAX exception, possibly
181: * wrapping another exception.
182: * @see org.xml.sax.ContentHandler#endDocument
183: */
184: public void endDocument() throws SAXException {
185: // no op
186: }
187:
188: /**
189: * Receive notification of the start of a Namespace mapping.
190: *
191: * <p>By default, do nothing. Application writers may override this
192: * method in a subclass to take specific actions at the start of
193: * each Namespace prefix scope (such as storing the prefix mapping).</p>
194: *
195: * @param prefix The Namespace prefix being declared.
196: * @param uri The Namespace URI mapped to the prefix.
197: * @exception org.xml.sax.SAXException Any SAX exception, possibly
198: * wrapping another exception.
199: * @see org.xml.sax.ContentHandler#startPrefixMapping
200: */
201: public void startPrefixMapping(String prefix, String uri)
202: throws SAXException {
203: // no op
204: }
205:
206: /**
207: * Receive notification of the end of a Namespace mapping.
208: *
209: * <p>By default, do nothing. Application writers may override this
210: * method in a subclass to take specific actions at the end of
211: * each prefix mapping.</p>
212: *
213: * @param prefix The Namespace prefix being declared.
214: * @exception org.xml.sax.SAXException Any SAX exception, possibly
215: * wrapping another exception.
216: * @see org.xml.sax.ContentHandler#endPrefixMapping
217: */
218: public void endPrefixMapping(String prefix) throws SAXException {
219: // no op
220: }
221:
222: /**
223: * Receive notification of the start of an element.
224: *
225: * <p>By default, do nothing. Application writers may override this
226: * method in a subclass to take specific actions at the start of
227: * each element (such as allocating a new tree node or writing
228: * output to a file).</p>
229: *
230: * @param uri The Namespace URI, or the empty string if the
231: * element has no Namespace URI or if Namespace
232: * processing is not being performed.
233: * @param localName The local name (without prefix), or the
234: * empty string if Namespace processing is not being
235: * performed.
236: * @param qName The qualified name (with prefix), or the
237: * empty string if qualified names are not available.
238: * @param atts The attributes attached to the element. If
239: * there are no attributes, it shall be an empty
240: * Attributes object.
241: * @exception org.xml.sax.SAXException Any SAX exception, possibly
242: * wrapping another exception.
243: * @see org.xml.sax.ContentHandler#startElement
244: */
245: public void startElement(String uri, String localName,
246: String qName, Attributes attributes) throws SAXException {
247: // no op
248: }
249:
250: /**
251: * Receive notification of the end 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 end of
255: * each element (such as finalising a 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: * @exception org.xml.sax.SAXException Any SAX exception, possibly
267: * wrapping another exception.
268: * @see org.xml.sax.ContentHandler#endElement
269: */
270: public void endElement(String uri, String localName, String qName)
271: throws SAXException {
272: // no op
273: }
274:
275: /**
276: * Receive notification of character data inside an element.
277: *
278: * <p>By default, do nothing. Application writers may override this
279: * method to take specific actions for each chunk of character data
280: * (such as adding the data to a node or buffer, or printing it to
281: * a file).</p>
282: *
283: * @param ch The characters.
284: * @param start The start position in the character array.
285: * @param length The number of characters to use from the
286: * character array.
287: * @exception org.xml.sax.SAXException Any SAX exception, possibly
288: * wrapping another exception.
289: * @see org.xml.sax.ContentHandler#characters
290: */
291: public void characters(char ch[], int start, int length)
292: throws SAXException {
293: // no op
294: }
295:
296: /**
297: * Receive notification of ignorable whitespace in element content.
298: *
299: * <p>By default, do nothing. Application writers may override this
300: * method to take specific actions for each chunk of ignorable
301: * whitespace (such as adding data to a node or buffer, or printing
302: * it to a file).</p>
303: *
304: * @param ch The whitespace characters.
305: * @param start The start position in the character array.
306: * @param length The number of characters to use from the
307: * character array.
308: * @exception org.xml.sax.SAXException Any SAX exception, possibly
309: * wrapping another exception.
310: * @see org.xml.sax.ContentHandler#ignorableWhitespace
311: */
312: public void ignorableWhitespace(char ch[], int start, int length)
313: throws SAXException {
314: // no op
315: }
316:
317: /**
318: * Receive notification of a processing instruction.
319: *
320: * <p>By default, do nothing. Application writers may override this
321: * method in a subclass to take specific actions for each
322: * processing instruction, such as setting status variables or
323: * invoking other methods.</p>
324: *
325: * @param target The processing instruction target.
326: * @param data The processing instruction data, or null if
327: * none is supplied.
328: * @exception org.xml.sax.SAXException Any SAX exception, possibly
329: * wrapping another exception.
330: * @see org.xml.sax.ContentHandler#processingInstruction
331: */
332: public void processingInstruction(String target, String data)
333: throws SAXException {
334: // no op
335: }
336:
337: /**
338: * Receive notification of a skipped entity.
339: *
340: * <p>By default, do nothing. Application writers may override this
341: * method in a subclass to take specific actions for each
342: * processing instruction, such as setting status variables or
343: * invoking other methods.</p>
344: *
345: * @param name The name of the skipped entity.
346: * @exception org.xml.sax.SAXException Any SAX exception, possibly
347: * wrapping another exception.
348: * @see org.xml.sax.ContentHandler#processingInstruction
349: */
350: public void skippedEntity(String name) throws SAXException {
351: // no op
352: }
353:
354: ////////////////////////////////////////////////////////////////////
355: // Default implementation of the ErrorHandler interface.
356: ////////////////////////////////////////////////////////////////////
357:
358: /**
359: * Receive notification of a parser warning.
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 warning, 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 warning(SAXParseException e) throws SAXException {
373: // no op
374: }
375:
376: /**
377: * Receive notification of a recoverable parser error.
378: *
379: * <p>The default implementation does nothing. Application writers
380: * may override this method in a subclass to take specific actions
381: * for each error, such as inserting the message in a log file or
382: * printing it to the console.</p>
383: *
384: * @param e The warning information encoded as an exception.
385: * @exception org.xml.sax.SAXException Any SAX exception, possibly
386: * wrapping another exception.
387: * @see org.xml.sax.ErrorHandler#warning
388: * @see org.xml.sax.SAXParseException
389: */
390: public void error(SAXParseException e) throws SAXException {
391: // no op
392: }
393:
394: /**
395: * Report a fatal XML parsing error.
396: *
397: * <p>The default implementation throws a SAXParseException.
398: * Application writers may override this method in a subclass if
399: * they need to take specific actions for each fatal error (such as
400: * collecting all of the errors into a single report): in any case,
401: * the application must stop all regular processing when this
402: * method is invoked, since the document is no longer reliable, and
403: * the parser may no longer report parsing events.</p>
404: *
405: * @param e The error information encoded as an exception.
406: * @exception org.xml.sax.SAXException Any SAX exception, possibly
407: * wrapping another exception.
408: * @see org.xml.sax.ErrorHandler#fatalError
409: * @see org.xml.sax.SAXParseException
410: */
411: public void fatalError(SAXParseException e) throws SAXException {
412: throw e;
413: }
414:
415: }
416:
417: // end of DefaultHandler.java
|