Added reload of levels on F7 (Update levelpack) to ease the test of changes.
[enigmagame.git] / src / DOMErrorReporter.cc
blob3eb8a40d8935283517eb11865eb7710c9b6aeddb
1 /*
2 * Copyright (C) 2005 Ronald Lamprecht
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "DOMErrorReporter.hh"
21 #include "main.hh"
22 #include "XMLtoLocal.hh"
23 #include <iostream>
24 #include <xercesc/dom/DOM.hpp>
25 #include <xercesc/util/XMLString.hpp>
26 #include <xercesc/util/XercesDefs.hpp>
29 XERCES_CPP_NAMESPACE_USE
31 namespace enigma
33 DOMErrorReporter::DOMErrorReporter(std::ostream *aLogStream) :
34 sawErrors(false), severity(DOMError::DOM_SEVERITY_WARNING),
35 logStream(aLogStream), reportStream(aLogStream) {
38 DOMErrorReporter::~DOMErrorReporter() {
41 // DOMCountHandlers: Overrides of the DOM ErrorHandler interface
42 bool DOMErrorReporter::handleError(const DOMError& domError) {
43 sawErrors = true;
44 if (domError.getSeverity() == DOMError::DOM_SEVERITY_WARNING) {
45 if(reportStream) {*reportStream << "\nWarning ";}
47 else if (domError.getSeverity() == DOMError::DOM_SEVERITY_ERROR) {
48 if(reportStream) {*reportStream << "\nError ";}
49 if (severity == DOMError::DOM_SEVERITY_WARNING)
50 severity = DOMError::DOM_SEVERITY_ERROR;
52 else {
53 if(reportStream) {*reportStream << "\nFatal Error ";}
54 severity = DOMError::DOM_SEVERITY_FATAL_ERROR;
57 if(reportStream) {
58 const XMLCh * const fileURI = domError.getLocation()->getURI();
59 if( fileURI && (XMLString::stringLen(fileURI) > 0)) {
60 *reportStream << "at file "
61 << XMLtoLocal(fileURI)
62 << ", line " << domError.getLocation()->getLineNumber()
63 << ", char " << domError.getLocation()->getColumnNumber();
65 *reportStream << "\n Message: " << XMLtoLocal(domError.getMessage())
66 << std::endl;
69 // try to continue
70 return true;
73 bool DOMErrorReporter::getSawErrors() const {
74 return sawErrors;
77 DOMError::ErrorSeverity DOMErrorReporter::getSeverity() const {
78 return severity;
81 void DOMErrorReporter::resetErrors() {
82 sawErrors = false;
83 severity = DOMError::DOM_SEVERITY_WARNING;
86 void DOMErrorReporter::reportToLog() {
87 reportStream = logStream;
90 void DOMErrorReporter::reportToErr() {
91 reportStream = &std::cerr;
94 void DOMErrorReporter::reportToNull() {
95 reportStream = NULL;
98 void DOMErrorReporter::reportToOstream(std::ostream *anOstream) {
99 reportStream = anOstream;
102 } // namespace enigma