KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > util > xml > MyFacesErrorHandler


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.apache.myfaces.util.xml;
17
18 import org.apache.commons.logging.Log;
19 import org.xml.sax.ErrorHandler JavaDoc;
20 import org.xml.sax.SAXParseException JavaDoc;
21
22 /**
23  * Convenient error handler for xml sax parsing.
24  * @author Manfred Geiler (latest modification by $Author: matze $)
25  * @version $Revision: 1.2 $ $Date: 2004/10/13 11:51:01 $
26  */

27 public class MyFacesErrorHandler
28         implements ErrorHandler JavaDoc
29 {
30     private Log _log;
31
32     public MyFacesErrorHandler(Log log)
33     {
34         _log = log;
35     }
36
37     public void warning(SAXParseException JavaDoc exception)
38     {
39         if (_log.isWarnEnabled()) _log.warn(getMessage(exception), exception);
40     }
41
42     public void error(SAXParseException JavaDoc exception)
43     {
44         _log.error(getMessage(exception), exception);
45     }
46
47     public void fatalError(SAXParseException JavaDoc exception)
48     {
49         _log.fatal(getMessage(exception), exception);
50     }
51
52     private String JavaDoc getMessage(SAXParseException JavaDoc exception)
53     {
54         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
55         buf.append("SAXParseException at");
56         buf.append(" URI=");
57         buf.append(exception.getSystemId());
58         buf.append(" Line=");
59         buf.append(exception.getLineNumber());
60         buf.append(" Column=");
61         buf.append(exception.getColumnNumber());
62         return buf.toString();
63     }
64
65 }
66
Popular Tags