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