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