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.servlet.SessionErrors;
27  import com.liferay.portal.kernel.servlet.SessionMessages;
28  import com.liferay.portal.kernel.util.Constants;
29  import com.liferay.portal.kernel.util.ParamUtil;
30  import com.liferay.portal.model.Layout;
31  import com.liferay.portal.theme.ThemeDisplay;
32  import com.liferay.portal.util.WebKeys;
33  import com.liferay.portlet.PortletPreferencesFactoryUtil;
34  import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
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  public class ConfigurationActionImpl extends BaseConfigurationAction {
49  
50      public void processAction(
51              PortletConfig portletConfig, ActionRequest actionRequest,
52              ActionResponse actionResponse)
53          throws Exception {
54  
55          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
56  
57          if (!cmd.equals(Constants.UPDATE)) {
58              return;
59          }
60  
61          long groupId = ParamUtil.getLong(actionRequest, "groupId");
62          String articleId = ParamUtil.getString(
63              actionRequest, "articleId").toUpperCase();
64          String templateId = ParamUtil.getString(
65              actionRequest, "templateId").toUpperCase();
66          boolean showAvailableLocales = ParamUtil.getBoolean(
67              actionRequest, "showAvailableLocales");
68          String[] extensions = actionRequest.getParameterValues("extensions");
69          boolean enablePrint = ParamUtil.getBoolean(
70              actionRequest, "enablePrint");
71          boolean enableRatings = ParamUtil.getBoolean(
72              actionRequest, "enableRatings");
73          boolean enableComments = ParamUtil.getBoolean(
74              actionRequest, "enableComments");
75          boolean enableCommentRatings = ParamUtil.getBoolean(
76              actionRequest, "enableCommentRatings");
77  
78          String portletResource = ParamUtil.getString(
79              actionRequest, "portletResource");
80  
81          PortletPreferences preferences =
82              PortletPreferencesFactoryUtil.getPortletSetup(
83                  actionRequest, portletResource);
84  
85          preferences.setValue("group-id", String.valueOf(groupId));
86          preferences.setValue("article-id", articleId);
87          preferences.setValue("template-id", templateId);
88          preferences.setValue(
89              "show-available-locales", String.valueOf(showAvailableLocales));
90          preferences.setValues("extensions", extensions);
91          preferences.setValue("enable-print", String.valueOf(enablePrint));
92          preferences.setValue("enable-ratings", String.valueOf(enableRatings));
93          preferences.setValue("enable-comments", String.valueOf(enableComments));
94          preferences.setValue(
95              "enable-comment-ratings", String.valueOf(enableCommentRatings));
96  
97          if (SessionErrors.isEmpty(actionRequest)) {
98              preferences.store();
99  
100             updateContentSearch(actionRequest, portletResource, articleId);
101 
102             SessionMessages.add(
103                 actionRequest, portletConfig.getPortletName() + ".doConfigure");
104         }
105 
106         actionResponse.sendRedirect(
107             ParamUtil.getString(actionRequest, "redirect"));
108     }
109 
110     public String render(
111             PortletConfig portletConfig, RenderRequest renderRequest,
112             RenderResponse renderResponse)
113         throws Exception {
114 
115         return "/html/portlet/journal_content/configuration.jsp";
116     }
117 
118     protected void updateContentSearch(
119             ActionRequest actionRequest, String portletResource,
120             String articleId)
121         throws Exception {
122 
123         ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
124             WebKeys.THEME_DISPLAY);
125 
126         Layout layout = themeDisplay.getLayout();
127 
128         JournalContentSearchLocalServiceUtil.updateContentSearch(
129             layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
130             portletResource, articleId, true);
131     }
132 
133 }