001    /**
002     * Copyright (c) 2000-2013 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.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    }