public void setDetailLevel(ErrorDetailLevel detailLevel) {
this.detailLevel = detailLevel;
}
public String handleException(String controlTarget, Exception e) {
ErrorDetailLevel detailLevel = getDetailLevel();
switch (detailLevel) {
case throwException:
return null;
case quiet:
return EMPTY_STRING;
default:
break;
}
StringWriter buf = new StringWriter();
PrintWriter pw = new PrintWriter(buf);
Formatter fmt = new Formatter(pw);
fmt.format("<!-- control failed: target=%s, exceptionType=%s -->", controlTarget, e.getClass().getName());
switch (detailLevel) {
case messageOnly:
fmt.format("<div class=\"%s\">", getErrorTagClass());
String msg = e.getMessage();
if (isEmpty(msg)) {
msg = e.getClass().getSimpleName();
}
pw.append(escapeHtml(msg)); // !!��Ҫ��escapeHtml
pw.append("</div>");
break;
case stackTrace:
fmt.format("<div class=\"%s\">", getErrorTagClass());
pw.append(ExceptionUtil.getStackTraceForHtmlComment(e)); // !!��Ҫ��escapeHtml
pw.append("</div>");
break;
case comment:
pw.append("<!-- stacktrace: \n");
pw.append(ExceptionUtil.getStackTraceForHtmlComment(e)); // !!��Ҫ��escapeHtml
pw.append("-->");
break;
default:
unreachableCode(detailLevel.name());
}
pw.flush();
return buf.toString();
}