00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
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 
00051 
00052     class ErrHandler : public xercesc::DefaultHandler
00053     {
00054       public:
00055         ErrHandler () : DefaultHandler() {}
00056 
00057         void
00058         warning (const xercesc::SAXParseException& exc);
00059         
00060         void
00061         error (const xercesc::SAXParseException& exc);
00062         
00063         void
00064         fatalError (const xercesc::SAXParseException& exc);
00065         
00066         void
00067         resetErrors () {}
00068         
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       void notletter(const std::string&);
00080     } 
00081     
00082 
00083 
00084     class Handler : public xercesc::DefaultHandler
00085     {
00086       public:
00087         Handler (xercesc::SAX2XMLReader* parser,
00088                  Handler& root);
00089         Handler (xercesc::SAX2XMLReader* parser,
00090                  xercesc::DefaultHandler& root,
00091                  XMLEq& eq);
00092 
00093         void
00094         startElement (const XMLCh* const uri,
00095                       const XMLCh* const localname,
00096                       const XMLCh* const qname,
00097                       const xercesc::Attributes& attrs);
00098         void
00099         endElement (const XMLCh* const uri,
00100                     const XMLCh* const localname,
00101                     const XMLCh* const qname);
00102 
00103         virtual void
00104         start (const XMLCh* const uri,
00105                       const XMLCh* const localname,
00106                       const XMLCh* const qname,
00107                       const xercesc::Attributes& attrs) = 0;
00108         virtual void
00109         end (const XMLCh* const uri,
00110                     const XMLCh* const localname,
00111                     const XMLCh* const qname) = 0;
00112 
00113         XMLEq& eq() { return eq_; };
00114 # ifdef DEBUG
00115         static int      indent_;
00116 # endif
00117       protected:
00118         
00119         xercesc::SAX2XMLReader*         parser_;
00120         xercesc::DefaultHandler&        root_;
00121 
00122         XMLEq&  eq_;
00123     };
00124 # ifdef DEBUG
00125     int Handler::indent_ = 0;
00126 # endif
00127 
00132     class UnsupHandler : public Handler
00133     {
00134       public:
00135         UnsupHandler(xercesc::SAX2XMLReader* parser,
00136                      Handler& root);
00137 
00138         void
00139         start (const XMLCh* const uri,
00140                       const XMLCh* const localname,
00141                       const XMLCh* const qname,
00142                       const xercesc::Attributes& attrs);
00143         void
00144         end (const XMLCh* const uri,
00145                     const XMLCh* const localname,
00146                     const XMLCh* const qname);
00147       private:
00148         int                             depth_;
00149     };
00150   } 
00151 } 
00152 
00153 # if ! defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00154 #  include <vaucanson/xml/handlers_base.hxx>
00155 # endif // !VCSN_USE_INTERFACE_ONLY || VCSN_USE_LIB
00156 
00157 #endif // !VCSN_XML_HANDLERS_BASE_HH