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.pollsdisplay.action;
24  
25  import com.liferay.portal.kernel.servlet.SessionErrors;
26  import com.liferay.portal.kernel.util.GetterUtil;
27  import com.liferay.portal.kernel.util.StringPool;
28  import com.liferay.portal.security.auth.PrincipalException;
29  import com.liferay.portal.struts.PortletAction;
30  import com.liferay.portal.util.WebKeys;
31  import com.liferay.portlet.polls.NoSuchQuestionException;
32  import com.liferay.portlet.polls.model.PollsQuestion;
33  import com.liferay.portlet.polls.service.PollsQuestionServiceUtil;
34  
35  import javax.portlet.PortletConfig;
36  import javax.portlet.PortletPreferences;
37  import javax.portlet.RenderRequest;
38  import javax.portlet.RenderResponse;
39  
40  import org.apache.struts.action.ActionForm;
41  import org.apache.struts.action.ActionForward;
42  import org.apache.struts.action.ActionMapping;
43  
44  /**
45   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Brian Wing Shun Chan
48   */
49  public class ViewAction extends PortletAction {
50  
51      public ActionForward render(
52              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
53              RenderRequest renderRequest, RenderResponse renderResponse)
54          throws Exception {
55  
56          try {
57              PortletPreferences preferences = renderRequest.getPreferences();
58  
59              long questionId = GetterUtil.getLong(
60                  preferences.getValue("question-id", StringPool.BLANK));
61  
62              PollsQuestion question =
63                  PollsQuestionServiceUtil.getQuestion(questionId);
64  
65              renderRequest.setAttribute(WebKeys.POLLS_QUESTION, question);
66  
67              return mapping.findForward("portlet.polls_display.view");
68          }
69          catch (NoSuchQuestionException nsqe) {
70              return mapping.findForward("/portal/portlet_not_setup");
71          }
72          catch (PrincipalException pe) {
73              SessionErrors.add(renderRequest, pe.getClass().getName());
74  
75              return mapping.findForward("portlet.polls_display.error");
76          }
77      }
78  
79  }