001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.portletconfiguration.action;
022:
023: import com.liferay.portal.kernel.security.permission.ActionKeys;
024: import com.liferay.portal.kernel.security.permission.PermissionChecker;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.model.Portlet;
027: import com.liferay.portal.security.auth.PrincipalException;
028: import com.liferay.portal.service.PortletLocalServiceUtil;
029: import com.liferay.portal.service.permission.PortletPermissionUtil;
030: import com.liferay.portal.struts.PortletAction;
031: import com.liferay.portal.theme.ThemeDisplay;
032: import com.liferay.portal.util.WebKeys;
033: import com.liferay.portlet.PortletPreferencesFactoryUtil;
034: import com.liferay.util.servlet.SessionErrors;
035:
036: import java.util.Iterator;
037: import java.util.Set;
038:
039: import javax.portlet.ActionRequest;
040: import javax.portlet.ActionResponse;
041: import javax.portlet.PortletConfig;
042: import javax.portlet.PortletPreferences;
043: import javax.portlet.PortletRequest;
044: import javax.portlet.RenderRequest;
045: import javax.portlet.RenderResponse;
046:
047: import org.apache.struts.action.ActionForm;
048: import org.apache.struts.action.ActionForward;
049: import org.apache.struts.action.ActionMapping;
050:
051: /**
052: * <a href="EditSupportedClientsAction.java.html"><b><i>View Source</i></b></a>
053: *
054: * @author Brian Wing Shun Chan
055: *
056: */
057: public class EditSupportedClientsAction extends PortletAction {
058:
059: public void processAction(ActionMapping mapping, ActionForm form,
060: PortletConfig config, ActionRequest req, ActionResponse res)
061: throws Exception {
062:
063: try {
064: checkPermissions(req);
065: } catch (PrincipalException pe) {
066: return;
067: }
068:
069: updateSupportedClients(req);
070:
071: String redirect = ParamUtil.getString(req,
072: "supportedClientsRedirect");
073:
074: sendRedirect(req, res, redirect);
075: }
076:
077: public ActionForward render(ActionMapping mapping, ActionForm form,
078: PortletConfig config, RenderRequest req, RenderResponse res)
079: throws Exception {
080:
081: try {
082: checkPermissions(req);
083: } catch (PrincipalException pe) {
084: SessionErrors.add(req, PrincipalException.class.getName());
085:
086: return mapping
087: .findForward("portlet.portlet_configuration.error");
088: }
089:
090: return mapping
091: .findForward("portlet.portlet_configuration.edit_supported_clients");
092: }
093:
094: protected void checkPermissions(PortletRequest req)
095: throws Exception {
096: ThemeDisplay themeDisplay = (ThemeDisplay) req
097: .getAttribute(WebKeys.THEME_DISPLAY);
098:
099: PermissionChecker permissionChecker = themeDisplay
100: .getPermissionChecker();
101:
102: String portletId = ParamUtil.getString(req, "portletResource");
103:
104: if (!PortletPermissionUtil.contains(permissionChecker,
105: themeDisplay.getPlid(), portletId,
106: ActionKeys.CONFIGURATION)) {
107:
108: throw new PrincipalException();
109: }
110: }
111:
112: protected void updateSupportedClients(ActionRequest req)
113: throws Exception {
114:
115: ThemeDisplay themeDisplay = (ThemeDisplay) req
116: .getAttribute(WebKeys.THEME_DISPLAY);
117:
118: String portletResource = ParamUtil.getString(req,
119: "portletResource");
120:
121: PortletPreferences portletSetup = PortletPreferencesFactoryUtil
122: .getPortletSetup(req, portletResource, true, true);
123:
124: Portlet portlet = PortletLocalServiceUtil.getPortletById(
125: themeDisplay.getCompanyId(), portletResource);
126:
127: Set allPortletModes = portlet.getAllPortletModes();
128:
129: Iterator itr = allPortletModes.iterator();
130:
131: while (itr.hasNext()) {
132: String portletMode = (String) itr.next();
133:
134: String mobileDevicesParam = "portlet-setup-supported-clients-mobile-devices-"
135: + portletMode;
136:
137: boolean mobileDevices = ParamUtil.getBoolean(req,
138: mobileDevicesParam);
139:
140: portletSetup.setValue(mobileDevicesParam, String
141: .valueOf(mobileDevices));
142: }
143:
144: portletSetup.store();
145: }
146:
147: }
|