source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/sax2/DefaultHandler.hpp @ 2674

Revision 2674, 24.4 KB checked in by mattausch, 16 years ago (diff)
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: DefaultHandler.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23#ifndef DEFAULTHANDLER_HPP
24#define DEFAULTHANDLER_HPP
25
26#include <xercesc/sax2/ContentHandler.hpp>
27#include <xercesc/sax2/LexicalHandler.hpp>
28#include <xercesc/sax2/DeclHandler.hpp>
29#include <xercesc/sax/DTDHandler.hpp>
30#include <xercesc/sax/EntityResolver.hpp>
31#include <xercesc/sax/ErrorHandler.hpp>
32#include <xercesc/sax/SAXParseException.hpp>
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36class Locator;
37class Attributes;
38
39/**
40  * Default base class for SAX2 handlers.
41  *
42  * <p>This class implements the default behaviour for SAX2
43  * interfaces: EntityResolver, DTDHandler, ContentHandler,
44  * ErrorHandler, LexicalHandler, and DeclHandler.</p>
45  *
46  * <p>Application writers can extend this class when they need to
47  * implement only part of an interface; parser writers can
48  * instantiate this class to provide default handlers when the
49  * application has not supplied its own.</p>
50  *
51  * <p>Note that the use of this class is optional.</p>
52  *
53  * @see EntityResolver#EntityResolver
54  * @see DTDHandler#DTDHandler
55  * @see ContentHandler#ContentHandler
56  * @see ErrorHandler#ErrorHandler
57  * @see LexicalHandler#LexicalHandler
58  * @see DeclHandler#DeclHandler
59  */
60
61class SAX2_EXPORT DefaultHandler :
62
63    public EntityResolver,
64        public DTDHandler,
65        public ContentHandler,
66    public ErrorHandler,
67    public LexicalHandler,
68    public DeclHandler
69{
70public:
71  /** @name Default handlers for the DocumentHandler interface */
72    //@{
73  /**
74    * Receive notification of character data inside an element.
75    *
76    * <p>By default, do nothing.  Application writers may override this
77    * method to take specific actions for each chunk of character data
78    * (such as adding the data to a node or buffer, or printing it to
79    * a file).</p>
80    *
81    * @param chars The characters.
82    * @param length The number of characters to use from the
83    *               character array.
84    * @exception SAXException Any SAX exception, possibly
85    *            wrapping another exception.
86    * @see DocumentHandler#characters
87    */
88    virtual void characters
89    (
90        const   XMLCh* const    chars
91        , const unsigned int    length
92    );
93
94  /**
95    * Receive notification of the end of the document.
96    *
97    * <p>By default, do nothing.  Application writers may override this
98    * method in a subclass to take specific actions at the beginning
99    * of a document (such as finalising a tree or closing an output
100    * file).</p>
101    *
102    * @exception SAXException Any SAX exception, possibly
103    *            wrapping another exception.
104    * @see DocumentHandler#endDocument
105    */
106    virtual void endDocument();
107
108  /**
109    * Receive notification of the end of an element.
110    *
111    * <p>By default, do nothing.  Application writers may override this
112    * method in a subclass to take specific actions at the end of
113    * each element (such as finalising a tree node or writing
114    * output to a file).</p>
115    *
116    * @param uri The URI of the asscioated namespace for this element
117        * @param localname The local part of the element name
118        * @param qname The QName of this element
119    * @exception SAXException Any SAX exception, possibly
120    *            wrapping another exception.
121    * @see DocumentHandler#endElement
122    */
123    virtual void endElement
124        (
125                const XMLCh* const uri,
126                const XMLCh* const localname,
127                const XMLCh* const qname
128        );
129
130  /**
131    * Receive notification of ignorable whitespace in element content.
132    *
133    * <p>By default, do nothing.  Application writers may override this
134    * method to take specific actions for each chunk of ignorable
135    * whitespace (such as adding data to a node or buffer, or printing
136    * it to a file).</p>
137    *
138    * @param chars The whitespace characters.
139    * @param length The number of characters to use from the
140    *               character array.
141    * @exception SAXException Any SAX exception, possibly
142    *            wrapping another exception.
143    * @see DocumentHandler#ignorableWhitespace
144    */
145    virtual void ignorableWhitespace
146    (
147        const   XMLCh* const    chars
148        , const unsigned int    length
149    );
150
151  /**
152    * Receive notification of a processing instruction.
153    *
154    * <p>By default, do nothing.  Application writers may override this
155    * method in a subclass to take specific actions for each
156    * processing instruction, such as setting status variables or
157    * invoking other methods.</p>
158    *
159    * @param target The processing instruction target.
160    * @param data The processing instruction data, or null if
161    *             none is supplied.
162    * @exception SAXException Any SAX exception, possibly
163    *            wrapping another exception.
164    * @see DocumentHandler#processingInstruction
165    */
166    virtual void processingInstruction
167    (
168        const   XMLCh* const    target
169        , const XMLCh* const    data
170    );
171
172    /**
173    * Reset the Docuemnt object on its reuse
174    *
175    * @see DocumentHandler#resetDocument
176    */
177    virtual void resetDocument();
178    //@}
179
180    /** @name Default implementation of DocumentHandler interface */
181
182    //@{
183  /**
184    * Receive a Locator object for document events.
185    *
186    * <p>By default, do nothing.  Application writers may override this
187    * method in a subclass if they wish to store the locator for use
188    * with other document events.</p>
189    *
190    * @param locator A locator for all SAX document events.
191    * @see DocumentHandler#setDocumentLocator
192    * @see Locator
193    */
194    virtual void setDocumentLocator(const Locator* const locator);
195
196  /**
197    * Receive notification of the beginning of the document.
198    *
199    * <p>By default, do nothing.  Application writers may override this
200    * method in a subclass to take specific actions at the beginning
201    * of a document (such as allocating the root node of a tree or
202    * creating an output file).</p>
203    *
204    * @exception SAXException Any SAX exception, possibly
205    *            wrapping another exception.
206    * @see DocumentHandler#startDocument
207    */
208    virtual void startDocument();
209
210  /**
211    * Receive notification of the start of an element.
212    *
213    * <p>By default, do nothing.  Application writers may override this
214    * method in a subclass to take specific actions at the start of
215    * each element (such as allocating a new tree node or writing
216    * output to a file).</p>
217    *
218    * @param uri The URI of the asscioated namespace for this element
219        * @param localname the local part of the element name
220        * @param qname the QName of this element
221    * @param attrs The specified or defaulted attributes.
222    * @exception SAXException Any SAX exception, possibly
223    *            wrapping another exception.
224    * @see DocumentHandler#startElement
225    */
226    virtual void startElement
227    (
228        const   XMLCh* const    uri,
229        const   XMLCh* const    localname,
230        const   XMLCh* const    qname
231        , const Attributes&     attrs
232    );
233
234  /**
235    * Receive notification of the start of an namespace prefix mapping.
236    *
237    * <p>By default, do nothing.  Application writers may override this
238    * method in a subclass to take specific actions at the start of
239    * each namespace prefix mapping.</p>
240    *
241    * @param prefix The namespace prefix used
242    * @param uri The namespace URI used.
243    * @exception SAXException Any SAX exception, possibly
244    *            wrapping another exception.
245    * @see DocumentHandler#startPrefixMapping
246    */
247        virtual void startPrefixMapping
248        (
249                const   XMLCh* const    prefix,
250                const   XMLCh* const    uri
251        ) ;
252
253  /**
254    * Receive notification of the end of an namespace prefix mapping.
255    *
256    * <p>By default, do nothing.  Application writers may override this
257    * method in a subclass to take specific actions at the end of
258    * each namespace prefix mapping.</p>
259    *
260    * @param prefix The namespace prefix used
261    * @exception SAXException Any SAX exception, possibly
262    *            wrapping another exception.
263    * @see DocumentHandler#endPrefixMapping
264    */
265        virtual void endPrefixMapping
266        (
267                const   XMLCh* const    prefix
268        ) ;
269
270  /**
271    * Receive notification of a skipped entity
272    *
273    * <p>The parser will invoke this method once for each entity
274        * skipped.  All processors may skip external entities,
275        * depending on the values of the features:<br>
276        * http://xml.org/sax/features/external-general-entities<br>
277        * http://xml.org/sax/features/external-parameter-entities</p>
278    *
279        * <p>Introduced with SAX2</p>
280        *
281    * @param name The name of the skipped entity.  If it is a parameter entity,
282        * the name will begin with %, and if it is the external DTD subset,
283        * it will be the string [dtd].
284    * @exception SAXException Any SAX exception, possibly
285    *            wrapping another exception.
286    */
287        virtual void skippedEntity
288        (
289                const   XMLCh* const    name
290        ) ;
291
292    //@}
293
294    /** @name Default implementation of the EntityResolver interface. */
295
296    //@{
297  /**
298    * Resolve an external entity.
299    *
300    * <p>Always return null, so that the parser will use the system
301    * identifier provided in the XML document.  This method implements
302    * the SAX default behaviour: application writers can override it
303    * in a subclass to do special translations such as catalog lookups
304    * or URI redirection.</p>
305    *
306    * @param publicId The public identifer, or null if none is
307    *                 available.
308    * @param systemId The system identifier provided in the XML
309    *                 document.
310    * @return The new input source, or null to require the
311    *         default behaviour.
312    *         The returned InputSource is owned by the parser which is
313    *         responsible to clean up the memory.
314    * @exception SAXException Any SAX exception, possibly
315    *            wrapping another exception.
316    * @see EntityResolver#resolveEntity
317    */
318    virtual InputSource* resolveEntity
319    (
320        const   XMLCh* const    publicId
321        , const XMLCh* const    systemId
322    );
323
324    //@}
325
326    /** @name Default implementation of the ErrorHandler interface */
327    //@{
328   /**
329    * Receive notification of a recoverable parser error.
330    *
331    * <p>The default implementation does nothing.  Application writers
332    * may override this method in a subclass to take specific actions
333    * for each error, such as inserting the message in a log file or
334    * printing it to the console.</p>
335    *
336    * @param exc The warning information encoded as an exception.
337    * @exception SAXException Any SAX exception, possibly
338    *            wrapping another exception.
339    * @see ErrorHandler#warning
340    * @see SAXParseException#SAXParseException
341    */
342    virtual void error(const SAXParseException& exc);
343
344  /**
345    * Report a fatal XML parsing error.
346    *
347    * <p>The default implementation throws a SAXParseException.
348    * Application writers may override this method in a subclass if
349    * they need to take specific actions for each fatal error (such as
350    * collecting all of the errors into a single report): in any case,
351    * the application must stop all regular processing when this
352    * method is invoked, since the document is no longer reliable, and
353    * the parser may no longer report parsing events.</p>
354    *
355    * @param exc The error information encoded as an exception.
356    * @exception SAXException Any SAX exception, possibly
357    *            wrapping another exception.
358    * @see ErrorHandler#fatalError
359    * @see SAXParseException#SAXParseException
360    */
361    virtual void fatalError(const SAXParseException& exc);
362
363  /**
364    * Receive notification of a parser warning.
365    *
366    * <p>The default implementation does nothing.  Application writers
367    * may override this method in a subclass to take specific actions
368    * for each warning, such as inserting the message in a log file or
369    * printing it to the console.</p>
370    *
371    * @param exc The warning information encoded as an exception.
372    * @exception SAXException Any SAX exception, possibly
373    *            wrapping another exception.
374    * @see ErrorHandler#warning
375    * @see SAXParseException#SAXParseException
376    */
377    virtual void warning(const SAXParseException& exc);
378
379    /**
380    * Reset the Error handler object on its reuse
381    *
382    * @see ErrorHandler#resetErrors
383    */
384    virtual void resetErrors();
385
386    //@}
387
388
389    /** @name Default implementation of DTDHandler interface. */
390    //@{
391
392  /**
393    * Receive notification of a notation declaration.
394    *
395    * <p>By default, do nothing.  Application writers may override this
396    * method in a subclass if they wish to keep track of the notations
397    * declared in a document.</p>
398    *
399    * @param name The notation name.
400    * @param publicId The notation public identifier, or null if not
401    *                 available.
402    * @param systemId The notation system identifier.
403    * @see DTDHandler#notationDecl
404    */
405    virtual void notationDecl
406    (
407        const   XMLCh* const    name
408        , const XMLCh* const    publicId
409        , const XMLCh* const    systemId
410    );
411
412    /**
413    * Reset the DTD object on its reuse
414    *
415    * @see DTDHandler#resetDocType
416    */
417    virtual void resetDocType();
418
419  /**
420    * Receive notification of an unparsed entity declaration.
421    *
422    * <p>By default, do nothing.  Application writers may override this
423    * method in a subclass to keep track of the unparsed entities
424    * declared in a document.</p>
425    *
426    * @param name The entity name.
427    * @param publicId The entity public identifier, or null if not
428    *                 available.
429    * @param systemId The entity system identifier.
430    * @param notationName The name of the associated notation.
431    * @see DTDHandler#unparsedEntityDecl
432    */
433    virtual void unparsedEntityDecl
434    (
435        const   XMLCh* const    name
436        , const XMLCh* const    publicId
437        , const XMLCh* const    systemId
438        , const XMLCh* const    notationName
439    );
440    //@}
441
442
443    /** @name Default implementation of LexicalHandler interface. */
444
445    //@{
446   /**
447    * Receive notification of comments.
448    *
449    * <p>The Parser will call this method to report each occurence of
450    * a comment in the XML document.</p>
451    *
452    * <p>The application must not attempt to read from the array
453    * outside of the specified range.</p>
454    *
455    * @param chars The characters from the XML document.
456    * @param length The number of characters to read from the array.
457    * @exception SAXException Any SAX exception, possibly
458    *            wrapping another exception.
459    */
460    virtual void comment
461    (
462        const   XMLCh* const    chars
463        , const unsigned int    length
464    );
465
466  /**
467    * Receive notification of the end of a CDATA section.
468    *
469    * <p>The SAX parser will invoke this method at the end of
470    * each CDATA parsed.</p>
471    *
472    * @exception SAXException Any SAX exception, possibly
473    *            wrapping another exception.
474    */
475    virtual void endCDATA ();
476
477  /**
478    * Receive notification of the end of the DTD declarations.
479    *
480    * <p>The SAX parser will invoke this method at the end of the
481    * DTD</p>
482    *
483    * @exception SAXException Any SAX exception, possibly
484    *            wrapping another exception.
485    */
486    virtual void endDTD ();
487
488  /**
489    * Receive notification of the end of an entity.
490    *
491    * <p>The SAX parser will invoke this method at the end of an
492    * entity</p>
493    *
494    * @param name The name of the entity that is ending.
495    * @exception SAXException Any SAX exception, possibly
496    *            wrapping another exception.
497    */
498    virtual void endEntity (const XMLCh* const name);
499
500  /**
501    * Receive notification of the start of a CDATA section.
502    *
503    * <p>The SAX parser will invoke this method at the start of
504    * each CDATA parsed.</p>
505    *
506    * @exception SAXException Any SAX exception, possibly
507    *            wrapping another exception.
508    */
509    virtual void startCDATA ();
510
511  /**
512    * Receive notification of the start of the DTD declarations.
513    *
514    * <p>The SAX parser will invoke this method at the start of the
515    * DTD</p>
516    *
517    * @param name The document type name.
518    * @param publicId The declared public identifier for the external DTD subset, or null if none was declared.
519    * @param systemId The declared system identifier for the external DTD subset, or null if none was declared.
520    * @exception SAXException Any SAX exception, possibly
521    *            wrapping another exception.
522    */
523    virtual void startDTD
524    (
525        const   XMLCh* const    name
526        , const   XMLCh* const    publicId
527        , const   XMLCh* const    systemId
528    );
529
530  /**
531    * Receive notification of the start of an entity.
532    *
533    * <p>The SAX parser will invoke this method at the start of an
534    * entity</p>
535    *
536    * @param name The name of the entity that is starting.
537    * @exception SAXException Any SAX exception, possibly
538    *            wrapping another exception.
539    */
540    virtual void startEntity (const XMLCh* const name);
541
542    //@}
543
544    /** @name Default implementation of DeclHandler interface. */
545
546    //@{
547
548   /**
549    * Report an element type declaration.
550    *
551    * <p>The content model will consist of the string "EMPTY", the string
552    * "ANY", or a parenthesised group, optionally followed by an occurrence
553    * indicator. The model will be normalized so that all parameter entities
554    * are fully resolved and all whitespace is removed,and will include the
555    * enclosing parentheses. Other normalization (such as removing redundant
556    * parentheses or simplifying occurrence indicators) is at the discretion
557    * of the parser.</p>
558    *
559    * @param name The element type name.
560    * @param model The content model as a normalized string.
561    * @exception SAXException Any SAX exception, possibly
562    *            wrapping another exception.
563    */
564    virtual void elementDecl
565    (
566        const   XMLCh* const    name
567        , const XMLCh* const    model
568    );
569
570   /**
571    * Report an attribute type declaration.
572    *
573    * <p>Only the effective (first) declaration for an attribute will
574    * be reported.</p>
575    *
576    * @param eName The name of the associated element.
577    * @param aName The name of the attribute.
578    * @param type A string representing the attribute type.
579    * @param mode A string representing the attribute defaulting mode ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.
580    * @param value A string representing the attribute's default value, or null if there is none.
581    * @exception SAXException Any SAX exception, possibly
582    *            wrapping another exception.
583    */
584    virtual void attributeDecl
585    (
586        const   XMLCh* const    eName
587        , const XMLCh* const    aName
588        , const XMLCh* const    type
589        , const XMLCh* const    mode
590        , const XMLCh* const    value
591    );
592
593   /**
594    * Report an internal entity declaration.
595    *
596    * <p>Only the effective (first) declaration for each entity will be
597    * reported. All parameter entities in the value will be expanded, but
598    * general entities will not.</p>
599    *
600    * @param name The name of the entity. If it is a parameter entity, the name will begin with '%'.
601    * @param value The replacement text of the entity.
602    * @exception SAXException Any SAX exception, possibly
603    *            wrapping another exception.
604    */
605    virtual void internalEntityDecl
606    (
607        const   XMLCh* const    name
608        , const XMLCh* const    value
609    );
610
611   /**
612    * Report a parsed external entity declaration.
613    *
614    * <p>Only the effective (first) declaration for each entity will
615    * be reported.</p>
616    *
617    * @param name The name of the entity. If it is a parameter entity, the name will begin with '%'.
618    * @param publicId The The declared public identifier of the entity, or null if none was declared.
619    * @param systemId The declared system identifier of the entity.
620    * @exception SAXException Any SAX exception, possibly
621    *            wrapping another exception.
622    */
623    virtual void externalEntityDecl
624    (
625        const   XMLCh* const    name
626        , const XMLCh* const    publicId
627        , const XMLCh* const    systemId
628    );
629
630    //@}
631
632    DefaultHandler() {};
633    virtual ~DefaultHandler() {};
634
635private:
636        // -----------------------------------------------------------------------
637    //  Unimplemented constructors and operators
638    // -----------------------------------------------------------------------
639    DefaultHandler(const DefaultHandler&);
640    DefaultHandler& operator=(const DefaultHandler&);   
641};
642
643
644// ---------------------------------------------------------------------------
645//  HandlerBase: Inline default implementations
646// ---------------------------------------------------------------------------
647inline void DefaultHandler::characters(const   XMLCh* const
648                                       ,const   unsigned int)
649{
650}
651
652inline void DefaultHandler::endDocument()
653{
654}
655
656inline void DefaultHandler::endElement(const    XMLCh* const
657                                                                                , const XMLCh* const
658                                                                                , const XMLCh* const)
659{
660}
661
662inline void DefaultHandler::error(const SAXParseException&)
663{
664}
665
666inline void DefaultHandler::fatalError(const SAXParseException& exc)
667{
668    throw exc;
669}
670
671inline void
672DefaultHandler::ignorableWhitespace( const   XMLCh* const
673                                    , const unsigned int)
674{
675}
676
677inline void DefaultHandler::notationDecl(  const   XMLCh* const
678                                                                                        , const XMLCh* const
679                                                                                        , const XMLCh* const)
680{
681}
682
683inline void
684DefaultHandler::processingInstruction( const   XMLCh* const
685                                                                                , const XMLCh* const)
686{
687}
688
689inline void DefaultHandler::resetErrors()
690{
691}
692
693inline void DefaultHandler::resetDocument()
694{
695}
696
697inline void DefaultHandler::resetDocType()
698{
699}
700
701inline InputSource*
702DefaultHandler::resolveEntity( const   XMLCh* const
703                                                                , const XMLCh* const)
704{
705    return 0;
706}
707
708inline void
709DefaultHandler::unparsedEntityDecl(const   XMLCh* const
710                                                                        , const XMLCh* const
711                                                                        , const XMLCh* const
712                                                                        , const XMLCh* const)
713{
714}
715
716inline void DefaultHandler::setDocumentLocator(const Locator* const)
717{
718}
719
720inline void DefaultHandler::startDocument()
721{
722}
723
724inline void
725DefaultHandler::startElement(  const     XMLCh* const
726                                                                , const   XMLCh* const
727                                                                , const   XMLCh* const
728                                                                , const   Attributes&
729)
730{
731}
732
733inline void DefaultHandler::warning(const SAXParseException&)
734{
735}
736
737inline void DefaultHandler::startPrefixMapping ( const  XMLCh* const
738                                                                                                ,const  XMLCh* const)
739{
740}
741
742inline void DefaultHandler::endPrefixMapping ( const    XMLCh* const)
743{
744}
745
746inline void DefaultHandler::skippedEntity ( const       XMLCh* const)
747{
748}
749
750inline void DefaultHandler::comment(  const   XMLCh* const
751                                       , const unsigned int)
752{
753}
754
755inline void DefaultHandler::endCDATA ()
756{
757}
758
759inline void DefaultHandler::endDTD ()
760{
761}
762
763inline void DefaultHandler::endEntity (const XMLCh* const)
764{
765}
766
767inline void DefaultHandler::startCDATA ()
768{
769}
770
771inline void DefaultHandler::startDTD(  const   XMLCh* const
772                                        , const   XMLCh* const
773                                        , const   XMLCh* const)
774{
775}
776
777inline void DefaultHandler::startEntity (const XMLCh* const)
778{
779}
780
781inline void DefaultHandler::attributeDecl(const XMLCh* const,
782                                          const XMLCh* const,
783                                          const XMLCh* const,
784                                          const XMLCh* const,
785                                          const XMLCh* const)
786{
787}
788
789inline void DefaultHandler::elementDecl(const XMLCh* const,
790                                        const XMLCh* const)
791{
792}
793
794inline void DefaultHandler::externalEntityDecl(const XMLCh* const,
795                                               const XMLCh* const,
796                                               const XMLCh* const)
797{
798}
799
800inline void DefaultHandler::internalEntityDecl(const XMLCh* const,
801                                               const XMLCh* const)
802{
803}
804
805XERCES_CPP_NAMESPACE_END
806
807#endif // ! DEFAULTHANDLER_HPP
Note: See TracBrowser for help on using the repository browser.