001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork;
006:
007: import com.opensymphony.xwork.ActionContext;
008: import com.opensymphony.xwork.util.OgnlValueStack;
009:
010: import javax.servlet.ServletContext;
011: import javax.servlet.http.HttpServletRequest;
012: import javax.servlet.http.HttpServletResponse;
013: import javax.servlet.jsp.PageContext;
014: import java.util.Map;
015:
016: /**
017: * Web-specific context information for actions. This class subclasses <tt>ActionContext</tt> which
018: * provides access to things like the action name, value stack, etc. This class adds access to
019: * web objects like servlet parameters, request attributes and things like the HTTP session.
020: *
021: * @author <a href="mailto:nightfal@etherlands.net">Erik Beeson</a>
022: * @author Bill Lynch (docs)
023: */
024: public class ServletActionContext extends ActionContext implements
025: WebWorkStatics {
026: public static final String WEBWORK_VALUESTACK_KEY = "webwork.valueStack";
027:
028: private ServletActionContext(Map context) {
029: super (context);
030: }
031:
032: public static ActionContext getActionContext(HttpServletRequest req) {
033: OgnlValueStack vs = getValueStack(req);
034: if (vs != null) {
035: return new ActionContext(vs.getContext());
036: } else {
037: return null;
038: }
039: }
040:
041: public static OgnlValueStack getValueStack(HttpServletRequest req) {
042: return (OgnlValueStack) req
043: .getAttribute(WEBWORK_VALUESTACK_KEY);
044: }
045:
046: /**
047: * Returns the HTTP page context.
048: *
049: * @return the HTTP page context.
050: */
051: public static PageContext getPageContext() {
052: return (PageContext) ActionContext.getContext().get(
053: PAGE_CONTEXT);
054: }
055:
056: /**
057: * Sets the HTTP servlet request object.
058: *
059: * @param request the HTTP servlet request object.
060: */
061: public static void setRequest(HttpServletRequest request) {
062: ActionContext.getContext().put(HTTP_REQUEST, request);
063: }
064:
065: /**
066: * Gets the HTTP servlet request object.
067: *
068: * @return the HTTP servlet request object.
069: */
070: public static HttpServletRequest getRequest() {
071: return (HttpServletRequest) ActionContext.getContext().get(
072: HTTP_REQUEST);
073: }
074:
075: /**
076: * Sets the HTTP servlet response object.
077: *
078: * @param response the HTTP servlet response object.
079: */
080: public static void setResponse(HttpServletResponse response) {
081: ActionContext.getContext().put(HTTP_RESPONSE, response);
082: }
083:
084: /**
085: * Gets the HTTP servlet response object.
086: *
087: * @return the HTTP servlet response object.
088: */
089: public static HttpServletResponse getResponse() {
090: return (HttpServletResponse) ActionContext.getContext().get(
091: HTTP_RESPONSE);
092: }
093:
094: /**
095: * Gets the servlet context.
096: *
097: * @return the servlet context.
098: */
099: public static ServletContext getServletContext() {
100: return (ServletContext) ActionContext.getContext().get(
101: SERVLET_CONTEXT);
102: }
103:
104: public static void setServletContext(ServletContext servletContext) {
105: ActionContext.getContext().put(SERVLET_CONTEXT, servletContext);
106: }
107: }
|