001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community 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 * http://www.opensource.org/licenses/ecl2.php 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 package org.kuali.rice.ken.util; 017 018 import org.apache.log4j.Logger; 019 import org.xml.sax.ErrorHandler; 020 import org.xml.sax.SAXException; 021 import org.xml.sax.SAXParseException; 022 023 /** 024 * A simple SAX ErrorHandler implementation that logs to a global logger for this 025 * class, or the one provided. 026 * @author Kuali Rice Team (rice.collab@kuali.org) 027 */ 028 public class SimpleErrorHandler implements ErrorHandler { 029 private static final Logger LOG = Logger.getLogger(SimpleErrorHandler.class); 030 031 private final Logger log; 032 033 /** 034 * Constructs a SimpleErrorHandler.java. 035 */ 036 public SimpleErrorHandler() { 037 this.log = LOG; 038 } 039 040 /** 041 * Constructs a SimpleErrorHandler.java. 042 * @param log 043 */ 044 public SimpleErrorHandler(Logger log) { 045 this.log = log; 046 } 047 048 /** 049 * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) 050 */ 051 public void warning(SAXParseException se) { 052 log.warn("Warning parsing xml doc " + se.getSystemId(), se); 053 } 054 055 /** 056 * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) 057 */ 058 public void error(SAXParseException se) throws SAXException { 059 log.error("Error parsing xml doc " + se.getSystemId(), se); 060 throw se; 061 } 062 063 /** 064 * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) 065 */ 066 public void fatalError(SAXParseException se) throws SAXException { 067 log.error("Fatal error parsing xml doc " + se.getSystemId(), se); 068 throw se; 069 } 070 }