CGEM BOSS 6.6.5.f
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 06:10:27 maqm Exp $
2// author: J. Bogart
3
4#include "xmlBase/XmlErrorHandler.h"
5#include "xmlBase/Dom.h"
6#include "facilities/Util.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&) {
14 m_nWarning++;
15 }
16
17 void XmlErrorHandler::error(const SAXParseException& toCatch) {
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 }
42
43 void XmlErrorHandler::fatalError(const SAXParseException& toCatch) {
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 }
83 m_nWarning = m_nError = m_nFatal = 0;
84 }
85}
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.