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
53 public class EditSupportedClientsAction extends EditConfigurationAction {
54
55 public void processAction(
56 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
57 ActionRequest actionRequest, ActionResponse actionResponse)
58 throws Exception {
59
60 Portlet portlet = null;
61
62 try {
63 portlet = getPortlet(actionRequest);
64 }
65 catch (PrincipalException pe) {
66 SessionErrors.add(
67 actionRequest, PrincipalException.class.getName());
68
69 setForward(actionRequest, "portlet.portlet_configuration.error");
70 }
71
72 updateSupportedClients(portlet, actionRequest);
73
74 sendRedirect(actionRequest, actionResponse);
75 }
76
77 public ActionForward render(
78 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
79 RenderRequest renderRequest, RenderResponse renderResponse)
80 throws Exception {
81
82 Portlet portlet = null;
83
84 try {
85 portlet = getPortlet(renderRequest);
86 }
87 catch (PrincipalException pe) {
88 SessionErrors.add(
89 renderRequest, PrincipalException.class.getName());
90
91 return mapping.findForward("portlet.portlet_configuration.error");
92 }
93
94 renderResponse.setTitle(getTitle(portlet, renderRequest));
95
96 return mapping.findForward(getForward(
97 renderRequest,
98 "portlet.portlet_configuration.edit_supported_clients"));
99 }
100
101 protected void updateSupportedClients(
102 Portlet portlet, ActionRequest actionRequest)
103 throws Exception {
104
105 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
106 WebKeys.THEME_DISPLAY);
107
108 Layout layout = themeDisplay.getLayout();
109
110 PortletPreferences portletSetup =
111 PortletPreferencesFactoryUtil.getLayoutPortletSetup(
112 layout, portlet.getPortletId());
113
114 Set<String> allPortletModes = portlet.getAllPortletModes();
115
116 for (String portletMode : allPortletModes) {
117 String mobileDevicesParam =
118 "portlet-setup-supported-clients-mobile-devices-" + portletMode;
119
120 boolean mobileDevices = ParamUtil.getBoolean(
121 actionRequest, mobileDevicesParam);
122
123 portletSetup.setValue(
124 mobileDevicesParam, String.valueOf(mobileDevices));
125 }
126
127 portletSetup.store();
128 }
129
130 }