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.enterpriseadmin.action;
022:
023: import com.liferay.portal.kernel.util.ParamUtil;
024: import com.liferay.portal.kernel.util.StringUtil;
025: import com.liferay.portal.model.impl.PortletImpl;
026: import com.liferay.portal.security.auth.PrincipalException;
027: import com.liferay.portal.service.PluginSettingServiceUtil;
028: import com.liferay.portal.service.PortletServiceUtil;
029: import com.liferay.portal.struts.PortletAction;
030: import com.liferay.portal.util.PortalUtil;
031: import com.liferay.util.servlet.SessionErrors;
032:
033: import java.util.Arrays;
034:
035: import javax.portlet.ActionRequest;
036: import javax.portlet.ActionResponse;
037: import javax.portlet.PortletConfig;
038: import javax.portlet.RenderRequest;
039: import javax.portlet.RenderResponse;
040:
041: import org.apache.struts.action.ActionForm;
042: import org.apache.struts.action.ActionForward;
043: import org.apache.struts.action.ActionMapping;
044:
045: /**
046: * <a href="EditPluginAction.java.html"><b><i>View Source</i></b></a>
047: *
048: * @author Brian Wing Shun Chan
049: * @author Jorge Ferrer
050: *
051: */
052: public class EditPluginAction extends PortletAction {
053:
054: public void processAction(ActionMapping mapping, ActionForm form,
055: PortletConfig config, ActionRequest req, ActionResponse res)
056: throws Exception {
057:
058: try {
059: updatePluginSetting(req);
060:
061: sendRedirect(req, res);
062: } catch (Exception e) {
063: if (e instanceof PrincipalException) {
064: SessionErrors.add(req, e.getClass().getName());
065:
066: setForward(req, "portlet.enterprise_admin.error");
067: } else {
068: throw e;
069: }
070: }
071: }
072:
073: public ActionForward render(ActionMapping mapping, ActionForm form,
074: PortletConfig config, RenderRequest req, RenderResponse res)
075: throws Exception {
076:
077: return mapping.findForward(getForward(req,
078: "portlet.enterprise_admin.edit_plugin"));
079: }
080:
081: protected void updatePluginSetting(ActionRequest req)
082: throws Exception {
083: long companyId = PortalUtil.getCompanyId(req);
084: String pluginId = ParamUtil.getString(req, "pluginId");
085: String pluginType = ParamUtil.getString(req, "pluginType");
086:
087: String[] rolesArray = StringUtil.split(ParamUtil.getString(req,
088: "roles"), "\n");
089:
090: Arrays.sort(rolesArray);
091:
092: String roles = StringUtil.merge(rolesArray);
093:
094: boolean active = ParamUtil.getBoolean(req, "active");
095:
096: if (pluginType.equals(PortletImpl.PLUGIN_TYPE)) {
097: String portletId = pluginId;
098:
099: PortletServiceUtil.updatePortlet(companyId, portletId,
100: roles, active);
101: } else {
102: PluginSettingServiceUtil.updatePluginSetting(companyId,
103: pluginId, pluginType, roles, active);
104: }
105: }
106:
107: }
|