View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.shared_orchestra.util.xml;
20  
21  import org.apache.commons.logging.Log;
22  import org.xml.sax.ErrorHandler;
23  import org.xml.sax.SAXParseException;
24  
25  /**
26   * Convenient error handler for xml sax parsing.
27   * @author Manfred Geiler (latest modification by $Author: grantsmith $)
28   * @version $Revision: 472630 $ $Date: 2006-11-08 15:40:03 -0500 (Wed, 08 Nov 2006) $
29   */
30  public class MyFacesErrorHandler
31          implements ErrorHandler
32  {
33      private Log _log;
34  
35      public MyFacesErrorHandler(Log log)
36      {
37          _log = log;
38      }
39  
40      public void warning(SAXParseException exception)
41      {
42          if (_log.isWarnEnabled()) _log.warn(getMessage(exception), exception);
43      }
44  
45      public void error(SAXParseException exception)
46      {
47          _log.error(getMessage(exception), exception);
48      }
49  
50      public void fatalError(SAXParseException exception)
51      {
52          _log.fatal(getMessage(exception), exception);
53      }
54  
55      private String getMessage(SAXParseException exception)
56      {
57          StringBuffer buf = new StringBuffer();
58          buf.append("SAXParseException at");
59          buf.append(" URI=");
60          buf.append(exception.getSystemId());
61          buf.append(" Line=");
62          buf.append(exception.getLineNumber());
63          buf.append(" Column=");
64          buf.append(exception.getColumnNumber());
65          return buf.toString();
66      }
67  
68  }