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.journalarticles.action;
21  
22  import com.liferay.portal.NoSuchGroupException;
23  import com.liferay.portal.kernel.portlet.ConfigurationAction;
24  import com.liferay.portal.kernel.servlet.SessionErrors;
25  import com.liferay.portal.kernel.servlet.SessionMessages;
26  import com.liferay.portal.kernel.util.Constants;
27  import com.liferay.portal.kernel.util.ParamUtil;
28  import com.liferay.portal.service.GroupLocalServiceUtil;
29  import com.liferay.portlet.PortletPreferencesFactoryUtil;
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 implements ConfigurationAction {
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 groupId = ParamUtil.getLong(actionRequest, "groupId");
59              String type = ParamUtil.getString(actionRequest, "type");
60              String pageURL = ParamUtil.getString(actionRequest, "pageURL");
61              int pageDelta = ParamUtil.getInteger(actionRequest, "pageDelta");
62              String orderByCol = ParamUtil.getString(
63                  actionRequest, "orderByCol");
64              String orderByType = ParamUtil.getString(
65                  actionRequest, "orderByType");
66  
67              GroupLocalServiceUtil.getGroup(groupId);
68  
69              String portletResource = ParamUtil.getString(
70                  actionRequest, "portletResource");
71  
72              PortletPreferences prefs =
73                  PortletPreferencesFactoryUtil.getPortletSetup(
74                      actionRequest, portletResource);
75  
76              prefs.setValue("group-id", String.valueOf(groupId));
77              prefs.setValue("type", type);
78              prefs.setValue("page-url", pageURL);
79              prefs.setValue("page-delta", String.valueOf(pageDelta));
80              prefs.setValue("order-by-col", orderByCol);
81              prefs.setValue("order-by-type", orderByType);
82  
83              prefs.store();
84  
85              SessionMessages.add(
86                  actionRequest, portletConfig.getPortletName() + ".doConfigure");
87          }
88          catch (NoSuchGroupException nsge) {
89              SessionErrors.add(actionRequest, nsge.getClass().getName());
90          }
91      }
92  
93      public String render(
94              PortletConfig portletConfig, RenderRequest renderRequest,
95              RenderResponse renderResponse)
96          throws Exception {
97  
98          return "/html/portlet/journal_articles/configuration.jsp";
99      }
100 
101 }