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