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.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  public class ActionUtil {
49  
50      public static void getCategory(ActionRequest actionRequest)
51          throws Exception {
52  
53          HttpServletRequest request = PortalUtil.getHttpServletRequest(
54              actionRequest);
55  
56          getCategory(request);
57      }
58  
59      public static void getCategory(RenderRequest renderRequest)
60          throws Exception {
61  
62          HttpServletRequest request = PortalUtil.getHttpServletRequest(
63              renderRequest);
64  
65          getCategory(request);
66      }
67  
68      public static void getCategory(HttpServletRequest request)
69          throws Exception {
70  
71          // Add redundant check here because the JSP does not check permissions
72          // on the initial search container
73  
74          ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
75              WebKeys.THEME_DISPLAY);
76  
77          MBBanLocalServiceUtil.checkBan(
78              themeDisplay.getScopeGroupId(), themeDisplay.getUserId());
79  
80          long categoryId = ParamUtil.getLong(request, "categoryId");
81  
82          MBCategory category = null;
83  
84          if ((categoryId > 0) &&
85              (categoryId != MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
86  
87              category = MBCategoryServiceUtil.getCategory(categoryId);
88          }
89  
90          request.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category);
91      }
92  
93      public static void getMessage(ActionRequest actionRequest)
94          throws Exception {
95  
96          HttpServletRequest request = PortalUtil.getHttpServletRequest(
97              actionRequest);
98  
99          getMessage(request);
100     }
101 
102     public static void getMessage(RenderRequest renderRequest)
103         throws Exception {
104 
105         HttpServletRequest request = PortalUtil.getHttpServletRequest(
106             renderRequest);
107 
108         getMessage(request);
109     }
110 
111     public static void getMessage(HttpServletRequest request) throws Exception {
112         long messageId = ParamUtil.getLong(request, "messageId");
113 
114         MBMessage message = null;
115 
116         if (messageId > 0) {
117             message = MBMessageServiceUtil.getMessage(messageId);
118         }
119 
120         request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
121     }
122 
123     public static void getThreadMessage(ActionRequest actionRequest)
124         throws Exception {
125 
126         HttpServletRequest request = PortalUtil.getHttpServletRequest(
127             actionRequest);
128 
129         getThreadMessage(request);
130     }
131 
132     public static void getThreadMessage(RenderRequest renderRequest)
133         throws Exception {
134 
135         HttpServletRequest request = PortalUtil.getHttpServletRequest(
136             renderRequest);
137 
138         getThreadMessage(request);
139     }
140 
141     public static void getThreadMessage(HttpServletRequest request)
142         throws Exception {
143 
144         long threadId = ParamUtil.getLong(request, "threadId");
145 
146         MBMessage message = null;
147 
148         if (threadId > 0) {
149             MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
150 
151             message = MBMessageServiceUtil.getMessage(
152                 thread.getRootMessageId());
153         }
154 
155         request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
156     }
157 
158 }