KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > compiler > DefaultErrorHandler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.jasper.compiler;
19
20 import org.apache.jasper.JasperException;
21
22 /**
23  * Default implementation of ErrorHandler interface.
24  *
25  * @author Jan Luehe
26  */

27 class DefaultErrorHandler implements ErrorHandler {
28     
29     /*
30      * Processes the given JSP parse error.
31      *
32      * @param fname Name of the JSP file in which the parse error occurred
33      * @param line Parse error line number
34      * @param column Parse error column number
35      * @param errMsg Parse error message
36      * @param exception Parse exception
37      */

38     public void jspError(String JavaDoc fname, int line, int column, String JavaDoc errMsg,
39             Exception JavaDoc ex) throws JasperException {
40         throw new JasperException(fname + "(" + line + "," + column + ")"
41                 + " " + errMsg, ex);
42     }
43     
44     /*
45      * Processes the given JSP parse error.
46      *
47      * @param errMsg Parse error message
48      * @param exception Parse exception
49      */

50     public void jspError(String JavaDoc errMsg, Exception JavaDoc ex) throws JasperException {
51         throw new JasperException(errMsg, ex);
52     }
53     
54     /*
55      * Processes the given javac compilation errors.
56      *
57      * @param details Array of JavacErrorDetail instances corresponding to the
58      * compilation errors
59      */

60     public void javacError(JavacErrorDetail[] details) throws JasperException {
61         
62         if (details == null) {
63             return;
64         }
65         
66         Object JavaDoc[] args = null;
67         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
68         
69         for (int i=0; i < details.length; i++) {
70             if (details[i].getJspBeginLineNumber() >= 0) {
71                 args = new Object JavaDoc[] {
72                         new Integer JavaDoc(details[i].getJspBeginLineNumber()),
73                         details[i].getJspFileName() };
74                 buf.append(Localizer.getMessage("jsp.error.single.line.number",
75                         args));
76                 buf.append("\n");
77             }
78             
79             buf.append(
80                     Localizer.getMessage("jsp.error.corresponding.servlet"));
81             buf.append(details[i].getErrorMessage());
82             buf.append("\n\n");
83         }
84         
85         throw new JasperException(Localizer.getMessage("jsp.error.unable.compile") + "\n\n" + buf);
86     }
87     
88     /**
89      * Processes the given javac error report and exception.
90      *
91      * @param errorReport Compilation error report
92      * @param exception Compilation exception
93      */

94     public void javacError(String JavaDoc errorReport, Exception JavaDoc exception)
95     throws JasperException {
96         
97         throw new JasperException(
98                 Localizer.getMessage("jsp.error.unable.compile"), exception);
99     }
100     
101 }
102
Popular Tags