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