001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.pollsdisplay.action;
016    
017    import com.liferay.portal.kernel.servlet.SessionErrors;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.security.auth.PrincipalException;
021    import com.liferay.portal.struts.PortletAction;
022    import com.liferay.portal.util.WebKeys;
023    import com.liferay.portlet.polls.NoSuchQuestionException;
024    import com.liferay.portlet.polls.model.PollsQuestion;
025    import com.liferay.portlet.polls.service.PollsQuestionServiceUtil;
026    
027    import javax.portlet.PortletConfig;
028    import javax.portlet.PortletPreferences;
029    import javax.portlet.RenderRequest;
030    import javax.portlet.RenderResponse;
031    
032    import org.apache.struts.action.ActionForm;
033    import org.apache.struts.action.ActionForward;
034    import org.apache.struts.action.ActionMapping;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    public class ViewAction extends PortletAction {
040    
041            public ActionForward render(
042                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
043                            RenderRequest renderRequest, RenderResponse renderResponse)
044                    throws Exception {
045    
046                    try {
047                            PortletPreferences preferences = renderRequest.getPreferences();
048    
049                            long questionId = GetterUtil.getLong(
050                                    preferences.getValue("question-id", StringPool.BLANK));
051    
052                            PollsQuestion question =
053                                    PollsQuestionServiceUtil.getQuestion(questionId);
054    
055                            renderRequest.setAttribute(WebKeys.POLLS_QUESTION, question);
056    
057                            return mapping.findForward("portlet.polls_display.view");
058                    }
059                    catch (NoSuchQuestionException nsqe) {
060                            return mapping.findForward("/portal/portlet_not_setup");
061                    }
062                    catch (PrincipalException pe) {
063                            SessionErrors.add(renderRequest, pe.getClass().getName());
064    
065                            return mapping.findForward("portlet.polls_display.error");
066                    }
067            }
068    
069    }