001
014
015 package com.liferay.portlet.journalcontent.action;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
020 import com.liferay.portal.kernel.portlet.PortletLayoutListener;
021 import com.liferay.portal.kernel.servlet.SessionErrors;
022 import com.liferay.portal.kernel.transaction.Isolation;
023 import com.liferay.portal.kernel.transaction.Propagation;
024 import com.liferay.portal.kernel.transaction.Transactional;
025 import com.liferay.portal.kernel.util.ParamUtil;
026 import com.liferay.portal.kernel.util.ServiceBeanMethodInvocationFactoryUtil;
027 import com.liferay.portal.kernel.util.StringUtil;
028 import com.liferay.portal.kernel.util.Validator;
029 import com.liferay.portal.model.Layout;
030 import com.liferay.portal.model.Portlet;
031 import com.liferay.portal.service.PortletLocalServiceUtil;
032 import com.liferay.portal.theme.ThemeDisplay;
033 import com.liferay.portal.util.WebKeys;
034
035 import java.lang.reflect.Method;
036
037 import javax.portlet.ActionRequest;
038 import javax.portlet.ActionResponse;
039 import javax.portlet.PortletConfig;
040 import javax.portlet.PortletPreferences;
041 import javax.portlet.PortletRequest;
042
043
048 public class ConfigurationActionImpl extends DefaultConfigurationAction {
049
050 public ConfigurationActionImpl() {
051 try {
052 Class<?> clazz = getClass();
053
054 _doProcessActionMethod = clazz.getDeclaredMethod(
055 "doProcessAction",
056 new Class<?>[] {
057 PortletConfig.class, ActionRequest.class,
058 ActionResponse.class
059 });
060 }
061 catch (Exception e) {
062 _log.error(e, e);
063 }
064 }
065
066 @Override
067 public void processAction(
068 PortletConfig portletConfig, ActionRequest actionRequest,
069 ActionResponse actionResponse)
070 throws Exception {
071
072
073
074
075 ServiceBeanMethodInvocationFactoryUtil.proceed(
076 this, ConfigurationActionImpl.class, _doProcessActionMethod,
077 new Object[] {portletConfig, actionRequest, actionResponse},
078 new String[] {"transactionAdvice"});
079 }
080
081
086 @Transactional(
087 isolation = Isolation.PORTAL, propagation = Propagation.REQUIRES_NEW,
088 rollbackFor = {Exception.class}
089 )
090 protected void doProcessAction(
091 PortletConfig portletConfig, ActionRequest actionRequest,
092 ActionResponse actionResponse)
093 throws Exception {
094
095 String[] extensions = actionRequest.getParameterValues("extensions");
096
097 setPreference(actionRequest, "extensions", extensions);
098
099 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
100 WebKeys.THEME_DISPLAY);
101
102 Layout layout = themeDisplay.getLayout();
103
104 String portletResource = ParamUtil.getString(
105 actionRequest, "portletResource");
106
107 PortletPreferences preferences = actionRequest.getPreferences();
108
109 String articleId = getArticleId(actionRequest);
110
111 String originalArticleId = preferences.getValue("articleId", null);
112
113 Portlet portlet = PortletLocalServiceUtil.getPortletById(
114 themeDisplay.getCompanyId(), portletResource);
115
116 PortletLayoutListener portletLayoutListener =
117 portlet.getPortletLayoutListenerInstance();
118
119 if ((portletLayoutListener != null) &&
120 Validator.isNotNull(originalArticleId) &&
121 !originalArticleId.equals(articleId)) {
122
123
124
125 portletLayoutListener.onRemoveFromLayout(
126 portletResource, layout.getPlid());
127 }
128
129
130
131 super.processAction(portletConfig, actionRequest, actionResponse);
132
133 if (SessionErrors.isEmpty(actionRequest) &&
134 (portletLayoutListener != null)) {
135
136
137
138 portletLayoutListener.onAddToLayout(
139 portletResource, layout.getPlid());
140 }
141 }
142
143 protected String getArticleId(PortletRequest portletRequest) {
144 String articleId = getParameter(portletRequest, "articleId");
145
146 return StringUtil.toUpperCase(articleId);
147 }
148
149 private static Log _log = LogFactoryUtil.getLog(
150 ConfigurationActionImpl.class);
151
152 private Method _doProcessActionMethod;
153
154 }