View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.ken.util;
17  
18  import org.apache.log4j.Logger;
19  import org.xml.sax.ErrorHandler;
20  import org.xml.sax.SAXException;
21  import org.xml.sax.SAXParseException;
22  
23  /**
24   * A simple SAX ErrorHandler implementation that logs to a global logger for this
25   * class, or the one provided.
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class SimpleErrorHandler implements ErrorHandler {
29      private static final Logger LOG = Logger.getLogger(SimpleErrorHandler.class);
30  
31      private final Logger log;
32  
33      /**
34       * Constructs a SimpleErrorHandler.java.
35       */
36      public SimpleErrorHandler() {
37          this.log = LOG;
38      }
39  
40      /**
41       * Constructs a SimpleErrorHandler.java.
42       * @param log
43       */
44      public SimpleErrorHandler(Logger log) {
45          this.log = log;
46      }
47  
48      /**
49       * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
50       */
51      public void warning(SAXParseException se) {
52          log.warn("Warning parsing xml doc " + se.getSystemId(), se);
53      }
54  
55      /**
56       * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
57       */
58      public void error(SAXParseException se) throws SAXException {
59          log.error("Error parsing xml doc " + se.getSystemId(), se);
60          throw se;
61      }
62  
63      /**
64       * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
65       */
66      public void fatalError(SAXParseException se) throws SAXException {
67          log.error("Fatal error parsing xml doc " + se.getSystemId(), se);
68          throw se;
69      }
70  }