1
22
23 package com.liferay.portlet.journalcontent.action;
24
25 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
26 import com.liferay.portal.kernel.servlet.SessionErrors;
27 import com.liferay.portal.kernel.servlet.SessionMessages;
28 import com.liferay.portal.kernel.util.Constants;
29 import com.liferay.portal.kernel.util.ParamUtil;
30 import com.liferay.portal.model.Layout;
31 import com.liferay.portal.theme.ThemeDisplay;
32 import com.liferay.portal.util.WebKeys;
33 import com.liferay.portlet.PortletPreferencesFactoryUtil;
34 import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
35
36 import javax.portlet.ActionRequest;
37 import javax.portlet.ActionResponse;
38 import javax.portlet.PortletConfig;
39 import javax.portlet.PortletPreferences;
40 import javax.portlet.RenderRequest;
41 import javax.portlet.RenderResponse;
42
43
48 public class ConfigurationActionImpl extends BaseConfigurationAction {
49
50 public void processAction(
51 PortletConfig portletConfig, ActionRequest actionRequest,
52 ActionResponse actionResponse)
53 throws Exception {
54
55 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
56
57 if (!cmd.equals(Constants.UPDATE)) {
58 return;
59 }
60
61 long groupId = ParamUtil.getLong(actionRequest, "groupId");
62 String articleId = ParamUtil.getString(
63 actionRequest, "articleId").toUpperCase();
64 String templateId = ParamUtil.getString(
65 actionRequest, "templateId").toUpperCase();
66 boolean showAvailableLocales = ParamUtil.getBoolean(
67 actionRequest, "showAvailableLocales");
68 String[] extensions = actionRequest.getParameterValues("extensions");
69 boolean enablePrint = ParamUtil.getBoolean(
70 actionRequest, "enablePrint");
71 boolean enableRatings = ParamUtil.getBoolean(
72 actionRequest, "enableRatings");
73 boolean enableComments = ParamUtil.getBoolean(
74 actionRequest, "enableComments");
75 boolean enableCommentRatings = ParamUtil.getBoolean(
76 actionRequest, "enableCommentRatings");
77
78 String portletResource = ParamUtil.getString(
79 actionRequest, "portletResource");
80
81 PortletPreferences preferences =
82 PortletPreferencesFactoryUtil.getPortletSetup(
83 actionRequest, portletResource);
84
85 preferences.setValue("group-id", String.valueOf(groupId));
86 preferences.setValue("article-id", articleId);
87 preferences.setValue("template-id", templateId);
88 preferences.setValue(
89 "show-available-locales", String.valueOf(showAvailableLocales));
90 preferences.setValues("extensions", extensions);
91 preferences.setValue("enable-print", String.valueOf(enablePrint));
92 preferences.setValue("enable-ratings", String.valueOf(enableRatings));
93 preferences.setValue("enable-comments", String.valueOf(enableComments));
94 preferences.setValue(
95 "enable-comment-ratings", String.valueOf(enableCommentRatings));
96
97 if (SessionErrors.isEmpty(actionRequest)) {
98 preferences.store();
99
100 updateContentSearch(actionRequest, portletResource, articleId);
101
102 SessionMessages.add(
103 actionRequest, portletConfig.getPortletName() + ".doConfigure");
104 }
105
106 actionResponse.sendRedirect(
107 ParamUtil.getString(actionRequest, "redirect"));
108 }
109
110 public String render(
111 PortletConfig portletConfig, RenderRequest renderRequest,
112 RenderResponse renderResponse)
113 throws Exception {
114
115 return "/html/portlet/journal_content/configuration.jsp";
116 }
117
118 protected void updateContentSearch(
119 ActionRequest actionRequest, String portletResource,
120 String articleId)
121 throws Exception {
122
123 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
124 WebKeys.THEME_DISPLAY);
125
126 Layout layout = themeDisplay.getLayout();
127
128 JournalContentSearchLocalServiceUtil.updateContentSearch(
129 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
130 portletResource, articleId, true);
131 }
132
133 }