xmlBase::XmlErrorHandler Class Reference

#include <XmlErrorHandler.h>

List of all members.

Public Member Functions

 XmlErrorHandler (bool throwErrors=false)
 ~XmlErrorHandler ()
void warning (const SAXParseException &exception)
 Keep count of warnings seen.
void error (const SAXParseException &exception)
 Output row, column of parse error and increment counter.
void fatalError (const SAXParseException &exception)
 Output row, column of fatal parse error and increment counter.
void resetErrors ()
 Clear counters.
int getWarningCount () const
int getErrorCount () const
int getFatalCount () const

Private Attributes

int m_nWarning
int m_nError
int m_nFatal
bool m_throwErrors


Detailed Description

This class handles errors during parsing of an xml file. By default output will go to cerr, but if throwErrors is set to true an exception of type xml::ParseException will be thrown instead

Definition at line 38 of file XmlErrorHandler.h.


Constructor & Destructor Documentation

xmlBase::XmlErrorHandler::XmlErrorHandler ( bool  throwErrors = false  )  [inline]

Definition at line 41 of file XmlErrorHandler.h.

References resetErrors().

00041                                               : m_throwErrors(throwErrors)
00042       {resetErrors();}

xmlBase::XmlErrorHandler::~XmlErrorHandler (  )  [inline]

Definition at line 43 of file XmlErrorHandler.h.

00043 {}


Member Function Documentation

void XmlErrorHandler::error ( const SAXParseException &  exception  ) 

Output row, column of parse error and increment counter.

Definition at line 17 of file XmlErrorHandler.cxx.

References RawFileTools::itoa(), genRecEmupikp::line, XmlErrorHandler::m_nError, release, and deljobs::string.

00017                                                               {
00018     char* charSyst = XMLString::transcode(toCatch.getSystemId());
00019     std::string systemId(charSyst);
00020     //    std::string systemId(Dom::transToChar(toCatch.getSystemId()));
00021     XMLString::release(&charSyst);
00022     char* charMsg = XMLString::transcode(toCatch.getMessage());
00023     std::string msg(charMsg);
00024     XMLString::release(&charMsg);
00025 
00026     std::string line;
00027     facilities::Util::itoa((int)toCatch.getLineNumber(), line);
00028     std::string col;
00029     facilities::Util::itoa((int)toCatch.getColumnNumber(), col);
00030 
00031     m_nError++;
00032 
00033     std::string errMsg("Error at file \"");
00034     errMsg += systemId + "\", line " + line + ",column " + col;
00035     errMsg += "\n Message: " + msg;
00036     if (m_throwErrors) {
00037       throw ParseException(errMsg);
00038     } else {
00039       std::cerr << errMsg << "\n\n";
00040     }
00041   }

void XmlErrorHandler::fatalError ( const SAXParseException &  exception  ) 

Output row, column of fatal parse error and increment counter.

Definition at line 43 of file XmlErrorHandler.cxx.

References RawFileTools::itoa(), genRecEmupikp::line, XmlErrorHandler::m_nFatal, release, and deljobs::string.

00043                                                                    {
00044 
00045     // getMessage returns type XMLCh*
00046 
00047     char* charMsg = XMLString::transcode(toCatch.getMessage());
00048     std::string msg(charMsg);
00049     XMLString::release(&charMsg);
00050 
00051     m_nFatal++;
00052 
00053     if (!(toCatch.getSystemId()) ) {
00054       std::string errMsg("Fatal XML parse error: no such file \n Message: ");
00055       errMsg += msg;
00056       if (m_throwErrors) {
00057         throw ParseException(errMsg);
00058       } else {
00059         std::cerr << errMsg << "\n\n";
00060       }
00061     }
00062     else {
00063       char* charSyst = XMLString::transcode(toCatch.getSystemId());
00064       std::string systemId(charSyst);
00065       XMLString::release(&charSyst);
00066 
00067       std::string line; 
00068       facilities::Util::itoa((int)toCatch.getLineNumber(), line);
00069       std::string col; 
00070       facilities::Util::itoa((int)toCatch.getColumnNumber(), col);
00071       std::string errMsg("Fatal error at file \"");
00072       errMsg += systemId + "\", line " + line + ",column " + col;
00073       errMsg += "\n Message: " + msg;
00074 
00075       if (m_throwErrors) {
00076         throw ParseException(errMsg);
00077       } else {
00078         std::cerr << errMsg << "\n\n";
00079       }
00080     }
00081   }

int xmlBase::XmlErrorHandler::getErrorCount (  )  const [inline]

Definition at line 57 of file XmlErrorHandler.h.

References m_nError.

Referenced by xmlBase::XmlParser::parse().

00057 {return m_nError;}

int xmlBase::XmlErrorHandler::getFatalCount (  )  const [inline]

Definition at line 58 of file XmlErrorHandler.h.

References m_nFatal.

Referenced by xmlBase::XmlParser::parse().

00058 {return m_nFatal;}

int xmlBase::XmlErrorHandler::getWarningCount (  )  const [inline]

Definition at line 56 of file XmlErrorHandler.h.

References m_nWarning.

00056 {return m_nWarning;}

void XmlErrorHandler::resetErrors (  ) 

Clear counters.

Definition at line 82 of file XmlErrorHandler.cxx.

References XmlErrorHandler::m_nError, XmlErrorHandler::m_nFatal, and XmlErrorHandler::m_nWarning.

Referenced by XmlErrorHandler().

00082                                     {
00083     m_nWarning = m_nError = m_nFatal = 0;
00084   }

void XmlErrorHandler::warning ( const SAXParseException &  exception  ) 

Keep count of warnings seen.

Definition at line 13 of file XmlErrorHandler.cxx.

References XmlErrorHandler::m_nWarning.

00013                                                         {
00014     m_nWarning++;
00015   }


Member Data Documentation

int xmlBase::XmlErrorHandler::m_nError [private]

Definition at line 62 of file XmlErrorHandler.h.

Referenced by getErrorCount().

int xmlBase::XmlErrorHandler::m_nFatal [private]

Definition at line 63 of file XmlErrorHandler.h.

Referenced by getFatalCount().

int xmlBase::XmlErrorHandler::m_nWarning [private]

Definition at line 61 of file XmlErrorHandler.h.

Referenced by getWarningCount().

bool xmlBase::XmlErrorHandler::m_throwErrors [private]

Definition at line 64 of file XmlErrorHandler.h.


Generated on Tue Nov 29 23:36:39 2016 for BOSS_7.0.2 by  doxygen 1.4.7