01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.springframework.util.xml;
18:
19: import org.apache.commons.logging.Log;
20: import org.xml.sax.ErrorHandler;
21: import org.xml.sax.SAXException;
22: import org.xml.sax.SAXParseException;
23:
24: /**
25: * Simple <code>org.xml.sax.ErrorHandler</code> implementation:
26: * logs warnings using the given Commons Logging logger instance,
27: * and rethrows errors to discontinue the XML transformation.
28: *
29: * @author Juergen Hoeller
30: * @since 1.2
31: */
32: public class SimpleSaxErrorHandler implements ErrorHandler {
33:
34: private final Log logger;
35:
36: /**
37: * Create a new SimpleSaxErrorHandler for the given
38: * Commons Logging logger instance.
39: */
40: public SimpleSaxErrorHandler(Log logger) {
41: this .logger = logger;
42: }
43:
44: public void warning(SAXParseException ex) throws SAXException {
45: logger.warn("Ignored XML validation warning", ex);
46: }
47:
48: public void error(SAXParseException ex) throws SAXException {
49: throw ex;
50: }
51:
52: public void fatalError(SAXParseException ex) throws SAXException {
53: throw ex;
54: }
55:
56: }
|