001
014
015 package com.liferay.portlet.enterpriseadmin.action;
016
017 import com.liferay.portal.kernel.servlet.SessionErrors;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.kernel.util.StringUtil;
021 import com.liferay.portal.model.Plugin;
022 import com.liferay.portal.security.auth.PrincipalException;
023 import com.liferay.portal.service.PluginSettingServiceUtil;
024 import com.liferay.portal.service.PortletServiceUtil;
025 import com.liferay.portal.struts.PortletAction;
026 import com.liferay.portal.util.PortalUtil;
027
028 import java.util.Arrays;
029
030 import javax.portlet.ActionRequest;
031 import javax.portlet.ActionResponse;
032 import javax.portlet.PortletConfig;
033 import javax.portlet.RenderRequest;
034 import javax.portlet.RenderResponse;
035
036 import org.apache.struts.action.ActionForm;
037 import org.apache.struts.action.ActionForward;
038 import org.apache.struts.action.ActionMapping;
039
040
044 public class EditPluginAction extends PortletAction {
045
046 public void processAction(
047 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
048 ActionRequest actionRequest, ActionResponse actionResponse)
049 throws Exception {
050
051 try {
052 updatePluginSetting(actionRequest);
053
054 sendRedirect(actionRequest, actionResponse);
055 }
056 catch (Exception e) {
057 if (e instanceof PrincipalException) {
058 SessionErrors.add(actionRequest, e.getClass().getName());
059
060 setForward(actionRequest, "portlet.enterprise_admin.error");
061 }
062 else {
063 throw e;
064 }
065 }
066 }
067
068 public ActionForward render(
069 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
070 RenderRequest renderRequest, RenderResponse renderResponse)
071 throws Exception {
072
073 return mapping.findForward(
074 getForward(renderRequest, "portlet.enterprise_admin.edit_plugin"));
075 }
076
077 protected void updatePluginSetting(ActionRequest actionRequest)
078 throws Exception {
079
080 long companyId = PortalUtil.getCompanyId(actionRequest);
081 String pluginId = ParamUtil.getString(actionRequest, "pluginId");
082 String pluginType = ParamUtil.getString(actionRequest, "pluginType");
083
084 String[] rolesArray = StringUtil.split(
085 ParamUtil.getString(actionRequest, "roles"), "\n");
086
087 Arrays.sort(rolesArray);
088
089 String roles = StringUtil.merge(rolesArray);
090
091 boolean active = ParamUtil.getBoolean(actionRequest, "active");
092
093 if (pluginType.equals(Plugin.TYPE_PORTLET)) {
094 String portletId = pluginId;
095
096 PortletServiceUtil.updatePortlet(
097 companyId, portletId, StringPool.BLANK, active);
098 }
099 else {
100 PluginSettingServiceUtil.updatePluginSetting(
101 companyId, pluginId, pluginType, roles, active);
102 }
103 }
104
105 }