1
22
23
41
42 package com.liferay.portal.portletcontainer;
43
44 import com.liferay.portal.kernel.portlet.LiferayPortletMode;
45 import com.liferay.portal.kernel.portlet.LiferayWindowState;
46 import com.liferay.portal.kernel.util.ReleaseInfo;
47 import com.liferay.portal.model.Portlet;
48 import com.liferay.portal.wsrp.WSRPFactoryUtil;
49
50 import com.sun.portal.container.ChannelMode;
51 import com.sun.portal.container.ChannelState;
52 import com.sun.portal.container.ChannelURLFactory;
53 import com.sun.portal.container.Container;
54 import com.sun.portal.container.ContainerFactory;
55 import com.sun.portal.container.ContainerRequest;
56 import com.sun.portal.container.ContainerType;
57 import com.sun.portal.container.EntityID;
58 import com.sun.portal.container.ExecuteActionRequest;
59 import com.sun.portal.container.GetMarkupRequest;
60 import com.sun.portal.container.GetResourceRequest;
61 import com.sun.portal.container.PortletWindowContext;
62 import com.sun.portal.container.WindowRequestReader;
63
64 import java.util.ArrayList;
65 import java.util.List;
66
67 import javax.portlet.PortletMode;
68 import javax.portlet.PortletRequest;
69 import javax.portlet.WindowState;
70
71 import javax.servlet.http.HttpServletRequest;
72
73
80 public class ContainerRequestFactory {
81
82 static List<ChannelMode> portletModes = new ArrayList<ChannelMode>();
83 static List<ChannelState> windowStates = new ArrayList<ChannelState>();
84
85 static {
86 portletModes.add(ChannelMode.EDIT);
87 portletModes.add(ChannelMode.HELP);
88 portletModes.add(ChannelMode.VIEW);
89 portletModes.add(
90 new ChannelMode(LiferayPortletMode.ABOUT.toString()));
91 portletModes.add(
92 new ChannelMode(LiferayPortletMode.CONFIG.toString()));
93 portletModes.add(
94 new ChannelMode(LiferayPortletMode.EDIT_DEFAULTS.toString()));
95 portletModes.add(
96 new ChannelMode(LiferayPortletMode.PREVIEW.toString()));
97 portletModes.add(
98 new ChannelMode(LiferayPortletMode.PRINT.toString()));
99
100 windowStates.add(ChannelState.MAXIMIZED);
101 windowStates.add(ChannelState.MINIMIZED);
102 windowStates.add(ChannelState.NORMAL);
103 windowStates.add(
104 new ChannelState(LiferayWindowState.EXCLUSIVE.toString()));
105 windowStates.add(
106 new ChannelState(LiferayWindowState.POP_UP.toString()));
107 }
108
109 public static ExecuteActionRequest createExecuteActionRequest(
110 HttpServletRequest request, Portlet portlet,
111 WindowState windowState, PortletMode portletMode,
112 long plid, boolean facesPortlet, boolean remotePortlet)
113 throws Exception {
114
115 return (ExecuteActionRequest)_createContainerRequest(
116 request, portlet, windowState, portletMode, plid,
117 facesPortlet, remotePortlet, PortletRequest.ACTION_PHASE);
118 }
119
120 public static GetMarkupRequest createGetMarkUpRequest(
121 HttpServletRequest request, Portlet portlet,
122 WindowState windowState, PortletMode portletMode,
123 long plid, boolean facesPortlet, boolean remotePortlet)
124 throws Exception {
125
126 return (GetMarkupRequest)_createContainerRequest(
127 request, portlet, windowState, portletMode, plid,
128 facesPortlet, remotePortlet, PortletRequest.RENDER_PHASE);
129 }
130
131 public static GetResourceRequest createGetResourceRequest(
132 HttpServletRequest request, Portlet portlet,
133 WindowState windowState, PortletMode portletMode,
134 long plid, boolean facesPortlet, boolean remotePortlet)
135 throws Exception {
136
137 return (GetResourceRequest)_createContainerRequest(
138 request, portlet, windowState, portletMode, plid,
139 facesPortlet, remotePortlet, PortletRequest.RESOURCE_PHASE);
140 }
141
142 private static ContainerRequest _createContainerRequest(
143 HttpServletRequest request, Portlet portlet,
144 WindowState windowState, PortletMode portletMode,
145 long plid, boolean facesPortlet, boolean remotePortlet,
146 String lifecycle)
147 throws Exception {
148
149 EntityID entityID = WindowInvokerUtil.getEntityID(portlet);
150
151 ChannelState channelWindowState = new ChannelState(
152 windowState.toString());
153
154 ChannelMode channelPortletMode = new ChannelMode(
155 portletMode.toString());
156
157 PortletWindowContext portletWindowContext =
158 PortletWindowContextFactoryUtil.create(request, portlet, lifecycle);
159
160 ChannelURLFactory channelURLFactory = null;
161
162 if (!remotePortlet) {
163 channelURLFactory = new PortletWindowURLFactory(
164 request, portlet, channelWindowState, channelPortletMode, plid);
165 }
166 else {
167 channelURLFactory = WSRPFactoryUtil.getWindowChannelURLFactory(
168 request, portlet, channelWindowState, channelPortletMode, plid);
169 }
170
171 WindowRequestReader windowRequestReader = null;
172
173 if (lifecycle.equals(PortletRequest.ACTION_PHASE) ||
174 lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
175
176 if (!remotePortlet) {
177 windowRequestReader = new PortletWindowRequestReader(
178 facesPortlet);
179 }
180 else {
181 windowRequestReader = WSRPFactoryUtil.getWindowRequestReader();
182 }
183
184 ChannelState newWindowState =
185 windowRequestReader.readNewWindowState(request);
186
187 if (newWindowState != null) {
188 channelWindowState = newWindowState;
189 }
190
191 ChannelMode newPortletWindowMode =
192 windowRequestReader.readNewPortletWindowMode(request);
193
194 if (newPortletWindowMode != null) {
195 channelPortletMode = newPortletWindowMode;
196 }
197 }
198
199 Container container = null;
200
201 if (remotePortlet) {
202 container = WSRPFactoryUtil.getContainer();
203 }
204 else {
205 container = ContainerFactory.getContainer(
206 ContainerType.PORTLET_CONTAINER);
207 }
208
209 ContainerRequest containerRequest = null;
210
211 if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
212 containerRequest = container.createExecuteActionRequest(
213 request, entityID, channelWindowState, channelPortletMode,
214 portletWindowContext, channelURLFactory, windowRequestReader);
215 }
216 else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
217 containerRequest = container.createGetMarkUpRequest(
218 request, entityID, channelWindowState, channelPortletMode,
219 portletWindowContext, channelURLFactory);
220 }
221 else if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
222 containerRequest = container.createGetResourceRequest(
223 request, entityID, channelWindowState, channelPortletMode,
224 portletWindowContext, channelURLFactory, windowRequestReader);
225 }
226
227 if (containerRequest != null) {
228 String namespace = WindowInvokerUtil.getPortletNamespace(
229 entityID);
230
231 String windowID = WindowInvokerUtil.getPortletWindowID(
232 entityID, plid);
233
234 containerRequest.setAllowableWindowStates(windowStates);
235 containerRequest.setAllowableChannelModes(portletModes);
236 containerRequest.setNamespace(namespace);
237 containerRequest.setPortalInfo(ReleaseInfo.getReleaseInfo());
238 containerRequest.setWindowID(windowID);
239 }
240
241 return containerRequest;
242 }
243
244 }