// to the generated servlet class, we can't really add anything
return new JasperException(ex);
}
else {
int javaLineNumber = jspFrame.getLineNumber();
JavacErrorDetail detail = ErrorDispatcher.createJavacError(
jspFrame.getMethodName(),
this.ctxt.getCompiler().getPageNodes(),
null,
javaLineNumber);
// If the line number is less than one we couldn't find out
// where in the JSP things went wrong
int jspLineNumber = detail.getJspBeginLineNumber();
if (jspLineNumber < 1) {
throw new JasperException(ex);
}
if (options.getDisplaySourceFragment()) {
// Read both files in, so we can inspect them
String[] jspLines = readFile
(this.ctxt.getResourceAsStream(this.ctxt.getJspFile()));
String[] javaLines = readFile
(new FileInputStream(this.ctxt.getServletJavaFileName()));
// If the line contains the opening of a multi-line scriptlet
// block, then the JSP line number we got back is probably
// faulty. Scan forward to match the java line...
if (jspLines[jspLineNumber-1].lastIndexOf("<%") >
jspLines[jspLineNumber-1].lastIndexOf("%>")) {
String javaLine = javaLines[javaLineNumber-1].trim();
for (int i=jspLineNumber-1; i<jspLines.length; i++) {
if (jspLines[i].indexOf(javaLine) != -1) {
jspLineNumber = i+1;
break;
}
}
}
// copy out a fragment of JSP to display to the user
StringBuffer buffer = new StringBuffer(1024);
int startIndex = Math.max(0, jspLineNumber-1-3);
int endIndex = Math.min(jspLines.length-1, jspLineNumber-1+3);
for (int i=startIndex;i<=endIndex; ++i) {
buffer.append(i+1);
buffer.append(": ");
buffer.append(jspLines[i]);
buffer.append("\n");
}
return new JasperException(Localizer.getMessage
("jsp.exception", detail.getJspFileName(), "" + jspLineNumber) + "\n" + buffer, ex);
} else {
return new JasperException(Localizer.getMessage
("jsp.exception", detail.getJspFileName(), "" + jspLineNumber), ex);
}
}
} catch (Exception je) {
// If anything goes wrong, just revert to the original behaviour
return new JasperException(ex);