1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.pollsdisplay.action;
21  
22  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
23  import com.liferay.portal.kernel.servlet.SessionErrors;
24  import com.liferay.portal.kernel.servlet.SessionMessages;
25  import com.liferay.portal.kernel.util.Constants;
26  import com.liferay.portal.kernel.util.ParamUtil;
27  import com.liferay.portlet.PortletPreferencesFactoryUtil;
28  import com.liferay.portlet.polls.NoSuchQuestionException;
29  import com.liferay.portlet.polls.service.PollsQuestionServiceUtil;
30  
31  import javax.portlet.ActionRequest;
32  import javax.portlet.ActionResponse;
33  import javax.portlet.PortletConfig;
34  import javax.portlet.PortletPreferences;
35  import javax.portlet.RenderRequest;
36  import javax.portlet.RenderResponse;
37  
38  /**
39   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   *
43   */
44  public class ConfigurationActionImpl extends BaseConfigurationAction {
45  
46      public void processAction(
47              PortletConfig portletConfig, ActionRequest actionRequest,
48              ActionResponse actionResponse)
49          throws Exception {
50  
51          try {
52              String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
53  
54              if (!cmd.equals(Constants.UPDATE)) {
55                  return;
56              }
57  
58              long questionId = ParamUtil.getLong(actionRequest, "questionId");
59  
60              PollsQuestionServiceUtil.getQuestion(questionId);
61  
62              String portletResource = ParamUtil.getString(
63                  actionRequest, "portletResource");
64  
65              PortletPreferences preferences =
66                  PortletPreferencesFactoryUtil.getPortletSetup(
67                      actionRequest, portletResource);
68  
69              preferences.setValue("question-id", String.valueOf(questionId));
70  
71              preferences.store();
72  
73              SessionMessages.add(
74                  actionRequest, portletConfig.getPortletName() + ".doConfigure");
75          }
76          catch (NoSuchQuestionException nsqe) {
77              SessionErrors.add(actionRequest, nsqe.getClass().getName());
78          }
79      }
80  
81      public String render(
82              PortletConfig portletConfig, RenderRequest renderRequest,
83              RenderResponse renderResponse)
84          throws Exception {
85  
86          return "/html/portlet/polls_display/configuration.jsp";
87      }
88  
89  }