001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.util.xml; 018 019import javax.xml.transform.ErrorListener; 020import javax.xml.transform.TransformerException; 021 022import org.apache.commons.logging.Log; 023 024/** 025 * Simple {@code javax.xml.transform.ErrorListener} implementation: 026 * logs warnings using the given Commons Logging logger instance, 027 * and rethrows errors to discontinue the XML transformation. 028 * 029 * @author Juergen Hoeller 030 * @since 1.2 031 */ 032public class SimpleTransformErrorListener implements ErrorListener { 033 034 private final Log logger; 035 036 037 /** 038 * Create a new SimpleTransformErrorListener for the given 039 * Commons Logging logger instance. 040 */ 041 public SimpleTransformErrorListener(Log logger) { 042 this.logger = logger; 043 } 044 045 046 @Override 047 public void warning(TransformerException ex) throws TransformerException { 048 logger.warn("XSLT transformation warning", ex); 049 } 050 051 @Override 052 public void error(TransformerException ex) throws TransformerException { 053 logger.error("XSLT transformation error", ex); 054 } 055 056 @Override 057 public void fatalError(TransformerException ex) throws TransformerException { 058 throw ex; 059 } 060 061}