handlers_base.hh

00001 // handlers_base.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2007, 2008 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 
00018 #ifndef VCSN_XML_HANDLERS_BASE_HH
00019 # define VCSN_XML_HANDLERS_BASE_HH
00020 
00031 # include <map>
00032 # include <string>
00033 
00034 # include <xercesc/sax2/SAX2XMLReader.hpp>
00035 # include <xercesc/sax2/XMLReaderFactory.hpp>
00036 # include <xercesc/sax2/DefaultHandler.hpp>
00037 # include <xercesc/sax2/Attributes.hpp>
00038 
00039 # include <xercesc/sax/SAXException.hpp>
00040 # include <xercesc/util/XMLString.hpp>
00041 
00042 # include <vaucanson/xml/xmleq.hh>
00043 # include <vaucanson/xml/strings.hh>
00044 
00045 namespace vcsn
00046 {
00047   namespace xml
00048   {
00049     /*
00050      * ErrHandler class, error handler.
00051      */
00052     class ErrHandler : public xercesc::DefaultHandler
00053     {
00054       public:
00055         ErrHandler () : DefaultHandler() {}
00056 
00057         void
00058         warning (const xercesc::SAXParseException& exc);
00059         // Receive notification of a warning.
00060         void
00061         error (const xercesc::SAXParseException& exc);
00062         // Receive notification of a recoverable error.
00063         void
00064         fatalError (const xercesc::SAXParseException& exc);
00065         // Receive notification of a non-recoverable error.
00066         void
00067         resetErrors () {}
00068         // Reset the Error handler object on its reuse.
00069     };
00070 
00071     namespace error
00072     {
00073       void token(const XMLCh* const localname);
00074       void attrs(const XMLCh* const localname,
00075                  const std::string& name,
00076                  const std::string& value);
00077       void missattrs(const XMLCh* const localname,
00078                      const std::string& name);
00079     } // !error
00080     /*
00081      * Handler class
00082      */
00083     class Handler : public xercesc::DefaultHandler
00084     {
00085       public:
00086         Handler (xercesc::SAX2XMLReader* parser,
00087                  Handler& root);
00088         Handler (xercesc::SAX2XMLReader* parser,
00089                  xercesc::DefaultHandler& root,
00090                  XMLEq& eq);
00091 
00092         void
00093         startElement (const XMLCh* const uri,
00094                       const XMLCh* const localname,
00095                       const XMLCh* const qname,
00096                       const xercesc::Attributes& attrs);
00097         void
00098         endElement (const XMLCh* const uri,
00099                     const XMLCh* const localname,
00100                     const XMLCh* const qname);
00101 
00102         virtual void
00103         start (const XMLCh* const uri,
00104                       const XMLCh* const localname,
00105                       const XMLCh* const qname,
00106                       const xercesc::Attributes& attrs) = 0;
00107         virtual void
00108         end (const XMLCh* const uri,
00109                     const XMLCh* const localname,
00110                     const XMLCh* const qname) = 0;
00111 
00112         XMLEq& eq() { return eq_; };
00113 # ifdef DEBUG
00114         static int      indent_;
00115 # endif
00116       protected:
00117         // Required to enable a change of the Handler while parsing.
00118         xercesc::SAX2XMLReader*         parser_;
00119         xercesc::DefaultHandler&        root_;
00120 
00121         XMLEq&  eq_;
00122     };
00123 # ifdef DEBUG
00124     int Handler::indent_ = 0;
00125 # endif
00126 
00131     class UnsupHandler : public Handler
00132     {
00133       public:
00134         UnsupHandler(xercesc::SAX2XMLReader* parser,
00135                      Handler& root);
00136 
00137         void
00138         start (const XMLCh* const uri,
00139                       const XMLCh* const localname,
00140                       const XMLCh* const qname,
00141                       const xercesc::Attributes& attrs);
00142         void
00143         end (const XMLCh* const uri,
00144                     const XMLCh* const localname,
00145                     const XMLCh* const qname);
00146       private:
00147         int                             depth_;
00148     };
00149   } // !xml
00150 } // !vcsn
00151 
00152 # if ! defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00153 #  include <vaucanson/xml/handlers_base.hxx>
00154 # endif // !VCSN_USE_INTERFACE_ONLY || VCSN_USE_LIB
00155 
00156 #endif // !VCSN_XML_HANDLERS_BASE_HH

Generated on Thu Oct 9 20:22:35 2008 for Vaucanson by  doxygen 1.5.1