BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
xmlBase::XmlErrorHandler Class Reference

#include <XmlErrorHandler.h>

+ Inheritance diagram for xmlBase::XmlErrorHandler:

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
 

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

◆ XmlErrorHandler()

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

Definition at line 41 of file XmlErrorHandler.h.

41 : m_throwErrors(throwErrors)
42 {resetErrors();}
void resetErrors()
Clear counters.

◆ ~XmlErrorHandler()

xmlBase::XmlErrorHandler::~XmlErrorHandler ( )
inline

Definition at line 43 of file XmlErrorHandler.h.

43{}

Member Function Documentation

◆ error()

void XmlErrorHandler::error ( const SAXParseException &  exception)

Output row, column of parse error and increment counter.

Definition at line 17 of file XmlErrorHandler.cxx.

17 {
18 char* charSyst = XMLString::transcode(toCatch.getSystemId());
19 std::string systemId(charSyst);
20 // std::string systemId(Dom::transToChar(toCatch.getSystemId()));
21 XMLString::release(&charSyst);
22 char* charMsg = XMLString::transcode(toCatch.getMessage());
23 std::string msg(charMsg);
24 XMLString::release(&charMsg);
25
26 std::string line;
27 facilities::Util::itoa((int)toCatch.getLineNumber(), line);
28 std::string col;
29 facilities::Util::itoa((int)toCatch.getColumnNumber(), col);
30
31 m_nError++;
32
33 std::string errMsg("Error at file \"");
34 errMsg += systemId + "\", line " + line + ",column " + col;
35 errMsg += "\n Message: " + msg;
36 if (m_throwErrors) {
37 throw ParseException(errMsg);
38 } else {
39 std::cerr << errMsg << "\n\n";
40 }
41 }
static const char * itoa(int val, std::string &outStr)

◆ fatalError()

void XmlErrorHandler::fatalError ( const SAXParseException &  exception)

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

Definition at line 43 of file XmlErrorHandler.cxx.

43 {
44
45 // getMessage returns type XMLCh*
46
47 char* charMsg = XMLString::transcode(toCatch.getMessage());
48 std::string msg(charMsg);
49 XMLString::release(&charMsg);
50
51 m_nFatal++;
52
53 if (!(toCatch.getSystemId()) ) {
54 std::string errMsg("Fatal XML parse error: no such file \n Message: ");
55 errMsg += msg;
56 if (m_throwErrors) {
57 throw ParseException(errMsg);
58 } else {
59 std::cerr << errMsg << "\n\n";
60 }
61 }
62 else {
63 char* charSyst = XMLString::transcode(toCatch.getSystemId());
64 std::string systemId(charSyst);
65 XMLString::release(&charSyst);
66
67 std::string line;
68 facilities::Util::itoa((int)toCatch.getLineNumber(), line);
69 std::string col;
70 facilities::Util::itoa((int)toCatch.getColumnNumber(), col);
71 std::string errMsg("Fatal error at file \"");
72 errMsg += systemId + "\", line " + line + ",column " + col;
73 errMsg += "\n Message: " + msg;
74
75 if (m_throwErrors) {
76 throw ParseException(errMsg);
77 } else {
78 std::cerr << errMsg << "\n\n";
79 }
80 }
81 }

◆ getErrorCount()

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

Definition at line 57 of file XmlErrorHandler.h.

57{return m_nError;}

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

◆ getFatalCount()

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

Definition at line 58 of file XmlErrorHandler.h.

58{return m_nFatal;}

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

◆ getWarningCount()

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

Definition at line 56 of file XmlErrorHandler.h.

56{return m_nWarning;}

◆ resetErrors()

void XmlErrorHandler::resetErrors ( )

Clear counters.

Definition at line 82 of file XmlErrorHandler.cxx.

82 {
83 m_nWarning = m_nError = m_nFatal = 0;
84 }

Referenced by XmlErrorHandler().

◆ warning()

void XmlErrorHandler::warning ( const SAXParseException &  exception)

Keep count of warnings seen.

Definition at line 13 of file XmlErrorHandler.cxx.

13 {
14 m_nWarning++;
15 }

The documentation for this class was generated from the following files: