01: /*
02: * NonCriticalExceptionHandler.java
03: *
04: *
05: */
06:
07: package org.manentia.kasai.ui.exceptions.handlers;
08:
09: import java.util.ResourceBundle;
10:
11: import javax.servlet.ServletException;
12: import javax.servlet.http.HttpServletRequest;
13: import javax.servlet.http.HttpServletResponse;
14:
15: import org.apache.commons.lang.exception.ExceptionUtils;
16: import org.apache.struts.action.ActionForm;
17: import org.apache.struts.action.ActionForward;
18: import org.apache.struts.action.ActionMapping;
19: import org.apache.struts.action.ExceptionHandler;
20: import org.apache.struts.config.ExceptionConfig;
21: import org.manentia.kasai.Constants;
22:
23: import com.manentia.commons.configuration.Configuration;
24:
25: /**
26: *
27: * @author
28: */
29: public class DefaultExceptionHandler extends ExceptionHandler {
30:
31: public ActionForward execute(Exception ex,
32: ExceptionConfig exConfig, ActionMapping mapping,
33: ActionForm formInstance, HttpServletRequest request,
34: HttpServletResponse response) throws ServletException {
35:
36: ActionForward forward = new ActionForward(exConfig.getPath());
37:
38: String message = ex.getMessage();
39:
40: try {
41: // we hope the module programmer used a key instead of a hard coded text
42: ResourceBundle res = ResourceBundle.getBundle(
43: Constants.MESSAGES_PROPERTY_FILE, request
44: .getLocale());
45: message = res.getString(message); // dahhh ?? :)
46: } catch (Exception unhandledBastard) {
47: }
48:
49: if (Configuration.getInstance(Constants.CONFIG_PROPERTY_FILE)
50: .getInt("page.debug", 1) == 1) {
51: message += ": " + ExceptionUtils.getStackTrace(ex);
52: }
53:
54: request.setAttribute("message", message);
55:
56: request.setAttribute("errorTrace", message);
57:
58: return forward;
59: }
60: }
|