1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.language.LanguageUtil;
26  import com.liferay.portal.kernel.portlet.ConfigurationAction;
27  import com.liferay.portal.kernel.util.Constants;
28  import com.liferay.portal.kernel.util.ParamUtil;
29  import com.liferay.portal.model.Layout;
30  import com.liferay.portal.theme.ThemeDisplay;
31  import com.liferay.portal.util.WebKeys;
32  import com.liferay.portlet.PortletPreferencesFactoryUtil;
33  import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
34  import com.liferay.portlet.journalcontent.util.JournalContentUtil;
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  /**
44   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   *
48   */
49  public class ConfigurationActionImpl implements ConfigurationAction {
50  
51      public void processAction(
52              PortletConfig config, ActionRequest req, ActionResponse res)
53          throws Exception {
54  
55          String cmd = ParamUtil.getString(req, Constants.CMD);
56  
57          if (!cmd.equals(Constants.UPDATE)) {
58              return;
59          }
60  
61          ThemeDisplay themeDisplay =
62              (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
63  
64          long groupId = ParamUtil.getLong(req, "groupId");
65          String articleId = ParamUtil.getString(req, "articleId").toUpperCase();
66          String templateId = ParamUtil.getString(
67              req, "templateId").toUpperCase();
68  
69          String languageId = LanguageUtil.getLanguageId(req);
70  
71          boolean disableCaching = ParamUtil.getBoolean(req, "disableCaching");
72  
73          String content = JournalContentUtil.getContent(
74              groupId, articleId, templateId, languageId, themeDisplay,
75              disableCaching);
76  
77          boolean showAvailableLocales = ParamUtil.getBoolean(
78              req, "showAvailableLocales");
79          boolean enableRatings = ParamUtil.getBoolean(req, "enableRatings");
80          boolean enableComments = ParamUtil.getBoolean(req, "enableComments");
81  
82          String portletResource = ParamUtil.getString(req, "portletResource");
83  
84          PortletPreferences prefs =
85              PortletPreferencesFactoryUtil.getPortletSetup(
86                  req, portletResource, true, true);
87  
88          prefs.setValue("group-id", String.valueOf(groupId));
89          prefs.setValue("article-id", articleId);
90          prefs.setValue("template-id", templateId);
91          prefs.setValue("disable-caching", String.valueOf(disableCaching));
92          prefs.setValue(
93              "show-available-locales", String.valueOf(showAvailableLocales));
94          prefs.setValue("enable-ratings", String.valueOf(enableRatings));
95          prefs.setValue("enable-comments", String.valueOf(enableComments));
96  
97          prefs.store();
98  
99          updateContentSearch(req, portletResource, articleId);
100 
101         res.sendRedirect(ParamUtil.getString(req, "redirect"));
102     }
103 
104     public String render(
105             PortletConfig config, RenderRequest req, RenderResponse res)
106         throws Exception {
107 
108         return "/html/portlet/journal_content/configuration.jsp";
109     }
110 
111     protected void updateContentSearch(
112             ActionRequest req, String portletResource, String articleId)
113         throws Exception {
114 
115         ThemeDisplay themeDisplay =
116             (ThemeDisplay)req.getAttribute(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 }