1
22
23 package com.liferay.portlet.portletconfiguration.action;
24
25 import com.liferay.portal.kernel.util.ParamUtil;
26 import com.liferay.portal.model.Layout;
27 import com.liferay.portal.model.Portlet;
28 import com.liferay.portal.security.auth.PrincipalException;
29 import com.liferay.portal.security.permission.ActionKeys;
30 import com.liferay.portal.security.permission.PermissionChecker;
31 import com.liferay.portal.service.PortletLocalServiceUtil;
32 import com.liferay.portal.service.permission.PortletPermissionUtil;
33 import com.liferay.portal.struts.PortletAction;
34 import com.liferay.portal.theme.ThemeDisplay;
35 import com.liferay.portal.util.WebKeys;
36 import com.liferay.portlet.PortletPreferencesFactoryUtil;
37 import com.liferay.util.servlet.SessionErrors;
38
39 import java.util.Set;
40
41 import javax.portlet.ActionRequest;
42 import javax.portlet.ActionResponse;
43 import javax.portlet.PortletConfig;
44 import javax.portlet.PortletPreferences;
45 import javax.portlet.PortletRequest;
46 import javax.portlet.RenderRequest;
47 import javax.portlet.RenderResponse;
48
49 import org.apache.struts.action.ActionForm;
50 import org.apache.struts.action.ActionForward;
51 import org.apache.struts.action.ActionMapping;
52
53
59 public class EditSupportedClientsAction extends PortletAction {
60
61 public void processAction(
62 ActionMapping mapping, ActionForm form, PortletConfig config,
63 ActionRequest req, ActionResponse res)
64 throws Exception {
65
66 try {
67 checkPermissions(req);
68 }
69 catch (PrincipalException pe) {
70 return;
71 }
72
73 updateSupportedClients(req);
74
75 String redirect = ParamUtil.getString(req, "supportedClientsRedirect");
76
77 sendRedirect(req, res, redirect);
78 }
79
80 public ActionForward render(
81 ActionMapping mapping, ActionForm form, PortletConfig config,
82 RenderRequest req, RenderResponse res)
83 throws Exception {
84
85 try {
86 checkPermissions(req);
87 }
88 catch (PrincipalException pe) {
89 SessionErrors.add(req, PrincipalException.class.getName());
90
91 return mapping.findForward("portlet.portlet_configuration.error");
92 }
93
94 return mapping.findForward(
95 "portlet.portlet_configuration.edit_supported_clients");
96 }
97
98 protected void checkPermissions(PortletRequest req) throws Exception {
99 ThemeDisplay themeDisplay =
100 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
101
102 PermissionChecker permissionChecker =
103 themeDisplay.getPermissionChecker();
104
105 String portletId = ParamUtil.getString(req, "portletResource");
106
107 if (!PortletPermissionUtil.contains(
108 permissionChecker, themeDisplay.getPlid(), portletId,
109 ActionKeys.CONFIGURATION)) {
110
111 throw new PrincipalException();
112 }
113 }
114
115 protected void updateSupportedClients(ActionRequest req)
116 throws Exception {
117
118 ThemeDisplay themeDisplay =
119 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
120
121 Layout layout = themeDisplay.getLayout();
122
123 String portletResource = ParamUtil.getString(req, "portletResource");
124
125 PortletPreferences portletSetup =
126 PortletPreferencesFactoryUtil.getPortletSetup(
127 layout, portletResource);
128
129 Portlet portlet = PortletLocalServiceUtil.getPortletById(
130 themeDisplay.getCompanyId(), portletResource);
131
132 Set<String> allPortletModes = portlet.getAllPortletModes();
133
134 for (String portletMode : allPortletModes) {
135 String mobileDevicesParam =
136 "portlet-setup-supported-clients-mobile-devices-" + portletMode;
137
138 boolean mobileDevices = ParamUtil.getBoolean(
139 req, mobileDevicesParam);
140
141 portletSetup.setValue(
142 mobileDevicesParam, String.valueOf(mobileDevices));
143 }
144
145 portletSetup.store();
146 }
147
148 }