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.portlet.BaseConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionErrors;
019    import com.liferay.portal.kernel.servlet.SessionMessages;
020    import com.liferay.portal.kernel.util.Constants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portlet.PortletPreferencesFactoryUtil;
023    import com.liferay.portlet.polls.NoSuchQuestionException;
024    import com.liferay.portlet.polls.service.PollsQuestionServiceUtil;
025    
026    import javax.portlet.ActionRequest;
027    import javax.portlet.ActionResponse;
028    import javax.portlet.PortletConfig;
029    import javax.portlet.PortletPreferences;
030    import javax.portlet.RenderRequest;
031    import javax.portlet.RenderResponse;
032    
033    /**
034     * @author Brian Wing Shun Chan
035     */
036    public class ConfigurationActionImpl extends BaseConfigurationAction {
037    
038            public void processAction(
039                            PortletConfig portletConfig, ActionRequest actionRequest,
040                            ActionResponse actionResponse)
041                    throws Exception {
042    
043                    try {
044                            String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
045    
046                            if (!cmd.equals(Constants.UPDATE)) {
047                                    return;
048                            }
049    
050                            long questionId = ParamUtil.getLong(actionRequest, "questionId");
051    
052                            PollsQuestionServiceUtil.getQuestion(questionId);
053    
054                            String portletResource = ParamUtil.getString(
055                                    actionRequest, "portletResource");
056    
057                            PortletPreferences preferences =
058                                    PortletPreferencesFactoryUtil.getPortletSetup(
059                                            actionRequest, portletResource);
060    
061                            preferences.setValue("question-id", String.valueOf(questionId));
062    
063                            preferences.store();
064    
065                            SessionMessages.add(
066                                    actionRequest, portletConfig.getPortletName() + ".doConfigure");
067                    }
068                    catch (NoSuchQuestionException nsqe) {
069                            SessionErrors.add(actionRequest, nsqe.getClass().getName());
070                    }
071            }
072    
073            public String render(
074                            PortletConfig portletConfig, RenderRequest renderRequest,
075                            RenderResponse renderResponse)
076                    throws Exception {
077    
078                    return "/html/portlet/polls_display/configuration.jsp";
079            }
080    
081    }