source: icXML/icXML-devel/src/icxercesc/sax/HandlerBase.hpp @ 2720

Last change on this file since 2720 was 2720, checked in by cameron, 6 years ago

Initial check-in of icXML 0.8 source files

File size: 14.2 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: HandlerBase.hpp 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_HANDLERBASE_HPP)
23#define XERCESC_INCLUDE_GUARD_HANDLERBASE_HPP
24
25#include <xercesc/sax/DocumentHandler.hpp>
26#include <xercesc/sax/DTDHandler.hpp>
27#include <xercesc/sax/EntityResolver.hpp>
28#include <xercesc/sax/ErrorHandler.hpp>
29#include <xercesc/sax/SAXParseException.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33class Locator;
34class AttributeList;
35
36/**
37  * Default base class for handlers.
38  *
39  * <p>This class implements the default behaviour for four SAX
40  * interfaces: EntityResolver, DTDHandler, DocumentHandler,
41  * and ErrorHandler.</p>
42  *
43  * <p>Application writers can extend this class when they need to
44  * implement only part of an interface; parser writers can
45  * instantiate this class to provide default handlers when the
46  * application has not supplied its own.</p>
47  *
48  * <p>Note that the use of this class is optional.</p>
49  *
50  * @see EntityResolver#EntityResolver
51  * @see DTDHandler#DTDHandler
52  * @see DocumentHandler#DocumentHandler
53  * @see ErrorHandler#ErrorHandler
54  */
55
56class SAX_EXPORT HandlerBase :
57
58    public EntityResolver, public DTDHandler, public DocumentHandler
59    , public ErrorHandler
60{
61public:
62    /** @name Default handlers for the DocumentHandler interface */
63    //@{
64  /**
65    * Receive notification of character data inside an element.
66    *
67    * <p>By default, do nothing.  Application writers may override this
68    * method to take specific actions for each chunk of character data
69    * (such as adding the data to a node or buffer, or printing it to
70    * a file).</p>
71    *
72    * @param chars The characters.
73    * @param length The number of characters to use from the
74    *               character array.
75    * @exception SAXException Any SAX exception, possibly
76    *            wrapping another exception.
77    * @see DocumentHandler#characters
78    */
79    virtual void characters
80    (
81        const   XMLCh* const    chars
82        , const XMLSize_t       length
83    );
84
85  /**
86    * Receive notification of the end of the document.
87    *
88    * <p>By default, do nothing.  Application writers may override this
89    * method in a subclass to take specific actions at the beginning
90    * of a document (such as finalising a tree or closing an output
91    * file).</p>
92    *
93    * @exception SAXException Any SAX exception, possibly
94    *            wrapping another exception.
95    * @see DocumentHandler#endDocument
96    */
97    virtual void endDocument();
98
99  /**
100    * Receive notification of the end of an element.
101    *
102    * <p>By default, do nothing.  Application writers may override this
103    * method in a subclass to take specific actions at the end of
104    * each element (such as finalising a tree node or writing
105    * output to a file).</p>
106    *
107    * @param name The element type name.
108    * @exception SAXException Any SAX exception, possibly
109    *            wrapping another exception.
110    * @see DocumentHandler#endElement
111    */
112    virtual void endElement(const XMLCh* const name);
113
114  /**
115    * Receive notification of ignorable whitespace in element content.
116    *
117    * <p>By default, do nothing.  Application writers may override this
118    * method to take specific actions for each chunk of ignorable
119    * whitespace (such as adding data to a node or buffer, or printing
120    * it to a file).</p>
121    *
122    * @param chars The whitespace characters.
123    * @param length The number of characters to use from the
124    *               character array.
125    * @exception SAXException Any SAX exception, possibly
126    *            wrapping another exception.
127    * @see DocumentHandler#ignorableWhitespace
128    */
129    virtual void ignorableWhitespace
130    (
131        const   XMLCh* const    chars
132        , const XMLSize_t       length
133    );
134
135  /**
136    * Receive notification of a processing instruction.
137    *
138    * <p>By default, do nothing.  Application writers may override this
139    * method in a subclass to take specific actions for each
140    * processing instruction, such as setting status variables or
141    * invoking other methods.</p>
142    *
143    * @param target The processing instruction target.
144    * @param data The processing instruction data, or null if
145    *             none is supplied.
146    * @exception SAXException Any SAX exception, possibly
147    *            wrapping another exception.
148    * @see DocumentHandler#processingInstruction
149    */
150    virtual void processingInstruction
151    (
152        const   XMLCh* const    target
153        , const XMLCh* const    data
154    );
155
156    /**
157    * Reset the Document object on its reuse
158    *
159    * @see DocumentHandler#resetDocument
160    */
161    virtual void resetDocument();
162    //@}
163
164    /** @name Default implementation of DocumentHandler interface */
165
166    //@{
167  /**
168    * Receive a Locator object for document events.
169    *
170    * <p>By default, do nothing.  Application writers may override this
171    * method in a subclass if they wish to store the locator for use
172    * with other document events.</p>
173    *
174    * @param locator A locator for all SAX document events.
175    * @see DocumentHandler#setDocumentLocator
176    * @see Locator
177    */
178    virtual void setDocumentLocator(const Locator* const locator);
179
180  /**
181    * Receive notification of the beginning of the document.
182    *
183    * <p>By default, do nothing.  Application writers may override this
184    * method in a subclass to take specific actions at the beginning
185    * of a document (such as allocating the root node of a tree or
186    * creating an output file).</p>
187    *
188    * @exception SAXException Any SAX exception, possibly
189    *            wrapping another exception.
190    * @see DocumentHandler#startDocument
191    */
192    virtual void startDocument();
193
194  /**
195    * Receive notification of the start of an element.
196    *
197    * <p>By default, do nothing.  Application writers may override this
198    * method in a subclass to take specific actions at the start of
199    * each element (such as allocating a new tree node or writing
200    * output to a file).</p>
201    *
202    * @param name The element type name.
203    * @param attributes The specified or defaulted attributes.
204    * @exception SAXException Any SAX exception, possibly
205    *            wrapping another exception.
206    * @see DocumentHandler#startElement
207    */
208    virtual void startElement
209    (
210        const   XMLCh* const    name
211        ,       AttributeList&  attributes
212    );
213
214    //@}
215
216    /** @name Default implementation of the EntityResolver interface. */
217
218    //@{
219  /**
220    * Resolve an external entity.
221    *
222    * <p>Always return null, so that the parser will use the system
223    * identifier provided in the XML document.  This method implements
224    * the SAX default behaviour: application writers can override it
225    * in a subclass to do special translations such as catalog lookups
226    * or URI redirection.</p>
227    *
228    * @param publicId The public identifier, or null if none is
229    *                 available.
230    * @param systemId The system identifier provided in the XML
231    *                 document.
232    * @return The new input source, or null to require the
233    *         default behaviour.
234    *         The returned InputSource is owned by the parser which is
235    *         responsible to clean up the memory.
236    * @exception SAXException Any SAX exception, possibly
237    *            wrapping another exception.
238    * @see EntityResolver#resolveEntity
239    */
240    virtual InputSource* resolveEntity
241    (
242        const   XMLCh* const    publicId
243        , const XMLCh* const    systemId
244    );
245
246    //@}
247
248    /** @name Default implementation of the ErrorHandler interface */
249    //@{
250   /**
251    * Receive notification of a recoverable parser error.
252    *
253    * <p>The default implementation does nothing.  Application writers
254    * may override this method in a subclass to take specific actions
255    * for each error, such as inserting the message in a log file or
256    * printing it to the console.</p>
257    *
258    * @param exc The warning information encoded as an exception.
259    * @exception SAXException Any SAX exception, possibly
260    *            wrapping another exception.
261    * @see ErrorHandler#pragma warning
262    * @see SAXParseException#SAXParseException
263    */
264    virtual void error(const SAXParseException& exc);
265
266  /**
267    * Report a fatal XML parsing error.
268    *
269    * <p>The default implementation throws a SAXParseException.
270    * Application writers may override this method in a subclass if
271    * they need to take specific actions for each fatal error (such as
272    * collecting all of the errors into a single report): in any case,
273    * the application must stop all regular processing when this
274    * method is invoked, since the document is no longer reliable, and
275    * the parser may no longer report parsing events.</p>
276    *
277    * @param exc The error information encoded as an exception.
278    * @exception SAXException Any SAX exception, possibly
279    *            wrapping another exception.
280    * @see ErrorHandler#fatalError
281    * @see SAXParseException#SAXParseException
282    */
283    virtual void fatalError(const SAXParseException& exc);
284
285  /**
286    * Receive notification of a parser warning.
287    *
288    * <p>The default implementation does nothing.  Application writers
289    * may override this method in a subclass to take specific actions
290    * for each warning, such as inserting the message in a log file or
291    * printing it to the console.</p>
292    *
293    * @param exc The warning information encoded as an exception.
294    * @exception SAXException Any SAX exception, possibly
295    *            wrapping another exception.
296    * @see ErrorHandler#pragma warning
297    * @see SAXParseException#SAXParseException
298    */
299    virtual void warning(const SAXParseException& exc);
300
301    /**
302    * Reset the Error handler object on its reuse
303    *
304    * @see ErrorHandler#resetErrors
305    */
306    virtual void resetErrors();
307
308    //@}
309
310
311    /** @name Default implementation of DTDHandler interface. */
312    //@{
313
314  /**
315    * Receive notification of a notation declaration.
316    *
317    * <p>By default, do nothing.  Application writers may override this
318    * method in a subclass if they wish to keep track of the notations
319    * declared in a document.</p>
320    *
321    * @param name The notation name.
322    * @param publicId The notation public identifier, or null if not
323    *                 available.
324    * @param systemId The notation system identifier.
325    * @see DTDHandler#notationDecl
326    */
327    virtual void notationDecl
328    (
329        const   XMLCh* const    name
330        , const XMLCh* const    publicId
331        , const XMLCh* const    systemId
332    );
333
334    /**
335    * Reset the DTD object on its reuse
336    *
337    * @see DTDHandler#resetDocType
338    */
339    virtual void resetDocType();
340
341  /**
342    * Receive notification of an unparsed entity declaration.
343    *
344    * <p>By default, do nothing.  Application writers may override this
345    * method in a subclass to keep track of the unparsed entities
346    * declared in a document.</p>
347    *
348    * @param name The entity name.
349    * @param publicId The entity public identifier, or null if not
350    *                 available.
351    * @param systemId The entity system identifier.
352    * @param notationName The name of the associated notation.
353    * @see DTDHandler#unparsedEntityDecl
354    */
355    virtual void unparsedEntityDecl
356    (
357        const   XMLCh* const    name
358        , const XMLCh* const    publicId
359        , const XMLCh* const    systemId
360        , const XMLCh* const    notationName
361    );
362    //@}
363
364    HandlerBase() {};
365    virtual ~HandlerBase() {};
366
367private:
368        // -----------------------------------------------------------------------
369    //  Unimplemented constructors and operators
370    // -----------------------------------------------------------------------
371    HandlerBase(const HandlerBase&);
372    HandlerBase& operator=(const HandlerBase&);
373};
374
375
376// ---------------------------------------------------------------------------
377//  HandlerBase: Inline default implementations
378// ---------------------------------------------------------------------------
379inline void HandlerBase::characters(const   XMLCh* const
380                                    , const XMLSize_t)
381{
382}
383
384inline void HandlerBase::endDocument()
385{
386}
387
388inline void HandlerBase::endElement(const XMLCh* const)
389{
390}
391
392inline void HandlerBase::error(const SAXParseException&)
393{
394}
395
396inline void HandlerBase::fatalError(const SAXParseException& exc)
397{
398    throw exc;
399}
400
401inline void
402HandlerBase::ignorableWhitespace(   const   XMLCh* const
403                                    , const XMLSize_t)
404{
405}
406
407inline void HandlerBase::notationDecl(  const   XMLCh* const
408                                        , const XMLCh* const
409                                        , const XMLCh* const)
410{
411}
412
413inline void
414HandlerBase::processingInstruction( const   XMLCh* const
415                                    , const XMLCh* const)
416{
417}
418
419inline void HandlerBase::resetErrors()
420{
421}
422
423inline void HandlerBase::resetDocument()
424{
425}
426
427inline void HandlerBase::resetDocType()
428{
429}
430
431inline InputSource*
432HandlerBase::resolveEntity( const   XMLCh* const
433                            , const XMLCh* const)
434{
435    return 0;
436}
437
438inline void
439HandlerBase::unparsedEntityDecl(const   XMLCh* const
440                                , const XMLCh* const
441                                , const XMLCh* const
442                                , const XMLCh* const)
443{
444}
445
446inline void HandlerBase::setDocumentLocator(const Locator* const)
447{
448}
449
450inline void HandlerBase::startDocument()
451{
452}
453
454inline void
455HandlerBase::startElement(  const   XMLCh* const
456                            ,       AttributeList&)
457{
458}
459
460inline void HandlerBase::warning(const SAXParseException&)
461{
462}
463
464XERCES_CPP_NAMESPACE_END
465
466#endif
Note: See TracBrowser for help on using the repository browser.