001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.bookmarks.action;
016    
017    import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionErrors;
019    import com.liferay.portal.kernel.servlet.SessionMessages;
020    import com.liferay.portal.kernel.util.Constants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portlet.PortletPreferencesFactoryUtil;
023    import com.liferay.portlet.bookmarks.model.BookmarksFolderConstants;
024    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
025    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
026    
027    import javax.portlet.ActionRequest;
028    import javax.portlet.ActionResponse;
029    import javax.portlet.PortletConfig;
030    import javax.portlet.PortletPreferences;
031    import javax.portlet.RenderRequest;
032    import javax.portlet.RenderResponse;
033    
034    /**
035     * @author Sergio González
036     */
037    public class ConfigurationActionImpl extends BaseConfigurationAction {
038    
039            public void processAction(
040                            PortletConfig portletConfig, ActionRequest actionRequest,
041                            ActionResponse actionResponse)
042                    throws Exception {
043    
044                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
045    
046                    if (!cmd.equals(Constants.UPDATE)) {
047                            return;
048                    }
049    
050                    long rootFolderId = ParamUtil.getLong(actionRequest, "rootFolderId");
051    
052                    boolean showFoldersSearch = ParamUtil.getBoolean(
053                            actionRequest, "showFoldersSearch");
054                    boolean showSubfolders = ParamUtil.getBoolean(
055                            actionRequest, "showSubfolders");
056                    int foldersPerPage = ParamUtil.getInteger(
057                            actionRequest, "foldersPerPage");
058                    String folderColumns = ParamUtil.getString(
059                            actionRequest, "folderColumns");
060    
061                    int entriesPerPage = ParamUtil.getInteger(
062                            actionRequest, "entriesPerPage");
063                    String entryColumns = ParamUtil.getString(
064                            actionRequest, "entryColumns");
065    
066                    String portletResource = ParamUtil.getString(
067                            actionRequest, "portletResource");
068    
069                    PortletPreferences preferences =
070                            PortletPreferencesFactoryUtil.getPortletSetup(
071                                    actionRequest, portletResource);
072    
073                    if (rootFolderId != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
074                            try {
075                                    BookmarksFolderLocalServiceUtil.getFolder(rootFolderId);
076                            }
077                            catch (NoSuchFolderException e) {
078                                    SessionErrors.add(actionRequest, "rootFolderIdInvalid");
079                            }
080                    }
081    
082                    preferences.setValue("rootFolderId", String.valueOf(rootFolderId));
083    
084                    preferences.setValue(
085                            "showFoldersSearch", String.valueOf(showFoldersSearch));
086                    preferences.setValue("showSubfolders", String.valueOf(showSubfolders));
087                    preferences.setValue("foldersPerPage", String.valueOf(foldersPerPage));
088                    preferences.setValue("folderColumns", folderColumns);
089    
090                    preferences.setValue(
091                            "entriesPerPage", String.valueOf(entriesPerPage));
092                    preferences.setValue("entryColumns", entryColumns);
093    
094                    if (SessionErrors.isEmpty(actionRequest)) {
095                            preferences.store();
096    
097                            SessionMessages.add(
098                                    actionRequest, portletConfig.getPortletName() + ".doConfigure");
099                    }
100            }
101    
102            public String render(
103                            PortletConfig portletConfig, RenderRequest renderRequest,
104                            RenderResponse renderResponse)
105                    throws Exception {
106    
107                    return "/html/portlet/bookmarks/configuration.jsp";
108            }
109    
110    }