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"
22 #include "XMLtoLocal.hh"
24 #include <xercesc/dom/DOM.hpp>
25 #include <xercesc/util/XMLString.hpp>
26 #include <xercesc/util/XercesDefs.hpp>
29 XERCES_CPP_NAMESPACE_USE
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
) {
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
;
53 if(reportStream
) {*reportStream
<< "\nFatal Error ";}
54 severity
= DOMError::DOM_SEVERITY_FATAL_ERROR
;
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())
73 bool DOMErrorReporter::getSawErrors() const {
77 DOMError::ErrorSeverity
DOMErrorReporter::getSeverity() const {
81 void DOMErrorReporter::resetErrors() {
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() {
98 void DOMErrorReporter::reportToOstream(std::ostream
*anOstream
) {
99 reportStream
= anOstream
;
102 } // namespace enigma