1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.journalcontent.action;
21  
22  import com.liferay.portal.kernel.portlet.ConfigurationAction;
23  import com.liferay.portal.kernel.util.Constants;
24  import com.liferay.portal.kernel.util.ParamUtil;
25  import com.liferay.portal.model.Layout;
26  import com.liferay.portal.theme.ThemeDisplay;
27  import com.liferay.portal.util.WebKeys;
28  import com.liferay.portlet.PortletPreferencesFactoryUtil;
29  import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
30  
31  import javax.portlet.ActionRequest;
32  import javax.portlet.ActionResponse;
33  import javax.portlet.PortletConfig;
34  import javax.portlet.PortletPreferences;
35  import javax.portlet.RenderRequest;
36  import javax.portlet.RenderResponse;
37  
38  /**
39   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   *
43   */
44  public class ConfigurationActionImpl implements ConfigurationAction {
45  
46      public void processAction(
47              PortletConfig portletConfig, ActionRequest actionRequest,
48              ActionResponse actionResponse)
49          throws Exception {
50  
51          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
52  
53          if (!cmd.equals(Constants.UPDATE)) {
54              return;
55          }
56  
57          long groupId = ParamUtil.getLong(actionRequest, "groupId");
58          String articleId = ParamUtil.getString(
59              actionRequest, "articleId").toUpperCase();
60          String templateId = ParamUtil.getString(
61              actionRequest, "templateId").toUpperCase();
62          boolean showAvailableLocales = ParamUtil.getBoolean(
63              actionRequest, "showAvailableLocales");
64          boolean enableRatings = ParamUtil.getBoolean(
65              actionRequest, "enableRatings");
66          boolean enableComments = ParamUtil.getBoolean(
67              actionRequest, "enableComments");
68          boolean enableCommentRatings = ParamUtil.getBoolean(
69              actionRequest, "enableCommentRatings");
70  
71          String portletResource = ParamUtil.getString(
72              actionRequest, "portletResource");
73  
74          PortletPreferences prefs =
75              PortletPreferencesFactoryUtil.getPortletSetup(
76                  actionRequest, portletResource);
77  
78          prefs.setValue("group-id", String.valueOf(groupId));
79          prefs.setValue("article-id", articleId);
80          prefs.setValue("template-id", templateId);
81          prefs.setValue(
82              "show-available-locales", String.valueOf(showAvailableLocales));
83          prefs.setValue("enable-ratings", String.valueOf(enableRatings));
84          prefs.setValue("enable-comments", String.valueOf(enableComments));
85          prefs.setValue(
86              "enable-comment-ratings", String.valueOf(enableCommentRatings));
87  
88          prefs.store();
89  
90          updateContentSearch(actionRequest, portletResource, articleId);
91  
92          actionResponse.sendRedirect(
93              ParamUtil.getString(actionRequest, "redirect"));
94      }
95  
96      public String render(
97              PortletConfig portletConfig, RenderRequest renderRequest,
98              RenderResponse renderResponse)
99          throws Exception {
100 
101         return "/html/portlet/journal_content/configuration.jsp";
102     }
103 
104     protected void updateContentSearch(
105             ActionRequest actionRequest, String portletResource,
106             String articleId)
107         throws Exception {
108 
109         ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
110             WebKeys.THEME_DISPLAY);
111 
112         Layout layout = themeDisplay.getLayout();
113 
114         JournalContentSearchLocalServiceUtil.updateContentSearch(
115             layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
116             portletResource, articleId, true);
117     }
118 
119 }