001
014
015 package com.liferay.portlet.journalcontent.action;
016
017 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018 import com.liferay.portal.kernel.servlet.SessionErrors;
019 import com.liferay.portal.kernel.servlet.SessionMessages;
020 import com.liferay.portal.kernel.util.Constants;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portal.util.WebKeys;
025 import com.liferay.portlet.PortletPreferencesFactoryUtil;
026 import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
027
028 import javax.portlet.ActionRequest;
029 import javax.portlet.ActionResponse;
030 import javax.portlet.PortletConfig;
031 import javax.portlet.PortletPreferences;
032 import javax.portlet.RenderRequest;
033 import javax.portlet.RenderResponse;
034
035
038 public class ConfigurationActionImpl extends BaseConfigurationAction {
039
040 public void processAction(
041 PortletConfig portletConfig, ActionRequest actionRequest,
042 ActionResponse actionResponse)
043 throws Exception {
044
045 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
046
047 if (!cmd.equals(Constants.UPDATE)) {
048 return;
049 }
050
051 long groupId = ParamUtil.getLong(actionRequest, "groupId");
052 String articleId = ParamUtil.getString(
053 actionRequest, "articleId").toUpperCase();
054 String templateId = ParamUtil.getString(
055 actionRequest, "templateId").toUpperCase();
056 boolean showAvailableLocales = ParamUtil.getBoolean(
057 actionRequest, "showAvailableLocales");
058 String[] extensions = actionRequest.getParameterValues("extensions");
059 boolean enablePrint = ParamUtil.getBoolean(
060 actionRequest, "enablePrint");
061 boolean enableRatings = ParamUtil.getBoolean(
062 actionRequest, "enableRatings");
063 boolean enableComments = ParamUtil.getBoolean(
064 actionRequest, "enableComments");
065 boolean enableCommentRatings = ParamUtil.getBoolean(
066 actionRequest, "enableCommentRatings");
067
068 String portletResource = ParamUtil.getString(
069 actionRequest, "portletResource");
070
071 PortletPreferences preferences =
072 PortletPreferencesFactoryUtil.getPortletSetup(
073 actionRequest, portletResource);
074
075 preferences.setValue("group-id", String.valueOf(groupId));
076 preferences.setValue("article-id", articleId);
077 preferences.setValue("template-id", templateId);
078 preferences.setValue(
079 "show-available-locales", String.valueOf(showAvailableLocales));
080 preferences.setValues("extensions", extensions);
081 preferences.setValue("enable-print", String.valueOf(enablePrint));
082 preferences.setValue("enable-ratings", String.valueOf(enableRatings));
083 preferences.setValue("enable-comments", String.valueOf(enableComments));
084 preferences.setValue(
085 "enable-comment-ratings", String.valueOf(enableCommentRatings));
086
087 if (SessionErrors.isEmpty(actionRequest)) {
088 preferences.store();
089
090 updateContentSearch(actionRequest, portletResource, articleId);
091
092 SessionMessages.add(
093 actionRequest, portletConfig.getPortletName() + ".doConfigure");
094 }
095
096 actionResponse.sendRedirect(
097 ParamUtil.getString(actionRequest, "redirect"));
098 }
099
100 public String render(
101 PortletConfig portletConfig, RenderRequest renderRequest,
102 RenderResponse renderResponse)
103 throws Exception {
104
105 return "/html/portlet/journal_content/configuration.jsp";
106 }
107
108 protected void updateContentSearch(
109 ActionRequest actionRequest, String portletResource,
110 String articleId)
111 throws Exception {
112
113 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
114 WebKeys.THEME_DISPLAY);
115
116 Layout layout = themeDisplay.getLayout();
117
118 JournalContentSearchLocalServiceUtil.updateContentSearch(
119 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
120 portletResource, articleId, true);
121 }
122
123 }