001
014
015 package com.liferay.portlet.pluginsadmin.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 @Override
047 public void processAction(
048 ActionMapping actionMapping, ActionForm actionForm,
049 PortletConfig portletConfig, ActionRequest actionRequest,
050 ActionResponse actionResponse)
051 throws Exception {
052
053 try {
054 updatePluginSetting(actionRequest);
055
056 sendRedirect(actionRequest, actionResponse);
057 }
058 catch (Exception e) {
059 if (e instanceof PrincipalException) {
060 SessionErrors.add(actionRequest, e.getClass());
061
062 setForward(actionRequest, "portlet.plugins_admin.error");
063 }
064 else {
065 throw e;
066 }
067 }
068 }
069
070 @Override
071 public ActionForward render(
072 ActionMapping actionMapping, ActionForm actionForm,
073 PortletConfig portletConfig, RenderRequest renderRequest,
074 RenderResponse renderResponse)
075 throws Exception {
076
077 return actionMapping.findForward(
078 getForward(renderRequest, "portlet.plugins_admin.edit_plugin"));
079 }
080
081 protected void updatePluginSetting(ActionRequest actionRequest)
082 throws Exception {
083
084 long companyId = PortalUtil.getCompanyId(actionRequest);
085 String pluginId = ParamUtil.getString(actionRequest, "pluginId");
086 String pluginType = ParamUtil.getString(actionRequest, "pluginType");
087
088 String[] rolesArray = StringUtil.split(
089 ParamUtil.getString(actionRequest, "roles"), '\n');
090
091 Arrays.sort(rolesArray);
092
093 String roles = StringUtil.merge(rolesArray);
094
095 boolean active = ParamUtil.getBoolean(actionRequest, "active");
096
097 if (pluginType.equals(Plugin.TYPE_PORTLET)) {
098 String portletId = pluginId;
099
100 PortletServiceUtil.updatePortlet(
101 companyId, portletId, StringPool.BLANK, active);
102 }
103 else {
104 PluginSettingServiceUtil.updatePluginSetting(
105 companyId, pluginId, pluginType, roles, active);
106 }
107 }
108
109 }