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