01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal;
07:
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10: import javax.servlet.http.HttpSession;
11:
12: /**
13: * This object is passed to special channels.
14: *
15: * @author Peter Kharchenko, peterk@interactivebusiness.com
16: * @version $Revision: 42516 $
17: */
18: public class PortalControlStructures {
19: //Track the current request and response in a thread local as well
20: //as the member variables. This ensures that the case of multiple
21: //request from a single user rendering at the same time is possible.
22: //The class member variables are still used as a fallback if needed.
23: protected static final ThreadLocal reqLocal = new ThreadLocal();
24: protected static final ThreadLocal resLocal = new ThreadLocal();
25:
26: protected IUserPreferencesManager ulm;
27: protected HttpServletRequest req;
28: protected HttpServletResponse res;
29: protected ChannelManager cm;
30:
31: public PortalControlStructures(HttpServletRequest req,
32: HttpServletResponse res, ChannelManager cm,
33: IUserPreferencesManager ulm) {
34: this .setHttpServletRequest(req);
35: this .setHttpServletResponse(res);
36: this .setChannelManager(cm);
37: this .setUserPreferencesManager(ulm);
38: }
39:
40: public PortalControlStructures() {
41: this (null, null, null, null);
42: }
43:
44: public IUserPreferencesManager getUserPreferencesManager() {
45: return ulm;
46: }
47:
48: public HttpServletRequest getHttpServletRequest() {
49: final HttpServletRequest localReq = (HttpServletRequest) reqLocal
50: .get();
51: if (localReq != null) {
52: return localReq;
53: }
54: return req;
55: }
56:
57: public HttpServletResponse getHttpServletResponse() {
58: final HttpServletResponse localRes = (HttpServletResponse) resLocal
59: .get();
60: if (localRes != null) {
61: return localRes;
62: }
63: return res;
64: }
65:
66: public ChannelManager getChannelManager() {
67: return cm;
68: }
69:
70: /**
71: * Convience method for getting just the HttpSession
72: * @return the session
73: */
74: public HttpSession getHttpSession() {
75: HttpSession session = null;
76: if (this .getHttpServletRequest() != null)
77: session = this .getHttpServletRequest().getSession(false);
78: return session;
79: }
80:
81: public void setUserPreferencesManager(IUserPreferencesManager lm) {
82: ulm = lm;
83: }
84:
85: public void setHttpServletRequest(HttpServletRequest r) {
86: req = r;
87: reqLocal.set(req);
88: }
89:
90: public void setHttpServletResponse(HttpServletResponse r) {
91: res = r;
92: resLocal.set(res);
93: }
94:
95: public void setChannelManager(ChannelManager m) {
96: cm = m;
97: }
98: }
|