1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.messageboards.action;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.theme.ThemeDisplay;
19  import com.liferay.portal.util.PortalUtil;
20  import com.liferay.portal.util.WebKeys;
21  import com.liferay.portlet.messageboards.model.MBCategory;
22  import com.liferay.portlet.messageboards.model.MBMessage;
23  import com.liferay.portlet.messageboards.model.MBThread;
24  import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
25  import com.liferay.portlet.messageboards.service.MBBanLocalServiceUtil;
26  import com.liferay.portlet.messageboards.service.MBCategoryServiceUtil;
27  import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
28  import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
29  
30  import javax.portlet.ActionRequest;
31  import javax.portlet.RenderRequest;
32  
33  import javax.servlet.http.HttpServletRequest;
34  
35  /**
36   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   */
40  public class ActionUtil {
41  
42      public static void getCategory(ActionRequest actionRequest)
43          throws Exception {
44  
45          HttpServletRequest request = PortalUtil.getHttpServletRequest(
46              actionRequest);
47  
48          getCategory(request);
49      }
50  
51      public static void getCategory(RenderRequest renderRequest)
52          throws Exception {
53  
54          HttpServletRequest request = PortalUtil.getHttpServletRequest(
55              renderRequest);
56  
57          getCategory(request);
58      }
59  
60      public static void getCategory(HttpServletRequest request)
61          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)request.getAttribute(
67              WebKeys.THEME_DISPLAY);
68  
69          MBBanLocalServiceUtil.checkBan(
70              themeDisplay.getScopeGroupId(), themeDisplay.getUserId());
71  
72          long categoryId = ParamUtil.getLong(request, "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          request.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category);
83      }
84  
85      public static void getMessage(ActionRequest actionRequest)
86          throws Exception {
87  
88          HttpServletRequest request = PortalUtil.getHttpServletRequest(
89              actionRequest);
90  
91          getMessage(request);
92      }
93  
94      public static void getMessage(RenderRequest renderRequest)
95          throws Exception {
96  
97          HttpServletRequest request = PortalUtil.getHttpServletRequest(
98              renderRequest);
99  
100         getMessage(request);
101     }
102 
103     public static void getMessage(HttpServletRequest request) throws Exception {
104         long messageId = ParamUtil.getLong(request, "messageId");
105 
106         MBMessage message = null;
107 
108         if (messageId > 0) {
109             message = MBMessageServiceUtil.getMessage(messageId);
110         }
111 
112         request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
113     }
114 
115     public static void getThreadMessage(ActionRequest actionRequest)
116         throws Exception {
117 
118         HttpServletRequest request = PortalUtil.getHttpServletRequest(
119             actionRequest);
120 
121         getThreadMessage(request);
122     }
123 
124     public static void getThreadMessage(RenderRequest renderRequest)
125         throws Exception {
126 
127         HttpServletRequest request = PortalUtil.getHttpServletRequest(
128             renderRequest);
129 
130         getThreadMessage(request);
131     }
132 
133     public static void getThreadMessage(HttpServletRequest request)
134         throws Exception {
135 
136         long threadId = ParamUtil.getLong(request, "threadId");
137 
138         MBMessage message = null;
139 
140         if (threadId > 0) {
141             MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
142 
143             message = MBMessageServiceUtil.getMessage(
144                 thread.getRootMessageId());
145         }
146 
147         request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
148     }
149 
150 }