001: //package javax.servlet.jsp;
002: package clime.messadmin.model;
003:
004: import java.io.Serializable;
005: import java.util.Date;
006:
007: import javax.servlet.ServletRequest;
008: import javax.servlet.http.HttpServletRequest;
009:
010: import clime.messadmin.utils.SessionUtils;
011:
012: /**
013: * Contains information about an error, for error pages. The information
014: * contained in this instance is meaningless if not used in the context of an
015: * error page. To indicate a JSP is an error page, the page author must set the
016: * isErrorPage attribute of the page directive to "true".
017: *
018: * @see javax.servlet.jsp.PageContext#getErrorData
019: * @since JSP 2.0
020: * @author Cédrik LIME
021: */
022: public final class ErrorData implements Serializable {
023:
024: protected Throwable throwable;
025: // protected int statusCode;
026: protected String uri;
027: // protected String servletName;
028:
029: private long date;
030:
031: /**
032: * Creates a new ErrorData object.
033: *
034: * @param throwable The Throwable that is the cause of the error
035: * @param statusCode The status code of the error
036: * @param uri The request URI
037: * @param servletName The name of the servlet invoked
038: */
039: public ErrorData(Throwable throwable, int statusCode, String uri,
040: String servletName) {
041: this .throwable = throwable;
042: // this.statusCode = statusCode;
043: this .uri = uri;
044: // this.servletName = servletName;
045: this .date = System.currentTimeMillis();
046: }
047:
048: /**
049: * Creates a new ErrorData object.
050: *
051: * @param request The ServletRequest to extract information from
052: */
053: public ErrorData(ServletRequest request) {
054: // Servlet 2.2
055: // Integer statusCodeInt = (Integer) request.getAttribute("javax.servlet.error.status_code");
056: // this.statusCode = (statusCodeInt == null ? 0 : statusCodeInt.intValue());//$NON-NLS-1$
057: /*
058: * With the introduction of the exception object to the attributes list for version
059: * 2.3 of this specification, the exception type and error message attributes are
060: * redundant. They are retained for backwards compatibility with earlier versions of
061: * the API.
062: */
063: //Class exceptionType = (Class) request.getAttribute("javax.servlet.error.exception_type");//$NON-NLS-1$
064: /** the exception message, passed to the exception constructor */
065: //String message = (String) request.getAttribute("javax.servlet.error.message");//$NON-NLS-1$
066: // Servlet 2.3
067: this .throwable = (Throwable) request
068: .getAttribute("javax.servlet.error.exception");//$NON-NLS-1$
069: if (this .throwable == null) {
070: this .throwable = (Throwable) request
071: .getAttribute("javax.servlet.jsp.jspException");//$NON-NLS-1$
072: }
073: this .uri = (String) request
074: .getAttribute("javax.servlet.error.request_uri");//$NON-NLS-1$
075: // this.servletName = (String) request.getAttribute("javax.servlet.error.servlet_name");//$NON-NLS-1$
076: this .date = System.currentTimeMillis();
077: }
078:
079: /**
080: * Creates a new ErrorData object.
081: *
082: * @param request The ServletRequest to extract information from
083: * @param t The Throwable that is the cause of the error
084: */
085: public ErrorData(HttpServletRequest request, Throwable t) {
086: this (request);
087: if (throwable == null) {
088: throwable = t;
089: }
090: if (uri == null) {
091: uri = SessionUtils
092: .getRequestURLWithMethodAndQueryString(request);
093: }
094: // if (statusCode == 0) {
095: // statusCode = response.getStatus();
096: // }
097: }
098:
099: /**
100: * Returns the Throwable that caused the error.
101: *
102: * @return The Throwable that caused the error
103: */
104: public Throwable getThrowable() {
105: return throwable;
106: }
107:
108: /**
109: * Returns the status code of the error.
110: *
111: * @return The status code of the error
112: */
113: // public int getStatusCode() {
114: // return statusCode;
115: // }
116: /**
117: * Returns the request URI.
118: *
119: * @return The request URI
120: */
121: public String getRequestURI() {
122: return uri;
123: }
124:
125: /**
126: * Returns the name of the servlet invoked.
127: *
128: * @return The name of the servlet invoked
129: */
130: // public String getServletName() {
131: // return servletName;
132: // }
133: /**
134: * @return Returns the date.
135: */
136: public Date getDate() {
137: return new Date(date);
138: }
139: }
|