001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.bookmarks.action;
016    
017    import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionErrors;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portlet.bookmarks.model.BookmarksFolderConstants;
021    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
022    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
023    
024    import javax.portlet.ActionRequest;
025    import javax.portlet.ActionResponse;
026    import javax.portlet.PortletConfig;
027    
028    /**
029     * @author Sergio González
030     */
031    public class ConfigurationActionImpl extends DefaultConfigurationAction {
032    
033            @Override
034            public void processAction(
035                            PortletConfig portletConfig, ActionRequest actionRequest,
036                            ActionResponse actionResponse)
037                    throws Exception {
038    
039                    validateRootFolder(actionRequest);
040    
041                    super.processAction(portletConfig, actionRequest, actionResponse);
042            }
043    
044            protected void validateRootFolder(ActionRequest actionRequest)
045                    throws Exception {
046    
047                    long rootFolderId = GetterUtil.getLong(
048                            getParameter(actionRequest, "rootFolderId"));
049    
050                    if (rootFolderId != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
051                            try {
052                                    BookmarksFolderLocalServiceUtil.getFolder(rootFolderId);
053                            }
054                            catch (NoSuchFolderException nsfe) {
055                                    SessionErrors.add(actionRequest, "rootFolderIdInvalid");
056                            }
057                    }
058            }
059    
060    }