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