1 /*
2 * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.opensaml.xml.parse;
18
19 import org.slf4j.Logger;
20 import org.xml.sax.ErrorHandler;
21 import org.xml.sax.SAXException;
22 import org.xml.sax.SAXParseException;
23
24 /**
25 * A SAX error handler that logs errors a {@link Logger} before rethrowing them.
26 */
27 public class LoggingErrorHandler implements ErrorHandler {
28
29 /** Error logger. */
30 private Logger log;
31
32 /**
33 * Constructor.
34 *
35 * @param logger logger errors will be written to
36 */
37 public LoggingErrorHandler(Logger logger) {
38 log = logger;
39 }
40
41 /** {@inheritDoc} */
42 public void error(SAXParseException exception) throws SAXException {
43 log.error("XML Parsing Error:", exception);
44 throw exception;
45 }
46
47 /** {@inheritDoc} */
48 public void fatalError(SAXParseException exception) throws SAXException {
49 log.error("XML Parsing Error", exception);
50 throw exception;
51 }
52
53 /** {@inheritDoc} */
54 public void warning(SAXParseException exception) throws SAXException {
55 log.warn("XML Parsing Error", exception);
56 throw exception;
57 }
58 }