1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portlet.wikidisplay.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.wiki.NoSuchNodeException;
24  import com.liferay.portlet.wiki.model.WikiNode;
25  import com.liferay.portlet.wiki.service.WikiNodeServiceUtil;
26  
27  import javax.portlet.ActionRequest;
28  import javax.portlet.ActionResponse;
29  import javax.portlet.PortletConfig;
30  import javax.portlet.PortletPreferences;
31  import javax.portlet.RenderRequest;
32  import javax.portlet.RenderResponse;
33  
34  /**
35   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   */
39  public class ConfigurationActionImpl extends BaseConfigurationAction {
40  
41      public void processAction(
42              PortletConfig portletConfig, ActionRequest actionRequest,
43              ActionResponse actionResponse)
44          throws Exception {
45  
46          try {
47              String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
48  
49              if (!cmd.equals(Constants.UPDATE)) {
50                  return;
51              }
52  
53              long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
54              String title = ParamUtil.getString(actionRequest, "title");
55  
56              WikiNode node = WikiNodeServiceUtil.getNode(nodeId);
57  
58              String portletResource = ParamUtil.getString(
59                  actionRequest, "portletResource");
60  
61              PortletPreferences preferences =
62                  PortletPreferencesFactoryUtil.getPortletSetup(
63                      actionRequest, portletResource);
64  
65              preferences.setValue("node-id", String.valueOf(node.getNodeId()));
66              preferences.setValue("title", title);
67  
68              preferences.store();
69  
70              SessionMessages.add(
71                  actionRequest, portletConfig.getPortletName() + ".doConfigure");
72          }
73          catch (NoSuchNodeException nsne) {
74              SessionErrors.add(actionRequest, nsne.getClass().getName());
75          }
76      }
77  
78      public String render(
79              PortletConfig portletConfig, RenderRequest renderRequest,
80              RenderResponse renderResponse)
81          throws Exception {
82  
83          return "/html/portlet/wiki_display/configuration.jsp";
84      }
85  
86  }