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.bookmarks.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.bookmarks.model.BookmarksFolderConstants;
24  import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
25  import com.liferay.portlet.documentlibrary.NoSuchFolderException;
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 Sergio González
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          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
47  
48          if (!cmd.equals(Constants.UPDATE)) {
49              return;
50          }
51  
52          long rootFolderId = ParamUtil.getLong(actionRequest, "rootFolderId");
53  
54          boolean showFoldersSearch = ParamUtil.getBoolean(
55              actionRequest, "showFoldersSearch");
56          boolean showSubfolders = ParamUtil.getBoolean(
57              actionRequest, "showSubfolders");
58          int foldersPerPage = ParamUtil.getInteger(
59              actionRequest, "foldersPerPage");
60          String folderColumns = ParamUtil.getString(
61              actionRequest, "folderColumns");
62  
63          int entriesPerPage = ParamUtil.getInteger(
64              actionRequest, "entriesPerPage");
65          String entryColumns = ParamUtil.getString(
66              actionRequest, "entryColumns");
67  
68          String portletResource = ParamUtil.getString(
69              actionRequest, "portletResource");
70  
71          PortletPreferences preferences =
72              PortletPreferencesFactoryUtil.getPortletSetup(
73                  actionRequest, portletResource);
74  
75          if (rootFolderId != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
76              try {
77                  BookmarksFolderLocalServiceUtil.getFolder(rootFolderId);
78              }
79              catch (NoSuchFolderException e) {
80                  SessionErrors.add(actionRequest, "rootFolderIdInvalid");
81              }
82          }
83  
84          preferences.setValue("rootFolderId", String.valueOf(rootFolderId));
85  
86          preferences.setValue(
87              "showFoldersSearch", String.valueOf(showFoldersSearch));
88          preferences.setValue("showSubfolders", String.valueOf(showSubfolders));
89          preferences.setValue("foldersPerPage", String.valueOf(foldersPerPage));
90          preferences.setValue("folderColumns", folderColumns);
91  
92          preferences.setValue(
93              "entriesPerPage", String.valueOf(entriesPerPage));
94          preferences.setValue("entryColumns", entryColumns);
95  
96          if (SessionErrors.isEmpty(actionRequest)) {
97              preferences.store();
98  
99              SessionMessages.add(
100                 actionRequest, portletConfig.getPortletName() + ".doConfigure");
101         }
102     }
103 
104     public String render(
105             PortletConfig portletConfig, RenderRequest renderRequest,
106             RenderResponse renderResponse)
107         throws Exception {
108 
109         return "/html/portlet/bookmarks/configuration.jsp";
110     }
111 
112 }