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.pollsdisplay.action;
16  
17  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18  import com.liferay.portal.kernel.servlet.SessionErrors;
19  import com.liferay.portal.kernel.servlet.SessionMessages;
20  import com.liferay.portal.kernel.util.Constants;
21  import com.liferay.portal.kernel.util.ParamUtil;
22  import com.liferay.portlet.PortletPreferencesFactoryUtil;
23  import com.liferay.portlet.polls.NoSuchQuestionException;
24  import com.liferay.portlet.polls.service.PollsQuestionServiceUtil;
25  
26  import javax.portlet.ActionRequest;
27  import javax.portlet.ActionResponse;
28  import javax.portlet.PortletConfig;
29  import javax.portlet.PortletPreferences;
30  import javax.portlet.RenderRequest;
31  import javax.portlet.RenderResponse;
32  
33  /**
34   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   */
38  public class ConfigurationActionImpl extends BaseConfigurationAction {
39  
40      public void processAction(
41              PortletConfig portletConfig, ActionRequest actionRequest,
42              ActionResponse actionResponse)
43          throws Exception {
44  
45          try {
46              String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
47  
48              if (!cmd.equals(Constants.UPDATE)) {
49                  return;
50              }
51  
52              long questionId = ParamUtil.getLong(actionRequest, "questionId");
53  
54              PollsQuestionServiceUtil.getQuestion(questionId);
55  
56              String portletResource = ParamUtil.getString(
57                  actionRequest, "portletResource");
58  
59              PortletPreferences preferences =
60                  PortletPreferencesFactoryUtil.getPortletSetup(
61                      actionRequest, portletResource);
62  
63              preferences.setValue("question-id", String.valueOf(questionId));
64  
65              preferences.store();
66  
67              SessionMessages.add(
68                  actionRequest, portletConfig.getPortletName() + ".doConfigure");
69          }
70          catch (NoSuchQuestionException nsqe) {
71              SessionErrors.add(actionRequest, nsqe.getClass().getName());
72          }
73      }
74  
75      public String render(
76              PortletConfig portletConfig, RenderRequest renderRequest,
77              RenderResponse renderResponse)
78          throws Exception {
79  
80          return "/html/portlet/polls_display/configuration.jsp";
81      }
82  
83  }