1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.blogs.action;
16  
17  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18  import com.liferay.portal.kernel.servlet.SessionMessages;
19  import com.liferay.portal.kernel.util.Constants;
20  import com.liferay.portal.kernel.util.ParamUtil;
21  import com.liferay.portlet.PortletPreferencesFactoryUtil;
22  
23  import javax.portlet.ActionRequest;
24  import javax.portlet.ActionResponse;
25  import javax.portlet.PortletConfig;
26  import javax.portlet.PortletPreferences;
27  import javax.portlet.RenderRequest;
28  import javax.portlet.RenderResponse;
29  
30  /**
31   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Jorge Ferrer
34   */
35  public class ConfigurationActionImpl extends BaseConfigurationAction {
36  
37      public void processAction(
38              PortletConfig portletConfig, ActionRequest actionRequest,
39              ActionResponse actionResponse)
40          throws Exception {
41  
42          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
43  
44          if (!cmd.equals(Constants.UPDATE)) {
45              return;
46          }
47  
48          int pageDelta = ParamUtil.getInteger(actionRequest, "pageDelta");
49          String pageDisplayStyle = ParamUtil.getString(
50              actionRequest, "pageDisplayStyle");
51          boolean enableRatings = ParamUtil.getBoolean(
52              actionRequest, "enableRatings");
53          boolean enableComments = ParamUtil.getBoolean(
54              actionRequest, "enableComments");
55          boolean enableCommentRatings = ParamUtil.getBoolean(
56              actionRequest, "enableCommentRatings");
57  
58          int rssDelta = ParamUtil.getInteger(actionRequest, "rssDelta");
59          String rssDisplayStyle = ParamUtil.getString(
60              actionRequest, "rssDisplayStyle");
61          String rssFormat = ParamUtil.getString(actionRequest, "rssFormat");
62  
63          String portletResource = ParamUtil.getString(
64              actionRequest, "portletResource");
65  
66          PortletPreferences prefs =
67              PortletPreferencesFactoryUtil.getPortletSetup(
68                  actionRequest, portletResource);
69  
70          prefs.setValue("page-delta", String.valueOf(pageDelta));
71          prefs.setValue("page-display-style", pageDisplayStyle);
72          prefs.setValue("enable-ratings", String.valueOf(enableRatings));
73          prefs.setValue("enable-comments", String.valueOf(enableComments));
74          prefs.setValue(
75              "enable-comment-ratings", String.valueOf(enableCommentRatings));
76  
77          prefs.setValue("rss-delta", String.valueOf(rssDelta));
78          prefs.setValue("rss-display-style", rssDisplayStyle);
79          prefs.setValue("rss-format", rssFormat);
80  
81          prefs.store();
82  
83          SessionMessages.add(
84              actionRequest, portletConfig.getPortletName() + ".doConfigure");
85      }
86  
87      public String render(
88              PortletConfig portletConfig, RenderRequest renderRequest,
89              RenderResponse renderResponse)
90          throws Exception {
91  
92          return "/html/portlet/blogs/configuration.jsp";
93      }
94  
95  }