Source code: org/apache/jasper/compiler/DefaultErrorHandler.java
1 /*
2 * Copyright 1999,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
17 package org.apache.jasper.compiler;
18
19 import org.apache.jasper.JasperException;
20
21 /**
22 * Default implementation of ErrorHandler interface.
23 *
24 * @author Jan Luehe
25 */
26 class DefaultErrorHandler implements ErrorHandler {
27
28 /*
29 * Processes the given JSP parse error.
30 *
31 * @param fname Name of the JSP file in which the parse error occurred
32 * @param line Parse error line number
33 * @param column Parse error column number
34 * @param errMsg Parse error message
35 * @param exception Parse exception
36 */
37 public void jspError(String fname, int line, int column, String errMsg,
38 Exception ex) throws JasperException {
39 throw new JasperException(fname + "(" + line + "," + column + ")"
40 + " " + errMsg, ex);
41 }
42
43 /*
44 * Processes the given JSP parse error.
45 *
46 * @param errMsg Parse error message
47 * @param exception Parse exception
48 */
49 public void jspError(String errMsg, Exception ex) throws JasperException {
50 throw new JasperException(errMsg, ex);
51 }
52
53 /*
54 * Processes the given javac compilation errors.
55 *
56 * @param details Array of JavacErrorDetail instances corresponding to the
57 * compilation errors
58 */
59 public void javacError(JavacErrorDetail[] details) throws JasperException {
60
61 if (details == null) {
62 return;
63 }
64
65 Object[] args = null;
66 StringBuffer buf = new StringBuffer();
67
68 for (int i=0; i < details.length; i++) {
69 if (details[i].getJspBeginLineNumber() >= 0) {
70 args = new Object[] {
71 new Integer(details[i].getJspBeginLineNumber()),
72 details[i].getJspFileName() };
73 buf.append(Localizer.getMessage("jsp.error.single.line.number",
74 args));
75 buf.append("\n");
76 }
77
78 buf.append(
79 Localizer.getMessage("jsp.error.corresponding.servlet"));
80 buf.append(details[i].getErrorMessage());
81 buf.append("\n\n");
82 }
83
84 throw new JasperException(Localizer.getMessage("jsp.error.unable.compile") + "\n\n" + buf);
85 }
86
87 /**
88 * Processes the given javac error report and exception.
89 *
90 * @param errorReport Compilation error report
91 * @param exception Compilation exception
92 */
93 public void javacError(String errorReport, Exception exception)
94 throws JasperException {
95
96 throw new JasperException(
97 Localizer.getMessage("jsp.error.unable.compile"), exception);
98 }
99
100 }