001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.jasper.compiler;
019:
020: import org.apache.jasper.JasperException;
021:
022: /**
023: * Default implementation of ErrorHandler interface.
024: *
025: * @author Jan Luehe
026: */
027: class DefaultErrorHandler implements ErrorHandler {
028:
029: /*
030: * Processes the given JSP parse error.
031: *
032: * @param fname Name of the JSP file in which the parse error occurred
033: * @param line Parse error line number
034: * @param column Parse error column number
035: * @param errMsg Parse error message
036: * @param exception Parse exception
037: */
038: public void jspError(String fname, int line, int column,
039: String errMsg, Exception ex) throws JasperException {
040: throw new JasperException(fname + "(" + line + "," + column
041: + ")" + " " + errMsg, ex);
042: }
043:
044: /*
045: * Processes the given JSP parse error.
046: *
047: * @param errMsg Parse error message
048: * @param exception Parse exception
049: */
050: public void jspError(String errMsg, Exception ex)
051: throws JasperException {
052: throw new JasperException(errMsg, ex);
053: }
054:
055: /*
056: * Processes the given javac compilation errors.
057: *
058: * @param details Array of JavacErrorDetail instances corresponding to the
059: * compilation errors
060: */
061: public void javacError(JavacErrorDetail[] details)
062: throws JasperException {
063:
064: if (details == null) {
065: return;
066: }
067:
068: Object[] args = null;
069: StringBuffer buf = new StringBuffer();
070:
071: for (int i = 0; i < details.length; i++) {
072: if (details[i].getJspBeginLineNumber() >= 0) {
073: args = new Object[] {
074: new Integer(details[i].getJspBeginLineNumber()),
075: details[i].getJspFileName() };
076: buf.append("\n\n");
077: buf.append(Localizer.getMessage(
078: "jsp.error.single.line.number", args));
079: buf.append("\n");
080: buf.append(details[i].getErrorMessage());
081: buf.append("\n");
082: buf.append(details[i].getJspExtract());
083: } else {
084: args = new Object[] { new Integer(details[i]
085: .getJavaLineNumber()) };
086: buf.append("\n\n");
087: buf.append(Localizer.getMessage(
088: "jsp.error.java.line.number", args));
089: buf.append("\n");
090: buf.append(details[i].getErrorMessage());
091: }
092: }
093: buf.append("\n\nStacktrace:");
094: throw new JasperException(Localizer
095: .getMessage("jsp.error.unable.compile")
096: + ": " + buf);
097: }
098:
099: /**
100: * Processes the given javac error report and exception.
101: *
102: * @param errorReport Compilation error report
103: * @param exception Compilation exception
104: */
105: public void javacError(String errorReport, Exception exception)
106: throws JasperException {
107:
108: throw new JasperException(Localizer
109: .getMessage("jsp.error.unable.compile"), exception);
110: }
111:
112: }
|