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 fname, int line, int column, String errMsg,
39 Exception 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 errMsg, Exception 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[] args = null;
67 StringBuffer buf = new StringBuffer();
68
69 for (int i=0; i < details.length; i++) {
70 if (details[i].getJspBeginLineNumber() >= 0) {
71 args = new Object[] {
72 new Integer(details[i].getJspBeginLineNumber()),
73 details[i].getJspFileName() };
74 buf.append("\n\n");
75 buf.append(Localizer.getMessage("jsp.error.single.line.number",
76 args));
77 buf.append("\n");
78 buf.append(details[i].getErrorMessage());
79 buf.append("\n");
80 buf.append(details[i].getJspExtract());
81 } else {
82 args = new Object[] {
83 new Integer(details[i].getJavaLineNumber()) };
84 buf.append("\n\n");
85 buf.append(Localizer.getMessage("jsp.error.java.line.number",
86 args));
87 buf.append("\n");
88 buf.append(details[i].getErrorMessage());
89 }
90 }
91 buf.append("\n\nStacktrace:");
92 throw new JasperException(
93 Localizer.getMessage("jsp.error.unable.compile") + ": " + buf);
94 }
95
96 /**
97 * Processes the given javac error report and exception.
98 *
99 * @param errorReport Compilation error report
100 * @param exception Compilation exception
101 */
102 public void javacError(String errorReport, Exception exception)
103 throws JasperException {
104
105 throw new JasperException(
106 Localizer.getMessage("jsp.error.unable.compile"), exception);
107 }
108
109 }