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.messageboards.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.theme.ThemeDisplay;
27  import com.liferay.portal.util.PortalUtil;
28  import com.liferay.portal.util.WebKeys;
29  import com.liferay.portlet.messageboards.model.MBCategory;
30  import com.liferay.portlet.messageboards.model.MBMessage;
31  import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
32  import com.liferay.portlet.messageboards.service.MBBanLocalServiceUtil;
33  import com.liferay.portlet.messageboards.service.MBCategoryServiceUtil;
34  import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
35  
36  import javax.portlet.ActionRequest;
37  import javax.portlet.RenderRequest;
38  
39  import javax.servlet.http.HttpServletRequest;
40  
41  /**
42   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
43   *
44   * @author Brian Wing Shun Chan
45   *
46   */
47  public class ActionUtil {
48  
49      public static void getCategory(ActionRequest req) throws Exception {
50          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
51  
52          getCategory(httpReq);
53      }
54  
55      public static void getCategory(RenderRequest req) throws Exception {
56          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
57  
58          getCategory(httpReq);
59      }
60  
61      public static void getCategory(HttpServletRequest req) throws Exception {
62  
63          // Add redundant check here because the JSP does not check permissions
64          // on the initial search container
65  
66          ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(
67              WebKeys.THEME_DISPLAY);
68  
69          MBBanLocalServiceUtil.checkBan(
70              themeDisplay.getPortletGroupId(), themeDisplay.getUserId());
71  
72          long categoryId = ParamUtil.getLong(req, "categoryId");
73  
74          MBCategory category = null;
75  
76          if ((categoryId > 0) &&
77              (categoryId != MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
78  
79              category = MBCategoryServiceUtil.getCategory(categoryId);
80          }
81  
82          req.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category);
83      }
84  
85      public static void getMessage(ActionRequest req) throws Exception {
86          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
87  
88          getMessage(httpReq);
89      }
90  
91      public static void getMessage(RenderRequest req) throws Exception {
92          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
93  
94          getMessage(httpReq);
95      }
96  
97      public static void getMessage(HttpServletRequest req) throws Exception {
98          long messageId = ParamUtil.getLong(req, "messageId");
99  
100         MBMessage message = null;
101 
102         if (messageId > 0) {
103             message = MBMessageServiceUtil.getMessage(messageId);
104         }
105 
106         req.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
107     }
108 
109 }