01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.xml;
19:
20: import org.xml.sax.ErrorHandler;
21: import org.xml.sax.SAXException;
22: import org.xml.sax.SAXParseException;
23:
24: import de.finix.contelligent.logging.LoggingService;
25:
26: /**
27: * An <code>EchoingErrorHandler</code> implements {@link ErrorHandler} and
28: * logs every exception and then rethrows the exception. A message may be
29: * specified which gets prepended to every log output.
30: */
31: public class EchoingErrorHandler implements ErrorHandler {
32: final static org.apache.log4j.Logger log = LoggingService
33: .getLogger(EchoingErrorHandler.class);
34:
35: private String msgPrefix;
36:
37: public EchoingErrorHandler(String msgPrefix) {
38: this .msgPrefix = msgPrefix;
39: }
40:
41: public EchoingErrorHandler() {
42: this ("");
43: }
44:
45: public String getMsgPrefix() {
46: return msgPrefix;
47: }
48:
49: public void setMsgPrefix(String msgPrefix) {
50: this .msgPrefix = msgPrefix;
51: }
52:
53: // -----------------------------------------------------------------------
54: // from interface 'org.xml.sax.ErrorHandler':
55: // -----------------------------------------------------------------------
56:
57: // Receive notification of a recoverable parser error.
58: public void error(SAXParseException e) throws SAXException {
59: log.error(msgPrefix + " parse error at line "
60: + e.getLineNumber() + " column " + e.getColumnNumber()
61: + ": " + e.getMessage(), e);
62: throw e;
63: }
64:
65: // Report a fatal XML parsing error.
66: public void fatalError(SAXParseException e) throws SAXException {
67: log.error(msgPrefix + " parse fatal error at line "
68: + e.getLineNumber() + " column " + e.getColumnNumber()
69: + ": " + e.getMessage(), e);
70: throw e;
71: }
72:
73: // Receive notification of a parser warning.
74: public void warning(SAXParseException e) throws SAXException {
75: log.warn(msgPrefix + " parse warning at line "
76: + e.getLineNumber() + " column " + e.getColumnNumber()
77: + ": " + e.getMessage(), e);
78: throw e;
79: }
80:
81: }
|