1
19
20 package com.liferay.portlet.portletconfiguration.action;
21
22 import com.liferay.portal.kernel.servlet.SessionErrors;
23 import com.liferay.portal.kernel.util.ParamUtil;
24 import com.liferay.portal.model.Layout;
25 import com.liferay.portal.model.Portlet;
26 import com.liferay.portal.security.auth.PrincipalException;
27 import com.liferay.portal.theme.ThemeDisplay;
28 import com.liferay.portal.util.WebKeys;
29 import com.liferay.portlet.PortletPreferencesFactoryUtil;
30
31 import java.util.Set;
32
33 import javax.portlet.ActionRequest;
34 import javax.portlet.ActionResponse;
35 import javax.portlet.PortletConfig;
36 import javax.portlet.PortletPreferences;
37 import javax.portlet.RenderRequest;
38 import javax.portlet.RenderResponse;
39
40 import org.apache.struts.action.ActionForm;
41 import org.apache.struts.action.ActionForward;
42 import org.apache.struts.action.ActionMapping;
43
44
50 public class EditSupportedClientsAction extends EditConfigurationAction {
51
52 public void processAction(
53 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
54 ActionRequest actionRequest, ActionResponse actionResponse)
55 throws Exception {
56
57 Portlet portlet = null;
58
59 try {
60 portlet = getPortlet(actionRequest);
61 }
62 catch (PrincipalException pe) {
63 SessionErrors.add(
64 actionRequest, PrincipalException.class.getName());
65
66 setForward(actionRequest, "portlet.portlet_configuration.error");
67 }
68
69 updateSupportedClients(portlet, actionRequest);
70
71 sendRedirect(actionRequest, actionResponse);
72 }
73
74 public ActionForward render(
75 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
76 RenderRequest renderRequest, RenderResponse renderResponse)
77 throws Exception {
78
79 Portlet portlet = null;
80
81 try {
82 portlet = getPortlet(renderRequest);
83 }
84 catch (PrincipalException pe) {
85 SessionErrors.add(
86 renderRequest, PrincipalException.class.getName());
87
88 return mapping.findForward("portlet.portlet_configuration.error");
89 }
90
91 renderResponse.setTitle(getTitle(portlet, renderRequest));
92
93 return mapping.findForward(getForward(
94 renderRequest,
95 "portlet.portlet_configuration.edit_supported_clients"));
96 }
97
98 protected void updateSupportedClients(
99 Portlet portlet, ActionRequest actionRequest)
100 throws Exception {
101
102 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
103 WebKeys.THEME_DISPLAY);
104
105 Layout layout = themeDisplay.getLayout();
106
107 PortletPreferences portletSetup =
108 PortletPreferencesFactoryUtil.getLayoutPortletSetup(
109 layout, portlet.getPortletId());
110
111 Set<String> allPortletModes = portlet.getAllPortletModes();
112
113 for (String portletMode : allPortletModes) {
114 String mobileDevicesParam =
115 "portlet-setup-supported-clients-mobile-devices-" + portletMode;
116
117 boolean mobileDevices = ParamUtil.getBoolean(
118 actionRequest, mobileDevicesParam);
119
120 portletSetup.setValue(
121 mobileDevicesParam, String.valueOf(mobileDevices));
122 }
123
124 portletSetup.store();
125 }
126
127 }