BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
XmlErrorHandler.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/xmlBase/src/XmlErrorHandler.cxx,v 1.1.1.1 2005/10/17
2// 06:10:27 maqm Exp $ author: J. Bogart
3
4#include "xmlBase/XmlErrorHandler.h"
5#include "facilities/Util.h"
6#include "xmlBase/Dom.h"
7#include <string>
8
9namespace xmlBase {
10 using XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException;
11 using XERCES_CPP_NAMESPACE_QUALIFIER XMLString;
12
13 void XmlErrorHandler::warning( const SAXParseException& ) { m_nWarning++; }
14
15 void XmlErrorHandler::error( const SAXParseException& toCatch ) {
16 char* charSyst = XMLString::transcode( toCatch.getSystemId() );
17 std::string systemId( charSyst );
18 // std::string systemId(Dom::transToChar(toCatch.getSystemId()));
19 XMLString::release( &charSyst );
20 char* charMsg = XMLString::transcode( toCatch.getMessage() );
21 std::string msg( charMsg );
22 XMLString::release( &charMsg );
23
24 std::string line;
25 facilities::Util::itoa( (int)toCatch.getLineNumber(), line );
26 std::string col;
27 facilities::Util::itoa( (int)toCatch.getColumnNumber(), col );
28
29 m_nError++;
30
31 std::string errMsg( "Error at file \"" );
32 errMsg += systemId + "\", line " + line + ",column " + col;
33 errMsg += "\n Message: " + msg;
34 if ( m_throwErrors ) { throw ParseException( errMsg ); }
35 else { std::cerr << errMsg << "\n\n"; }
36 }
37
38 void XmlErrorHandler::fatalError( const SAXParseException& toCatch ) {
39
40 // getMessage returns type XMLCh*
41
42 char* charMsg = XMLString::transcode( toCatch.getMessage() );
43 std::string msg( charMsg );
44 XMLString::release( &charMsg );
45
46 m_nFatal++;
47
48 if ( !( toCatch.getSystemId() ) )
49 {
50 std::string errMsg( "Fatal XML parse error: no such file \n Message: " );
51 errMsg += msg;
52 if ( m_throwErrors ) { throw ParseException( errMsg ); }
53 else { std::cerr << errMsg << "\n\n"; }
54 }
55 else
56 {
57 char* charSyst = XMLString::transcode( toCatch.getSystemId() );
58 std::string systemId( charSyst );
59 XMLString::release( &charSyst );
60
61 std::string line;
62 facilities::Util::itoa( (int)toCatch.getLineNumber(), line );
63 std::string col;
64 facilities::Util::itoa( (int)toCatch.getColumnNumber(), col );
65 std::string errMsg( "Fatal error at file \"" );
66 errMsg += systemId + "\", line " + line + ",column " + col;
67 errMsg += "\n Message: " + msg;
68
69 if ( m_throwErrors ) { throw ParseException( errMsg ); }
70 else { std::cerr << errMsg << "\n\n"; }
71 }
72 }
73 void XmlErrorHandler::resetErrors() { m_nWarning = m_nError = m_nFatal = 0; }
74} // namespace xmlBase
static const char * itoa(int val, std::string &outStr)
Exception class for XmlParser, XmlErrorHandler.
void warning(const SAXParseException &exception)
Keep count of warnings seen.
void resetErrors()
Clear counters.
void fatalError(const SAXParseException &exception)
Output row, column of fatal parse error and increment counter.
void error(const SAXParseException &exception)
Output row, column of parse error and increment counter.