1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.polls.action;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.util.PortalUtil;
19  import com.liferay.portal.util.WebKeys;
20  import com.liferay.portlet.polls.model.PollsQuestion;
21  import com.liferay.portlet.polls.service.PollsQuestionServiceUtil;
22  
23  import javax.portlet.ActionRequest;
24  import javax.portlet.RenderRequest;
25  
26  import javax.servlet.http.HttpServletRequest;
27  
28  /**
29   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class ActionUtil {
34  
35      public static void getQuestion(ActionRequest actionRequest)
36          throws Exception {
37  
38          HttpServletRequest request = PortalUtil.getHttpServletRequest(
39              actionRequest);
40  
41          getQuestion(request);
42      }
43  
44      public static void getQuestion(RenderRequest renderRequest)
45          throws Exception {
46  
47          HttpServletRequest request = PortalUtil.getHttpServletRequest(
48              renderRequest);
49  
50          getQuestion(request);
51      }
52  
53      public static void getQuestion(HttpServletRequest request)
54          throws Exception {
55  
56          long questionId = ParamUtil.getLong(request, "questionId");
57  
58          PollsQuestion question = null;
59  
60          if (questionId > 0) {
61              question = PollsQuestionServiceUtil.getQuestion(questionId);
62          }
63  
64          request.setAttribute(WebKeys.POLLS_QUESTION, question);
65      }
66  
67  }