1   /**
2    * Copyright (c) 2000-2008 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.MBThread;
32  import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
33  import com.liferay.portlet.messageboards.service.MBBanLocalServiceUtil;
34  import com.liferay.portlet.messageboards.service.MBCategoryServiceUtil;
35  import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
36  import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
37  
38  import javax.portlet.ActionRequest;
39  import javax.portlet.RenderRequest;
40  
41  import javax.servlet.http.HttpServletRequest;
42  
43  /**
44   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   *
48   */
49  public class ActionUtil {
50  
51      public static void getCategory(ActionRequest req) throws Exception {
52          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
53  
54          getCategory(httpReq);
55      }
56  
57      public static void getCategory(RenderRequest req) throws Exception {
58          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
59  
60          getCategory(httpReq);
61      }
62  
63      public static void getCategory(HttpServletRequest req) throws Exception {
64  
65          // Add redundant check here because the JSP does not check permissions
66          // on the initial search container
67  
68          ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(
69              WebKeys.THEME_DISPLAY);
70  
71          MBBanLocalServiceUtil.checkBan(
72              themeDisplay.getPortletGroupId(), themeDisplay.getUserId());
73  
74          long categoryId = ParamUtil.getLong(req, "categoryId");
75  
76          MBCategory category = null;
77  
78          if ((categoryId > 0) &&
79              (categoryId != MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
80  
81              category = MBCategoryServiceUtil.getCategory(categoryId);
82          }
83  
84          req.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category);
85      }
86  
87      public static void getMessage(ActionRequest req) throws Exception {
88          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
89  
90          getMessage(httpReq);
91      }
92  
93      public static void getMessage(RenderRequest req) throws Exception {
94          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
95  
96          getMessage(httpReq);
97      }
98  
99      public static void getMessage(HttpServletRequest req) throws Exception {
100         long messageId = ParamUtil.getLong(req, "messageId");
101 
102         MBMessage message = null;
103 
104         if (messageId > 0) {
105             message = MBMessageServiceUtil.getMessage(messageId);
106         }
107 
108         req.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
109     }
110 
111     public static void getThreadMessage(RenderRequest req) throws Exception {
112         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
113 
114         getThreadMessage(httpReq);
115     }
116 
117     public static void getThreadMessage(ActionRequest req) throws Exception {
118         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
119 
120         getThreadMessage(httpReq);
121     }
122 
123     public static void getThreadMessage(HttpServletRequest req)
124         throws Exception {
125 
126         long threadId = ParamUtil.getLong(req, "threadId");
127 
128         MBMessage message = null;
129 
130         if (threadId > 0) {
131             MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
132 
133             message = MBMessageServiceUtil.getMessage(
134                 thread.getRootMessageId());
135         }
136 
137         req.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
138     }
139 
140 }