error_handler.hxx

00001 // error_handler.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2004 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 #ifndef VCSN_XML_ERROR_HANDLER_HXX
00018 # define VCSN_XML_ERROR_HANDLER_HXX
00019 
00020 # include <vaucanson/xml/error_handler.hh>
00021 
00022 # include <iostream>
00023 
00024 namespace vcsn
00025 {
00026   namespace xml
00027   {
00028     inline
00029     std::string
00030     myDOMErrorHandler::get_msg() const
00031     {
00032       return message;
00033     }
00034 
00035     inline
00036     myDOMErrorHandler::myDOMErrorHandler(const myDOMErrorHandler& c)
00037       : DOMErrorHandler()
00038     {
00039       message = c.get_msg();
00040       error_ = c.has_error();
00041     }
00042 
00043     inline
00044     bool
00045     myDOMErrorHandler::has_error() const
00046     {
00047       return error_;
00048     }
00049 
00050     inline
00051     bool
00052     myDOMErrorHandler::handleError(const xercesc::DOMError& err)
00053     {
00054       using namespace xercesc;
00055       std::string msg;
00056 
00057       const XMLCh* uri = err.getLocation()->getURI();
00058       if (uri) {
00059         char* str = XMLString::transcode(uri);
00060         msg += str;
00061         XMLString::release(&str);
00062         msg += ": ";
00063       }
00064 
00065       std::ostringstream lo;
00066       lo << (int)(err.getLocation()->getLineNumber());
00067       msg += lo.str();
00068       msg += ", ";
00069       std::ostringstream co;
00070       co << (int)(err.getLocation()->getColumnNumber());
00071       msg += co.str();
00072       msg += ": ";
00073       const XMLCh* reason = err.getMessage();
00074       if (reason) {
00075         char* str = XMLString::transcode(reason);
00076         msg += str;
00077         XMLString::release(&str);
00078       }
00079       else
00080         msg += "no reason";
00081 
00082       if (err.getSeverity() == xercesc::DOMError::DOM_SEVERITY_WARNING) {
00083         std::cerr << msg << std::endl;
00084         return true;
00085       }
00086       message = msg;
00087 
00088       error_ = true;
00089       return false;
00090     }
00091   }
00092 }
00093 
00094 #endif // ! VCSN_XML_ERROR_HANDLER_HXX

Generated on Fri Jul 28 12:18:31 2006 for Vaucanson by  doxygen 1.4.6