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