* @throws ServletException
*/
private void performDebugMode(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws HttpErrorException, ServletException, IOException {
if (!getCore().isAdminLoggedIn(request)) {
throw new HttpErrorException(HttpServletResponse.SC_FORBIDDEN, "You must be logged in to the wga admin page to use WebTML debugging", null);
}
String command = request.getParameter("command");
Boolean debugModeEnabled = (Boolean) session.getAttribute(WGACore.ATTRIB_TMLDEBUG);
if (debugModeEnabled == null) {
debugModeEnabled = new Boolean(false);
}
Boolean resultTracingEnabled = (Boolean) session.getAttribute(WGACore.ATTRIB_TMLDEBUG_TRACE_RESULTS);
if (resultTracingEnabled == null) {
resultTracingEnabled = new Boolean(false);
}
Boolean optionsTracingEnabled = (Boolean) session.getAttribute(WGACore.ATTRIB_TMLDEBUG_TRACE_OPTIONS);
if (optionsTracingEnabled == null) {
optionsTracingEnabled = new Boolean(false);
}
Boolean tmlscriptOptimizationDisabled = (Boolean) session.getAttribute(WGACore.ATTRIB_TMLDEBUG_DISABLE_TMLSCRIPT_OPTIMIZATION);
if (tmlscriptOptimizationDisabled == null) {
tmlscriptOptimizationDisabled = new Boolean(false);
}
if (command == null) {
request.getRequestDispatcher("/tmlDebugFrameset.jsp").include(request, response);
return;
}
if (command.equalsIgnoreCase("toggledebug")) {
debugModeEnabled = new Boolean(!debugModeEnabled.booleanValue());
session.setAttribute(WGACore.ATTRIB_TMLDEBUG, debugModeEnabled);
command = "status";
}
else if (command.equalsIgnoreCase("toggleresulttrace")) {
resultTracingEnabled = new Boolean(!resultTracingEnabled.booleanValue());
session.setAttribute(WGACore.ATTRIB_TMLDEBUG_TRACE_RESULTS, resultTracingEnabled);
command = "status";
}
else if (command.equalsIgnoreCase("toggleoptionstrace")) {
optionsTracingEnabled = new Boolean(!optionsTracingEnabled.booleanValue());
session.setAttribute(WGACore.ATTRIB_TMLDEBUG_TRACE_OPTIONS, optionsTracingEnabled);
command = "status";
}
else if (command.equalsIgnoreCase("toggletmlscriptoptimization")) {
tmlscriptOptimizationDisabled = new Boolean(!tmlscriptOptimizationDisabled.booleanValue());
session.setAttribute(WGACore.ATTRIB_TMLDEBUG_DISABLE_TMLSCRIPT_OPTIMIZATION, tmlscriptOptimizationDisabled);
command = "status";
}
else if (command.equalsIgnoreCase("clearlist")) {
List debugDocuments = WGACore.getDebugDocumentsList(session);
debugDocuments.clear();
command = "list";
}
if (command.equalsIgnoreCase("toolbar")) {
request.getRequestDispatcher("/tmlDebugToolbar.jsp").include(request, response);
}
else if (command.equalsIgnoreCase("status")) {
response.getWriter().write("TMLScript stack traces are switched " + (tmlscriptOptimizationDisabled.booleanValue() ? "ON" : "OFF") + "\n");
if (debugModeEnabled.booleanValue() == true) {
response.getWriter().write("WebTML debug mode is switched ON\n");
response.getWriter().write("Result tracing is switched " + (resultTracingEnabled.booleanValue() ? "ON" : "OFF") + "\n");
response.getWriter().write("Options tracing is switched " + (optionsTracingEnabled.booleanValue() ? "ON" : "OFF") + "\n");
}
else {
response.getWriter().write("WebTML debug mode is switched OFF\n");
}
}
else if (command.equalsIgnoreCase("list")) {
if (debugModeEnabled.booleanValue() == true) {
sendDebugDocList(request, response, session);
}
else {
throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "WebTML debug mode is not enabled. First enable it via tmldebug?command=on", null);
}
}
else if (command.equalsIgnoreCase("showModules")) {
showTMLModules(request, response, session);
}
else if (command.equalsIgnoreCase("showTags")) {
showTMLTags(request, response, session);
}
else if (command.equalsIgnoreCase("show")) {
sendDebugDoc(request, response, session);
}
else {
throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "Unknown debug command: " + command, null);
}
}