KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > portlet > context > PortletContext


1 /*
2  * Copyright (c) 2005 Opensymphony. All Rights Reserved.
3  */

4 package com.opensymphony.webwork.portlet.context;
5
6 import com.opensymphony.module.sitemesh.Factory;
7 import com.opensymphony.webwork.portlet.WebWorkPortletStatics;
8 import com.opensymphony.xwork.util.OgnlValueStack;
9
10 import javax.servlet.ServletConfig JavaDoc;
11 import javax.servlet.ServletContext JavaDoc;
12 import java.io.Serializable JavaDoc;
13 import java.util.Map JavaDoc;
14
15 /**
16  * We should get PortletContext object in all running scope.
17  * PortletContext must add Serializable interface, because
18  * processAction & doView in JetSpeed/Tomcat ware belong to two
19  * difference threads. We should use PortletSession as bridge to
20  * transfer PortletContext between these two threads.
21  *
22  * @author <a HREF="mailto:hu_pengfei@yahoo.com.cn">Henry Hu </a>
23  * @since 2005-7-18
24  */

25 public class PortletContext implements Serializable JavaDoc {
26
27     static ThreadLocal JavaDoc portletContextThreadLocal = new PortletContextThreadLocal();
28
29     Map JavaDoc mapContext;
30
31     private static class PortletContextThreadLocal extends ThreadLocal JavaDoc {
32         private PortletContextThreadLocal() {
33         }
34     }
35
36     public PortletContext(Map JavaDoc mapContext) {
37         this.mapContext = mapContext;
38     }
39
40     public static PortletContext getContext() {
41         PortletContext portletContext = (PortletContext) portletContextThreadLocal.get();
42
43         if (portletContext == null) {
44             OgnlValueStack vs = new OgnlValueStack();
45             portletContext = new PortletContext(vs.getContext());
46             portletContextThreadLocal.set(portletContext);
47         }
48
49         return portletContext;
50     }
51
52     ///////////////Fix for JetSpeed/Tomcat////////////////////
53
public static void setContext(PortletContext portletContext) {
54         portletContextThreadLocal.set(portletContext);
55     }
56
57     public Object JavaDoc get(Object JavaDoc key) {
58         return mapContext.get(key);
59     }
60
61     public void set(Object JavaDoc key, Object JavaDoc value) {
62         mapContext.put(key, value);
63     }
64
65     public void setActionContextMap(Map JavaDoc contextMap) {
66         set(WebWorkPortletStatics.ACTION_CONTEXT_MAP, contextMap);
67     }
68
69     public Map JavaDoc getActionContextMap() {
70         return (Map JavaDoc) get(WebWorkPortletStatics.ACTION_CONTEXT_MAP);
71     }
72
73     public void setNameAction(String JavaDoc nameAction) {
74         set(WebWorkPortletStatics.NAME_ACTION, nameAction);
75     }
76
77     public String JavaDoc getNameAction() {
78         return (String JavaDoc) get(WebWorkPortletStatics.NAME_ACTION);
79     }
80
81     public void setPortletContextType(String JavaDoc portletContextType) {
82         set(WebWorkPortletStatics.PORTLET_CONTENT_TYPE, portletContextType);
83     }
84
85     public String JavaDoc getPortletContextType() {
86         return (String JavaDoc) get(WebWorkPortletStatics.PORTLET_CONTENT_TYPE);
87     }
88
89     public void setPortletResult(String JavaDoc portletResult) {
90         set(WebWorkPortletStatics.PORTLET_RESULT, portletResult);
91     }
92
93     public String JavaDoc getPortletResult() {
94         return (String JavaDoc) get(WebWorkPortletStatics.PORTLET_RESULT);
95     }
96
97     public void setActionURL(String JavaDoc actionURL) {
98         set(WebWorkPortletStatics.PORTLET_ACTION_URL, actionURL);
99     }
100
101     public String JavaDoc getActionURL() {
102         return (String JavaDoc) get(WebWorkPortletStatics.PORTLET_ACTION_URL);
103     }
104
105     public void setRunTag(String JavaDoc runTag) {
106         set(WebWorkPortletStatics.PORTLET_RUN_TAG, runTag);
107     }
108
109     public String JavaDoc getRunTag() {
110         return (String JavaDoc) get(WebWorkPortletStatics.PORTLET_RUN_TAG);
111     }
112
113     public void setUserUID(String JavaDoc userName) {
114         set(WebWorkPortletStatics.USER_UID, userName);
115     }
116
117     public String JavaDoc getUserUID() {
118         return (String JavaDoc) get(WebWorkPortletStatics.USER_UID);
119     }
120
121     public void setPortletInstanceUID(Integer JavaDoc portletInstanceUID) {
122         set(WebWorkPortletStatics.PORTLET_INSTANCE_UID, portletInstanceUID);
123     }
124
125     public Integer JavaDoc getPortletInstanceUID() {
126         return (Integer JavaDoc) get(WebWorkPortletStatics.PORTLET_INSTANCE_UID);
127     }
128
129     public void setPortletMode(String JavaDoc portletMode) {
130         set(WebWorkPortletStatics.PORTLET_MODE, portletMode);
131     }
132
133     public String JavaDoc getPortletMode() {
134         return (String JavaDoc) get(WebWorkPortletStatics.PORTLET_MODE);
135     }
136
137     public void setSiteMeshFactory(Factory factory) {
138         set(WebWorkPortletStatics.SITEMESH_FACTORY, factory);
139     }
140
141     public Factory getSiteMeshFactory() {
142         return (Factory) get(WebWorkPortletStatics.SITEMESH_FACTORY);
143     }
144
145     public void setServletConfig(ServletConfig JavaDoc servletConfig) {
146         set(WebWorkPortletStatics.SERVLET_CONFIG, servletConfig);
147     }
148
149     public ServletConfig JavaDoc getServletConfig() {
150         return (ServletConfig JavaDoc) get(WebWorkPortletStatics.SERVLET_CONFIG);
151     }
152
153     //////////////////////////////Fix for JetSpeed/Tomcat /////////////////////////
154
public void setServletContext(ServletContext JavaDoc servletContext) {
155         set(WebWorkPortletStatics.SERVLET_CONTEXT, servletContext);
156     }
157
158     public ServletContext JavaDoc getServletContext() {
159         return (ServletContext JavaDoc) get(WebWorkPortletStatics.SERVLET_CONTEXT);
160     }
161     ////////////////////////////////////////////////////////////////////////////////
162

163 // public void setActionExecuted(String actionExecuted) {
164
// set(WebWorkPortletStatics.ACTION_EXECUTED, actionExecuted);
165
// }
166
//
167
// public String getActionExecuted() {
168
// return (String) get(WebWorkPortletStatics.ACTION_EXECUTED);
169
// }
170

171 }
Popular Tags