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          String[] extensions = actionRequest.getParameterValues("extensions");
67          boolean enablePrint = ParamUtil.getBoolean(
68              actionRequest, "enablePrint");
69          boolean enableRatings = ParamUtil.getBoolean(
70              actionRequest, "enableRatings");
71          boolean enableComments = ParamUtil.getBoolean(
72              actionRequest, "enableComments");
73          boolean enableCommentRatings = ParamUtil.getBoolean(
74              actionRequest, "enableCommentRatings");
75  
76          String portletResource = ParamUtil.getString(
77              actionRequest, "portletResource");
78  
79          PortletPreferences preferences =
80              PortletPreferencesFactoryUtil.getPortletSetup(
81                  actionRequest, portletResource);
82  
83          preferences.setValue("group-id", String.valueOf(groupId));
84          preferences.setValue("article-id", articleId);
85          preferences.setValue("template-id", templateId);
86          preferences.setValue(
87              "show-available-locales", String.valueOf(showAvailableLocales));
88          preferences.setValues("extensions", extensions);
89          preferences.setValue("enable-print", String.valueOf(enablePrint));
90          preferences.setValue("enable-ratings", String.valueOf(enableRatings));
91          preferences.setValue("enable-comments", String.valueOf(enableComments));
92          preferences.setValue(
93              "enable-comment-ratings", String.valueOf(enableCommentRatings));
94  
95          preferences.store();
96  
97          updateContentSearch(actionRequest, portletResource, articleId);
98  
99          actionResponse.sendRedirect(
100             ParamUtil.getString(actionRequest, "redirect"));
101     }
102 
103     public String render(
104             PortletConfig portletConfig, RenderRequest renderRequest,
105             RenderResponse renderResponse)
106         throws Exception {
107 
108         return "/html/portlet/journal_content/configuration.jsp";
109     }
110 
111     protected void updateContentSearch(
112             ActionRequest actionRequest, String portletResource,
113             String articleId)
114         throws Exception {
115 
116         ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
117             WebKeys.THEME_DISPLAY);
118 
119         Layout layout = themeDisplay.getLayout();
120 
121         JournalContentSearchLocalServiceUtil.updateContentSearch(
122             layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
123             portletResource, articleId, true);
124     }
125 
126 }