1 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 ; 11 import javax.servlet.ServletContext ; 12 import java.io.Serializable ; 13 import java.util.Map ; 14 15 25 public class PortletContext implements Serializable { 26 27 static ThreadLocal portletContextThreadLocal = new PortletContextThreadLocal(); 28 29 Map mapContext; 30 31 private static class PortletContextThreadLocal extends ThreadLocal { 32 private PortletContextThreadLocal() { 33 } 34 } 35 36 public PortletContext(Map 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 public static void setContext(PortletContext portletContext) { 54 portletContextThreadLocal.set(portletContext); 55 } 56 57 public Object get(Object key) { 58 return mapContext.get(key); 59 } 60 61 public void set(Object key, Object value) { 62 mapContext.put(key, value); 63 } 64 65 public void setActionContextMap(Map contextMap) { 66 set(WebWorkPortletStatics.ACTION_CONTEXT_MAP, contextMap); 67 } 68 69 public Map getActionContextMap() { 70 return (Map ) get(WebWorkPortletStatics.ACTION_CONTEXT_MAP); 71 } 72 73 public void setNameAction(String nameAction) { 74 set(WebWorkPortletStatics.NAME_ACTION, nameAction); 75 } 76 77 public String getNameAction() { 78 return (String ) get(WebWorkPortletStatics.NAME_ACTION); 79 } 80 81 public void setPortletContextType(String portletContextType) { 82 set(WebWorkPortletStatics.PORTLET_CONTENT_TYPE, portletContextType); 83 } 84 85 public String getPortletContextType() { 86 return (String ) get(WebWorkPortletStatics.PORTLET_CONTENT_TYPE); 87 } 88 89 public void setPortletResult(String portletResult) { 90 set(WebWorkPortletStatics.PORTLET_RESULT, portletResult); 91 } 92 93 public String getPortletResult() { 94 return (String ) get(WebWorkPortletStatics.PORTLET_RESULT); 95 } 96 97 public void setActionURL(String actionURL) { 98 set(WebWorkPortletStatics.PORTLET_ACTION_URL, actionURL); 99 } 100 101 public String getActionURL() { 102 return (String ) get(WebWorkPortletStatics.PORTLET_ACTION_URL); 103 } 104 105 public void setRunTag(String runTag) { 106 set(WebWorkPortletStatics.PORTLET_RUN_TAG, runTag); 107 } 108 109 public String getRunTag() { 110 return (String ) get(WebWorkPortletStatics.PORTLET_RUN_TAG); 111 } 112 113 public void setUserUID(String userName) { 114 set(WebWorkPortletStatics.USER_UID, userName); 115 } 116 117 public String getUserUID() { 118 return (String ) get(WebWorkPortletStatics.USER_UID); 119 } 120 121 public void setPortletInstanceUID(Integer portletInstanceUID) { 122 set(WebWorkPortletStatics.PORTLET_INSTANCE_UID, portletInstanceUID); 123 } 124 125 public Integer getPortletInstanceUID() { 126 return (Integer ) get(WebWorkPortletStatics.PORTLET_INSTANCE_UID); 127 } 128 129 public void setPortletMode(String portletMode) { 130 set(WebWorkPortletStatics.PORTLET_MODE, portletMode); 131 } 132 133 public String getPortletMode() { 134 return (String ) 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 servletConfig) { 146 set(WebWorkPortletStatics.SERVLET_CONFIG, servletConfig); 147 } 148 149 public ServletConfig getServletConfig() { 150 return (ServletConfig ) get(WebWorkPortletStatics.SERVLET_CONFIG); 151 } 152 153 public void setServletContext(ServletContext servletContext) { 155 set(WebWorkPortletStatics.SERVLET_CONTEXT, servletContext); 156 } 157 158 public ServletContext getServletContext() { 159 return (ServletContext ) get(WebWorkPortletStatics.SERVLET_CONTEXT); 160 } 161 163 171 } | Popular Tags |