001: // SAX default handler base class.
002: // http://www.saxproject.org
003: // No warranty; no copyright -- use this as you will.
004: // $Id: HandlerBase.java,v 1.6 2002/02/01 20:06:20 db Exp $
005:
006: package org.xml.sax;
007:
008: /**
009: * Default base class for handlers.
010: *
011: * <blockquote>
012: * <em>This module, both source code and documentation, is in the
013: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
014: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
015: * for further information.
016: * </blockquote>
017: *
018: * <p>This class implements the default behaviour for four SAX1
019: * interfaces: EntityResolver, DTDHandler, DocumentHandler,
020: * and ErrorHandler. It is now obsolete, but is included in SAX2 to
021: * support legacy SAX1 applications. SAX2 applications should use
022: * the {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}
023: * class instead.</p>
024: *
025: * <p>Application writers can extend this class when they need to
026: * implement only part of an interface; parser writers can
027: * instantiate this class to provide default handlers when the
028: * application has not supplied its own.</p>
029: *
030: * <p>Note that the use of this class is optional.</p>
031: *
032: * @deprecated This class works with the deprecated
033: * {@link org.xml.sax.DocumentHandler DocumentHandler}
034: * interface. It has been replaced by the SAX2
035: * {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}
036: * class.
037: * @since SAX 1.0
038: * @author David Megginson
039: * @version 2.0.1 (sax2r2)
040: * @see org.xml.sax.EntityResolver
041: * @see org.xml.sax.DTDHandler
042: * @see org.xml.sax.DocumentHandler
043: * @see org.xml.sax.ErrorHandler
044: */
045: public class HandlerBase implements EntityResolver, DTDHandler,
046: DocumentHandler, ErrorHandler {
047:
048: ////////////////////////////////////////////////////////////////////
049: // Default implementation of the EntityResolver interface.
050: ////////////////////////////////////////////////////////////////////
051:
052: /**
053: * Resolve an external entity.
054: *
055: * <p>Always return null, so that the parser will use the system
056: * identifier provided in the XML document. This method implements
057: * the SAX default behaviour: application writers can override it
058: * in a subclass to do special translations such as catalog lookups
059: * or URI redirection.</p>
060: *
061: * @param publicId The public identifer, or null if none is
062: * available.
063: * @param systemId The system identifier provided in the XML
064: * document.
065: * @return The new input source, or null to require the
066: * default behaviour.
067: * @exception org.xml.sax.SAXException Any SAX exception, possibly
068: * wrapping another exception.
069: * @see org.xml.sax.EntityResolver#resolveEntity
070: */
071: public InputSource resolveEntity(String publicId, String systemId)
072: throws SAXException {
073: return null;
074: }
075:
076: ////////////////////////////////////////////////////////////////////
077: // Default implementation of DTDHandler interface.
078: ////////////////////////////////////////////////////////////////////
079:
080: /**
081: * Receive notification of a notation declaration.
082: *
083: * <p>By default, do nothing. Application writers may override this
084: * method in a subclass if they wish to keep track of the notations
085: * declared in a document.</p>
086: *
087: * @param name The notation name.
088: * @param publicId The notation public identifier, or null if not
089: * available.
090: * @param systemId The notation system identifier.
091: * @see org.xml.sax.DTDHandler#notationDecl
092: */
093: public void notationDecl(String name, String publicId,
094: String systemId) {
095: // no op
096: }
097:
098: /**
099: * Receive notification of an unparsed entity declaration.
100: *
101: * <p>By default, do nothing. Application writers may override this
102: * method in a subclass to keep track of the unparsed entities
103: * declared in a document.</p>
104: *
105: * @param name The entity name.
106: * @param publicId The entity public identifier, or null if not
107: * available.
108: * @param systemId The entity system identifier.
109: * @param notationName The name of the associated notation.
110: * @see org.xml.sax.DTDHandler#unparsedEntityDecl
111: */
112: public void unparsedEntityDecl(String name, String publicId,
113: String systemId, String notationName) {
114: // no op
115: }
116:
117: ////////////////////////////////////////////////////////////////////
118: // Default implementation of DocumentHandler interface.
119: ////////////////////////////////////////////////////////////////////
120:
121: /**
122: * Receive a Locator object for document events.
123: *
124: * <p>By default, do nothing. Application writers may override this
125: * method in a subclass if they wish to store the locator for use
126: * with other document events.</p>
127: *
128: * @param locator A locator for all SAX document events.
129: * @see org.xml.sax.DocumentHandler#setDocumentLocator
130: * @see org.xml.sax.Locator
131: */
132: public void setDocumentLocator(Locator locator) {
133: // no op
134: }
135:
136: /**
137: * Receive notification of the beginning of the document.
138: *
139: * <p>By default, do nothing. Application writers may override this
140: * method in a subclass to take specific actions at the beginning
141: * of a document (such as allocating the root node of a tree or
142: * creating an output file).</p>
143: *
144: * @exception org.xml.sax.SAXException Any SAX exception, possibly
145: * wrapping another exception.
146: * @see org.xml.sax.DocumentHandler#startDocument
147: */
148: public void startDocument() throws SAXException {
149: // no op
150: }
151:
152: /**
153: * Receive notification of the end of the document.
154: *
155: * <p>By default, do nothing. Application writers may override this
156: * method in a subclass to take specific actions at the beginning
157: * of a document (such as finalising a tree or closing an output
158: * file).</p>
159: *
160: * @exception org.xml.sax.SAXException Any SAX exception, possibly
161: * wrapping another exception.
162: * @see org.xml.sax.DocumentHandler#endDocument
163: */
164: public void endDocument() throws SAXException {
165: // no op
166: }
167:
168: /**
169: * Receive notification of the start of an element.
170: *
171: * <p>By default, do nothing. Application writers may override this
172: * method in a subclass to take specific actions at the start of
173: * each element (such as allocating a new tree node or writing
174: * output to a file).</p>
175: *
176: * @param name The element type name.
177: * @param attributes The specified or defaulted attributes.
178: * @exception org.xml.sax.SAXException Any SAX exception, possibly
179: * wrapping another exception.
180: * @see org.xml.sax.DocumentHandler#startElement
181: */
182: public void startElement(String name, AttributeList attributes)
183: throws SAXException {
184: // no op
185: }
186:
187: /**
188: * Receive notification of the end of an element.
189: *
190: * <p>By default, do nothing. Application writers may override this
191: * method in a subclass to take specific actions at the end of
192: * each element (such as finalising a tree node or writing
193: * output to a file).</p>
194: *
195: * @param name The element type name.
196: * @param attributes The specified or defaulted attributes.
197: * @exception org.xml.sax.SAXException Any SAX exception, possibly
198: * wrapping another exception.
199: * @see org.xml.sax.DocumentHandler#endElement
200: */
201: public void endElement(String name) throws SAXException {
202: // no op
203: }
204:
205: /**
206: * Receive notification of character data inside an element.
207: *
208: * <p>By default, do nothing. Application writers may override this
209: * method to take specific actions for each chunk of character data
210: * (such as adding the data to a node or buffer, or printing it to
211: * a file).</p>
212: *
213: * @param ch The characters.
214: * @param start The start position in the character array.
215: * @param length The number of characters to use from the
216: * character array.
217: * @exception org.xml.sax.SAXException Any SAX exception, possibly
218: * wrapping another exception.
219: * @see org.xml.sax.DocumentHandler#characters
220: */
221: public void characters(char ch[], int start, int length)
222: throws SAXException {
223: // no op
224: }
225:
226: /**
227: * Receive notification of ignorable whitespace in element content.
228: *
229: * <p>By default, do nothing. Application writers may override this
230: * method to take specific actions for each chunk of ignorable
231: * whitespace (such as adding data to a node or buffer, or printing
232: * it to a file).</p>
233: *
234: * @param ch The whitespace characters.
235: * @param start The start position in the character array.
236: * @param length The number of characters to use from the
237: * character array.
238: * @exception org.xml.sax.SAXException Any SAX exception, possibly
239: * wrapping another exception.
240: * @see org.xml.sax.DocumentHandler#ignorableWhitespace
241: */
242: public void ignorableWhitespace(char ch[], int start, int length)
243: throws SAXException {
244: // no op
245: }
246:
247: /**
248: * Receive notification of a processing instruction.
249: *
250: * <p>By default, do nothing. Application writers may override this
251: * method in a subclass to take specific actions for each
252: * processing instruction, such as setting status variables or
253: * invoking other methods.</p>
254: *
255: * @param target The processing instruction target.
256: * @param data The processing instruction data, or null if
257: * none is supplied.
258: * @exception org.xml.sax.SAXException Any SAX exception, possibly
259: * wrapping another exception.
260: * @see org.xml.sax.DocumentHandler#processingInstruction
261: */
262: public void processingInstruction(String target, String data)
263: throws SAXException {
264: // no op
265: }
266:
267: ////////////////////////////////////////////////////////////////////
268: // Default implementation of the ErrorHandler interface.
269: ////////////////////////////////////////////////////////////////////
270:
271: /**
272: * Receive notification of a parser warning.
273: *
274: * <p>The default implementation does nothing. Application writers
275: * may override this method in a subclass to take specific actions
276: * for each warning, such as inserting the message in a log file or
277: * printing it to the console.</p>
278: *
279: * @param e The warning information encoded as an exception.
280: * @exception org.xml.sax.SAXException Any SAX exception, possibly
281: * wrapping another exception.
282: * @see org.xml.sax.ErrorHandler#warning
283: * @see org.xml.sax.SAXParseException
284: */
285: public void warning(SAXParseException e) throws SAXException {
286: // no op
287: }
288:
289: /**
290: * Receive notification of a recoverable parser error.
291: *
292: * <p>The default implementation does nothing. Application writers
293: * may override this method in a subclass to take specific actions
294: * for each error, such as inserting the message in a log file or
295: * printing it to the console.</p>
296: *
297: * @param e The warning information encoded as an exception.
298: * @exception org.xml.sax.SAXException Any SAX exception, possibly
299: * wrapping another exception.
300: * @see org.xml.sax.ErrorHandler#warning
301: * @see org.xml.sax.SAXParseException
302: */
303: public void error(SAXParseException e) throws SAXException {
304: // no op
305: }
306:
307: /**
308: * Report a fatal XML parsing error.
309: *
310: * <p>The default implementation throws a SAXParseException.
311: * Application writers may override this method in a subclass if
312: * they need to take specific actions for each fatal error (such as
313: * collecting all of the errors into a single report): in any case,
314: * the application must stop all regular processing when this
315: * method is invoked, since the document is no longer reliable, and
316: * the parser may no longer report parsing events.</p>
317: *
318: * @param e The error information encoded as an exception.
319: * @exception org.xml.sax.SAXException Any SAX exception, possibly
320: * wrapping another exception.
321: * @see org.xml.sax.ErrorHandler#fatalError
322: * @see org.xml.sax.SAXParseException
323: */
324: public void fatalError(SAXParseException e) throws SAXException {
325: throw e;
326: }
327:
328: }
329:
330: // end of HandlerBase.java
|