001: /* Copyright 2000 - 2001 Quadcap Software. All rights reserved.
002: *
003: * This software is distributed under the Quadcap Free Software License.
004: * This software may be used or modified for any purpose, personal or
005: * commercial. Open Source redistributions are permitted. Commercial
006: * redistribution of larger works derived from, or works which bundle
007: * this software requires a "Commercial Redistribution License"; see
008: * http://www.quadcap.com/purchase.
009: *
010: * Redistributions qualify as "Open Source" under one of the following terms:
011: *
012: * Redistributions are made at no charge beyond the reasonable cost of
013: * materials and delivery.
014: *
015: * Redistributions are accompanied by a copy of the Source Code or by an
016: * irrevocable offer to provide a copy of the Source Code for up to three
017: * years at the cost of materials and delivery. Such redistributions
018: * must allow further use, modification, and redistribution of the Source
019: * Code under substantially the same terms as this license.
020: *
021: * Redistributions of source code must retain the copyright notices as they
022: * appear in each source code file, these license terms, and the
023: * disclaimer/limitation of liability set forth as paragraph 6 below.
024: *
025: * Redistributions in binary form must reproduce this Copyright Notice,
026: * these license terms, and the disclaimer/limitation of liability set
027: * forth as paragraph 6 below, in the documentation and/or other materials
028: * provided with the distribution.
029: *
030: * The Software is provided on an "AS IS" basis. No warranty is
031: * provided that the Software is free of defects, or fit for a
032: * particular purpose.
033: *
034: * Limitation of Liability. Quadcap Software shall not be liable
035: * for any damages suffered by the Licensee or any third party resulting
036: * from use of the Software.
037: */
038:
039: // SAX default handler base class.
040: // No warranty; no copyright -- use this as you will.
041: // $Id: HandlerBase.java,v 1.3 2001/01/06 06:11:02 stan Exp $
042: package org.xml.sax;
043:
044: /**
045: * Default base class for handlers.
046: *
047: * <p>This class implements the default behaviour for four SAX
048: * interfaces: EntityResolver, DTDHandler, DocumentHandler,
049: * and ErrorHandler.</p>
050: *
051: * <p>Application writers can extend this class when they need to
052: * implement only part of an interface; parser writers can
053: * instantiate this class to provide default handlers when the
054: * application has not supplied its own.</p>
055: *
056: * <p>Note that the use of this class is optional.</p>
057: *
058: * @author David Megginson (ak117@freenet.carleton.ca)
059: * @version 1.0
060: * @see org.xml.sax.EntityResolver
061: * @see org.xml.sax.DTDHandler
062: * @see org.xml.sax.DocumentHandler
063: * @see org.xml.sax.ErrorHandler
064: */
065: public class HandlerBase implements EntityResolver, DTDHandler,
066: DocumentHandler, ErrorHandler {
067:
068: //////////////////////////////////////////////////////////////////////
069: // Default implementation of the EntityResolver interface.
070: //////////////////////////////////////////////////////////////////////
071:
072: /**
073: * Resolve an external entity.
074: *
075: * <p>Always return null, so that the parser will use the system
076: * identifier provided in the XML document. This method implements
077: * the SAX default behaviour: application writers can override it
078: * in a subclass to do special translations such as catalog lookups
079: * or URI redirection.</p>
080: *
081: * @param publicId The public identifer, or null if none is
082: * available.
083: * @param systemId The system identifier provided in the XML
084: * document.
085: * @return The new input source, or null to require the
086: * default behaviour.
087: * @exception org.xml.sax.SAXException Any SAX exception, possibly
088: * wrapping another exception.
089: * @see org.xml.sax.EntityResolver#resolveEntity
090: */
091: public InputSource resolveEntity(String publicId, String systemId)
092: throws SAXException {
093: return null;
094: }
095:
096: //////////////////////////////////////////////////////////////////////
097: // Default implementation of DTDHandler interface.
098: //////////////////////////////////////////////////////////////////////
099:
100: /**
101: * Receive notification of a notation declaration.
102: *
103: * <p>By default, do nothing. Application writers may override this
104: * method in a subclass if they wish to keep track of the notations
105: * declared in a document.</p>
106: *
107: * @param name The notation name.
108: * @param publicId The notation public identifier, or null if not
109: * available.
110: * @param systemId The notation system identifier.
111: * @see org.xml.sax.DTDHandler#notationDecl
112: */
113: public void notationDecl(String name, String publicId,
114: String systemId) {
115: // no op
116: }
117:
118: /**
119: * Receive notification of an unparsed entity declaration.
120: *
121: * <p>By default, do nothing. Application writers may override this
122: * method in a subclass to keep track of the unparsed entities
123: * declared in a document.</p>
124: *
125: * @param name The entity name.
126: * @param publicId The entity public identifier, or null if not
127: * available.
128: * @param systemId The entity system identifier.
129: * @param notationName The name of the associated notation.
130: * @see org.xml.sax.DTDHandler#unparsedEntityDecl
131: */
132: public void unparsedEntityDecl(String name, String publicId,
133: String systemId, String notationName) {
134: // no op
135: }
136:
137: //////////////////////////////////////////////////////////////////////
138: // Default implementation of DocumentHandler 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.DocumentHandler#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.DocumentHandler#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 beginning
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.DocumentHandler#endDocument
183: */
184: public void endDocument() throws SAXException {
185: // no op
186: }
187:
188: /**
189: * Receive notification of the start of an element.
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 element (such as allocating a new tree node or writing
194: * output to a file).</p>
195: *
196: * @param name The element type name.
197: * @param attributes The specified or defaulted attributes.
198: * @exception org.xml.sax.SAXException Any SAX exception, possibly
199: * wrapping another exception.
200: * @see org.xml.sax.DocumentHandler#startElement
201: */
202: public void startElement(String name, AttributeList attributes)
203: throws SAXException {
204: // no op
205: }
206:
207: /**
208: * Receive notification of the end of an element.
209: *
210: * <p>By default, do nothing. Application writers may override this
211: * method in a subclass to take specific actions at the end of
212: * each element (such as finalising a tree node or writing
213: * output to a file).</p>
214: *
215: * @param name The element type name.
216: * @param attributes The specified or defaulted attributes.
217: * @exception org.xml.sax.SAXException Any SAX exception, possibly
218: * wrapping another exception.
219: * @see org.xml.sax.DocumentHandler#endElement
220: */
221: public void endElement(String name) throws SAXException {
222: // no op
223: }
224:
225: /**
226: * Receive notification of character data inside an element.
227: *
228: * <p>By default, do nothing. Application writers may override this
229: * method to take specific actions for each chunk of character data
230: * (such as adding the data to a node or buffer, or printing it to
231: * a file).</p>
232: *
233: * @param ch The characters.
234: * @param start The start position in the character array.
235: * @param length The number of characters to use from the
236: * character array.
237: * @exception org.xml.sax.SAXException Any SAX exception, possibly
238: * wrapping another exception.
239: * @see org.xml.sax.DocumentHandler#characters
240: */
241: public void characters(char ch[], int start, int length)
242: throws SAXException {
243: // no op
244: }
245:
246: /**
247: * Receive notification of ignorable whitespace in element content.
248: *
249: * <p>By default, do nothing. Application writers may override this
250: * method to take specific actions for each chunk of ignorable
251: * whitespace (such as adding data to a node or buffer, or printing
252: * it to a file).</p>
253: *
254: * @param ch The whitespace characters.
255: * @param start The start position in the character array.
256: * @param length The number of characters to use from the
257: * character array.
258: * @exception org.xml.sax.SAXException Any SAX exception, possibly
259: * wrapping another exception.
260: * @see org.xml.sax.DocumentHandler#ignorableWhitespace
261: */
262: public void ignorableWhitespace(char ch[], int start, int length)
263: throws SAXException {
264: // no op
265: }
266:
267: /**
268: * Receive notification of a processing instruction.
269: *
270: * <p>By default, do nothing. Application writers may override this
271: * method in a subclass to take specific actions for each
272: * processing instruction, such as setting status variables or
273: * invoking other methods.</p>
274: *
275: * @param target The processing instruction target.
276: * @param data The processing instruction data, or null if
277: * none is supplied.
278: * @exception org.xml.sax.SAXException Any SAX exception, possibly
279: * wrapping another exception.
280: * @see org.xml.sax.DocumentHandler#processingInstruction
281: */
282: public void processingInstruction(String target, String data)
283: throws SAXException {
284: // no op
285: }
286:
287: //////////////////////////////////////////////////////////////////////
288: // Default implementation of the ErrorHandler interface.
289: //////////////////////////////////////////////////////////////////////
290:
291: /**
292: * Receive notification of a parser warning.
293: *
294: * <p>The default implementation does nothing. Application writers
295: * may override this method in a subclass to take specific actions
296: * for each warning, such as inserting the message in a log file or
297: * printing it to the console.</p>
298: *
299: * @param e The warning information encoded as an exception.
300: * @exception org.xml.sax.SAXException Any SAX exception, possibly
301: * wrapping another exception.
302: * @see org.xml.sax.ErrorHandler#warning
303: * @see org.xml.sax.SAXParseException
304: */
305: public void warning(SAXParseException e) throws SAXException {
306: // no op
307: }
308:
309: /**
310: * Receive notification of a recoverable parser error.
311: *
312: * <p>The default implementation does nothing. Application writers
313: * may override this method in a subclass to take specific actions
314: * for each error, such as inserting the message in a log file or
315: * printing it to the console.</p>
316: *
317: * @param e The warning information encoded as an exception.
318: * @exception org.xml.sax.SAXException Any SAX exception, possibly
319: * wrapping another exception.
320: * @see org.xml.sax.ErrorHandler#warning
321: * @see org.xml.sax.SAXParseException
322: */
323: public void error(SAXParseException e) throws SAXException {
324: // no op
325: }
326:
327: /**
328: * Report a fatal XML parsing error.
329: *
330: * <p>The default implementation throws a SAXParseException.
331: * Application writers may override this method in a subclass if
332: * they need to take specific actions for each fatal error (such as
333: * collecting all of the errors into a single report): in any case,
334: * the application must stop all regular processing when this
335: * method is invoked, since the document is no longer reliable, and
336: * the parser may no longer report parsing events.</p>
337: *
338: * @param e The error information encoded as an exception.
339: * @exception org.xml.sax.SAXException Any SAX exception, possibly
340: * wrapping another exception.
341: * @see org.xml.sax.ErrorHandler#fatalError
342: * @see org.xml.sax.SAXParseException
343: */
344: public void fatalError(SAXParseException e) throws SAXException {
345: throw e;
346: }
347:
348: }
|