1
19
20 package com.liferay.portlet.myplaces.action;
21
22 import com.liferay.portal.NoSuchLayoutSetException;
23 import com.liferay.portal.kernel.servlet.SessionErrors;
24 import com.liferay.portal.kernel.util.GetterUtil;
25 import com.liferay.portal.kernel.util.ParamUtil;
26 import com.liferay.portal.model.Layout;
27 import com.liferay.portal.model.LayoutConstants;
28 import com.liferay.portal.service.LayoutLocalServiceUtil;
29 import com.liferay.portal.struts.PortletAction;
30 import com.liferay.portal.theme.ThemeDisplay;
31 import com.liferay.portal.util.PortalUtil;
32 import com.liferay.portal.util.WebKeys;
33
34 import java.util.List;
35
36 import javax.portlet.ActionRequest;
37 import javax.portlet.ActionResponse;
38 import javax.portlet.PortletConfig;
39 import javax.portlet.RenderRequest;
40 import javax.portlet.RenderResponse;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44
45 import org.apache.struts.action.ActionForm;
46 import org.apache.struts.action.ActionForward;
47 import org.apache.struts.action.ActionMapping;
48
49
55 public class ViewAction extends PortletAction {
56
57 public ActionForward strutsExecute(
58 ActionMapping mapping, ActionForm form, HttpServletRequest request,
59 HttpServletResponse response)
60 throws Exception {
61
62 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
63 WebKeys.THEME_DISPLAY);
64
65 long groupId = ParamUtil.getLong(request, "groupId");
66 String privateLayoutParam = request.getParameter("privateLayout");
67
68 String redirect = getRedirect(
69 themeDisplay, groupId, privateLayoutParam);
70
71 if (redirect == null) {
72 redirect = ParamUtil.getString(request, "redirect");
73
74 SessionErrors.add(
75 request, NoSuchLayoutSetException.class.getName(),
76 new NoSuchLayoutSetException(
77 "{groupId=" + groupId + ",privateLayout=" +
78 privateLayoutParam + "}"));
79 }
80
81 response.sendRedirect(redirect);
82
83 return null;
84 }
85
86 public void processAction(
87 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
88 ActionRequest actionRequest, ActionResponse actionResponse)
89 throws Exception {
90
91 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
92 WebKeys.THEME_DISPLAY);
93
94 long groupId = ParamUtil.getLong(actionRequest, "groupId");
95 String privateLayoutParam = actionRequest.getParameter("privateLayout");
96
97 String redirect = getRedirect(
98 themeDisplay, groupId, privateLayoutParam);
99
100 if (redirect == null) {
101 redirect = ParamUtil.getString(actionRequest, "redirect");
102
103 SessionErrors.add(
104 actionRequest, NoSuchLayoutSetException.class.getName(),
105 new NoSuchLayoutSetException(
106 "{groupId=" + groupId + ",privateLayout=" +
107 privateLayoutParam + "}"));
108 }
109
110 actionResponse.sendRedirect(redirect);
111 }
112
113 public ActionForward render(
114 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
115 RenderRequest renderRequest, RenderResponse renderResponse)
116 throws Exception {
117
118 return mapping.findForward("portlet.my_places.view");
119 }
120
121 protected List<Layout> getLayouts(long groupId, boolean privateLayout)
122 throws Exception {
123
124 return LayoutLocalServiceUtil.getLayouts(
125 groupId, privateLayout, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, 0,
126 1);
127 }
128
129 protected String getRedirect(
130 ThemeDisplay themeDisplay, long groupId, String privateLayoutParam)
131 throws Exception {
132
133 List<Layout> layouts = null;
134
135 if (privateLayoutParam == null) {
136 layouts = getLayouts(groupId, false);
137
138 if (layouts.size() == 0) {
139 layouts = getLayouts(groupId, true);
140 }
141 }
142 else {
143 boolean privateLayout = GetterUtil.getBoolean(privateLayoutParam);
144
145 layouts = getLayouts(groupId, privateLayout);
146 }
147
148 String redirect = null;
149
150 if (layouts.size() > 0) {
151 Layout layout = layouts.get(0);
152
153 redirect = PortalUtil.getLayoutURL(layout, themeDisplay);
154 }
155
156 return redirect;
157 }
158
159 protected boolean isCheckMethodOnProcessAction() {
160 return _CHECK_METHOD_ON_PROCESS_ACTION;
161 }
162
163 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
164
165 }