1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.journalcontent.action;
16  
17  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18  import com.liferay.portal.kernel.servlet.SessionErrors;
19  import com.liferay.portal.kernel.servlet.SessionMessages;
20  import com.liferay.portal.kernel.util.Constants;
21  import com.liferay.portal.kernel.util.ParamUtil;
22  import com.liferay.portal.model.Layout;
23  import com.liferay.portal.theme.ThemeDisplay;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.PortletPreferencesFactoryUtil;
26  import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
27  
28  import javax.portlet.ActionRequest;
29  import javax.portlet.ActionResponse;
30  import javax.portlet.PortletConfig;
31  import javax.portlet.PortletPreferences;
32  import javax.portlet.RenderRequest;
33  import javax.portlet.RenderResponse;
34  
35  /**
36   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   */
40  public class ConfigurationActionImpl extends BaseConfigurationAction {
41  
42      public void processAction(
43              PortletConfig portletConfig, ActionRequest actionRequest,
44              ActionResponse actionResponse)
45          throws Exception {
46  
47          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
48  
49          if (!cmd.equals(Constants.UPDATE)) {
50              return;
51          }
52  
53          long groupId = ParamUtil.getLong(actionRequest, "groupId");
54          String articleId = ParamUtil.getString(
55              actionRequest, "articleId").toUpperCase();
56          String templateId = ParamUtil.getString(
57              actionRequest, "templateId").toUpperCase();
58          boolean showAvailableLocales = ParamUtil.getBoolean(
59              actionRequest, "showAvailableLocales");
60          String[] extensions = actionRequest.getParameterValues("extensions");
61          boolean enablePrint = ParamUtil.getBoolean(
62              actionRequest, "enablePrint");
63          boolean enableRatings = ParamUtil.getBoolean(
64              actionRequest, "enableRatings");
65          boolean enableComments = ParamUtil.getBoolean(
66              actionRequest, "enableComments");
67          boolean enableCommentRatings = ParamUtil.getBoolean(
68              actionRequest, "enableCommentRatings");
69  
70          String portletResource = ParamUtil.getString(
71              actionRequest, "portletResource");
72  
73          PortletPreferences preferences =
74              PortletPreferencesFactoryUtil.getPortletSetup(
75                  actionRequest, portletResource);
76  
77          preferences.setValue("group-id", String.valueOf(groupId));
78          preferences.setValue("article-id", articleId);
79          preferences.setValue("template-id", templateId);
80          preferences.setValue(
81              "show-available-locales", String.valueOf(showAvailableLocales));
82          preferences.setValues("extensions", extensions);
83          preferences.setValue("enable-print", String.valueOf(enablePrint));
84          preferences.setValue("enable-ratings", String.valueOf(enableRatings));
85          preferences.setValue("enable-comments", String.valueOf(enableComments));
86          preferences.setValue(
87              "enable-comment-ratings", String.valueOf(enableCommentRatings));
88  
89          if (SessionErrors.isEmpty(actionRequest)) {
90              preferences.store();
91  
92              updateContentSearch(actionRequest, portletResource, articleId);
93  
94              SessionMessages.add(
95                  actionRequest, portletConfig.getPortletName() + ".doConfigure");
96          }
97  
98          actionResponse.sendRedirect(
99              ParamUtil.getString(actionRequest, "redirect"));
100     }
101 
102     public String render(
103             PortletConfig portletConfig, RenderRequest renderRequest,
104             RenderResponse renderResponse)
105         throws Exception {
106 
107         return "/html/portlet/journal_content/configuration.jsp";
108     }
109 
110     protected void updateContentSearch(
111             ActionRequest actionRequest, String portletResource,
112             String articleId)
113         throws Exception {
114 
115         ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
116             WebKeys.THEME_DISPLAY);
117 
118         Layout layout = themeDisplay.getLayout();
119 
120         JournalContentSearchLocalServiceUtil.updateContentSearch(
121             layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
122             portletResource, articleId, true);
123     }
124 
125 }