KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > util > LogErrorHandler


1 /*
2  * Copyright 2005 Joe Walker
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.directwebremoting.util;
17
18 import org.xml.sax.ErrorHandler JavaDoc;
19 import org.xml.sax.SAXParseException JavaDoc;
20
21 /**
22  * An ErrorHandler that writes to the Logger class
23  * @author Joe Walker [joe at getahead dot ltd dot uk]
24  */

25 public final class LogErrorHandler implements ErrorHandler JavaDoc
26 {
27     /* (non-Javadoc)
28      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
29      */

30     public void fatalError(SAXParseException JavaDoc ex)
31     {
32         log.fatal(getMessage(ex));
33     }
34
35     /* (non-Javadoc)
36      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
37      */

38     public void error(SAXParseException JavaDoc ex)
39     {
40         log.error(getMessage(ex));
41     }
42
43     /* (non-Javadoc)
44      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
45      */

46     public void warning(SAXParseException JavaDoc ex)
47     {
48         log.warn(getMessage(ex));
49     }
50
51     /**
52      * @param ex The exception to create a message from
53      * @return A summary of what went wrong.
54      */

55     private String JavaDoc getMessage(SAXParseException JavaDoc ex)
56     {
57         if (ex.getSystemId() != null)
58         {
59             return "SystemID=" + ex.getSystemId() + " Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
60         }
61
62         if (ex.getPublicId() != null)
63         {
64             return "PublicID=" + ex.getPublicId() + " Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
65         }
66
67         return "Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
68     }
69
70     /**
71      * The log stream
72      */

73     private static final Logger log = Logger.getLogger(LogErrorHandler.class);
74 }
75
Popular Tags