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.documentlibrary.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.documentlibrary.NoSuchFolderException;
24  import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
25  import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
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 Jorge Ferrer
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          String folderDisplayStyle = ParamUtil.getString(
53              actionRequest, "folderDisplayStyle");
54  
55          long rootFolderId = ParamUtil.getLong(actionRequest, "rootFolderId");
56  
57          boolean showBreadcrumbs = ParamUtil.getBoolean(
58              actionRequest, "showBreadcrumbs");
59          boolean showFoldersSearch = ParamUtil.getBoolean(
60              actionRequest, "showFoldersSearch");
61          boolean showSubfolders = ParamUtil.getBoolean(
62              actionRequest, "showSubfolders");
63          int foldersPerPage = ParamUtil.getInteger(
64              actionRequest, "foldersPerPage");
65          String folderColumns = ParamUtil.getString(
66              actionRequest, "folderColumns");
67  
68          boolean showFileEntriesSearch = ParamUtil.getBoolean(
69              actionRequest, "showFileEntriesSearch");
70          int fileEntriesPerPage = ParamUtil.getInteger(
71              actionRequest, "fileEntriesPerPage");
72          String fileEntryColumns = ParamUtil.getString(
73              actionRequest, "fileEntryColumns");
74  
75          boolean enableCommentRatings = ParamUtil.getBoolean(
76              actionRequest, "enableCommentRatings");
77  
78          String portletResource = ParamUtil.getString(
79              actionRequest, "portletResource");
80  
81          PortletPreferences prefs =
82              PortletPreferencesFactoryUtil.getPortletSetup(
83                  actionRequest, portletResource);
84  
85          if (rootFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
86              try {
87                  DLFolderLocalServiceUtil.getFolder(rootFolderId);
88              }
89              catch (NoSuchFolderException e) {
90                  SessionErrors.add(actionRequest, "rootFolderIdInvalid");
91              }
92          }
93  
94          prefs.setValue("folderDisplayStyle", folderDisplayStyle);
95  
96          prefs.setValue("rootFolderId", String.valueOf(rootFolderId));
97  
98          prefs.setValue("showBreadcrumbs", String.valueOf(showBreadcrumbs));
99          prefs.setValue("showFoldersSearch", String.valueOf(showFoldersSearch));
100         prefs.setValue("showSubfolders", String.valueOf(showSubfolders));
101         prefs.setValue("foldersPerPage", String.valueOf(foldersPerPage));
102         prefs.setValue("folderColumns", folderColumns);
103 
104         prefs.setValue(
105             "showFileEntriesSearch", String.valueOf(showFileEntriesSearch));
106         prefs.setValue(
107             "fileEntriesPerPage", String.valueOf(fileEntriesPerPage));
108         prefs.setValue("fileEntryColumns", fileEntryColumns);
109 
110         prefs.setValue(
111             "enable-comment-ratings", String.valueOf(enableCommentRatings));
112 
113         if (SessionErrors.isEmpty(actionRequest)) {
114             prefs.store();
115 
116             SessionMessages.add(
117                 actionRequest, portletConfig.getPortletName() + ".doConfigure");
118         }
119     }
120 
121     public String render(
122             PortletConfig portletConfig, RenderRequest renderRequest,
123             RenderResponse renderResponse)
124         throws Exception {
125 
126         return "/html/portlet/document_library/configuration.jsp";
127     }
128 
129 }