import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.SocketTimeoutException;
+import java.text.MessageFormat;
import java.util.Locale;
import net.jaekl.qd.http.InvalidResponseException;
public class ErrorHandler {
- static final String JAVASCRIPT =
+ static final String JAVASCRIPT_PART1 =
"<SCRIPT>\n" +
" var show_hide = function() {\n" +
" var theDiv = document.getElementById('details');\n" +
" var theButton = document.getElementById('details_btn');\n" +
" if (theDiv.style.display === 'block' || theDiv.style.display === '') {\n" +
" theDiv.style.display = 'none';\n" +
- " theButton.value = 'Show details';\n" +
+ " theButton.value = '";
+ // insert "show details" text here
+ static final String JAVASCRIPT_PART2 = "';\n" +
" }\n" +
" else {\n" +
" theDiv.style.display = 'block';\n" +
- " theButton.value = 'Hide details';\n" +
+ " theButton.value = '";
+ // insert "hide details" text here
+ static final String JAVASCRIPT_PART3 = "';\n" +
" }\n" +
"}\n" +
"</SCRIPT>";
- void writeScript(PrintWriter pw) {
- pw.println(JAVASCRIPT);
+ void writeScript(PrintWriter pw, FrankBundle bundle) {
+ String javaScript = JAVASCRIPT_PART1 +
+ bundle.get(FrankBundle.SHOW_DETAILS) +
+ JAVASCRIPT_PART2 +
+ bundle.get(FrankBundle.HIDE_DETAILS) +
+ JAVASCRIPT_PART3;
+
+ pw.println(javaScript);
}
void explain(PrintWriter pw, Throwable t, FrankBundle bundle) {
bundle.get(FrankBundle.ERROR_PAGE) +
"</TITLE>");
style.writeStyle(pw);
- writeScript(pw);
+ writeScript(pw, bundle);
pw.println("</HEAD>");
pw.println("<BODY>");
// potential information leak in favour of reducing our code complexity
// and the administrator's workload.
- pw.println("<P><INPUT TYPE=\"button\" ID=\"details_btn\" VALUE=\"Show details\" ONCLICK=\"show_hide();\"/></P>");
+ pw.println("<P><INPUT TYPE=\"button\" ID=\"details_btn\" VALUE=\"" +
+ bundle.get(FrankBundle.SHOW_DETAILS) +
+ "\" ONCLICK=\"show_hide();\"/></P>");
pw.println("<P>");
pw.println("<DIV ID=\"details\" STYLE=\"display: none;\"><PRE>");
pw.println(stackTrace);
pw.println("</PRE>\n</P>\n</DIV>");
- pw.println("<P>Click <A HREF=\"/\">here</A> to return to the main page.</P>");
+
+ String returnToMainFormat = bundle.get(FrankBundle.RETURN_TO_MAIN_PAGE);
+ String returnToMain = MessageFormat.format(returnToMainFormat, "/");
+ pw.println("<P>" + returnToMain + "</P>");
pw.println("</BODY></HTML>");
}
}