• Main Page
  • Related Pages
  • Classes
  • Files
  • File List

src/XercesParser.hh

00001 /*
00002  * Copyright Anders Boberg 2006-2007.
00003  * Copyright Staffan Gimåker 2007-2010.
00004  *
00005  * ---
00006  *
00007  * This file is part of peekabot.
00008  *
00009  * peekabot is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 3 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * peekabot is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #ifndef PEEKABOT_XERCES_PARSER_HH_INCLUDED
00024 #define PEEKABOT_XERCES_PARSER_HH_INCLUDED
00025 
00026 #include "XMLParser.hh"
00027 #include <xercesc/sax2/SAX2XMLReader.hpp>
00028 #include <xercesc/sax2/DefaultHandler.hpp>
00029 #include <xercesc/util/XercesVersion.hpp>
00030 
00031 namespace peekabot
00032 {
00033 
00046     class XercesParser : public XMLParser
00047     {
00048     public:
00049         XercesParser() : m_handler(0) {}
00050         
00051         XercesParser(XMLHandler* handler)
00052             : m_handler(handler) {}
00053     
00063         virtual void invoke(const std::string& filename)
00064             throw(std::exception);
00065 
00069         virtual void set_handler(XMLHandler *handler)
00070         {
00071             m_handler = handler;
00072         }
00073 
00079         void set_schema(const std::string & schema)
00080         {
00081             m_schema = schema;
00082         }
00083 
00084     private:
00085         class XercesHandler : public xercesc::DefaultHandler
00086         {
00087         public:
00088             XercesHandler();
00089 
00090             XercesHandler(XMLHandler *handler);
00091 
00092             void set_handler(XMLHandler *handler);
00093 
00094             virtual void setDocumentLocator(
00095                 const xercesc::Locator * const locator);
00096 
00097             virtual void startDocument();
00098     
00099             virtual void endDocument();
00100             
00101             virtual void startElement(
00102                 const XMLCh* const uri, 
00103                 const XMLCh* const localname, 
00104                 const XMLCh* const qname, 
00105                 const xercesc::Attributes& attrs);
00106             
00107             virtual void endElement(
00108                 const XMLCh* const uri, 
00109                 const XMLCh* const localname,
00110                 const XMLCh* const qname);
00111 
00112             virtual void characters(
00113                 const XMLCh* const chars,
00114 #if _XERCES_VERSION >= 30000
00115                 const XMLSize_t length
00116 #else
00117                 const unsigned int length
00118 #endif
00119                 );
00120 
00121             virtual void error(
00122                 const xercesc::SAXParseException& exception)
00123                 throw(std::runtime_error);
00124             
00125             virtual void fatalError(
00126                 const xercesc::SAXParseException& exception)
00127                 throw(std::runtime_error);
00128 
00129             XMLSSize_t get_last_line() const throw();
00130 
00131             XMLSSize_t get_last_col() const throw();
00132 
00133             bool has_locator() const throw();
00134 
00135         protected:
00136             void update_line_info() throw();
00137             
00138         private:
00139             XMLHandler *m_handler;
00140             
00141             const xercesc::Locator *m_locator;
00142 
00143             XMLSSize_t m_last_line, m_last_col;
00144         };
00145 
00146         XMLHandler* m_handler;
00147 
00148         std::string m_schema;
00149     };
00150 
00151 }
00152 #endif // PEEKABOT_XERCES_PARSER_HH_INCLUDED

Generated on Sun Jan 30 2011 for peekabot by  doxygen 1.7.1