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