001    /**
002     * Copyright (c) 2000-present 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.documentlibrary.action;
016    
017    import com.liferay.portal.NoSuchRepositoryEntryException;
018    import com.liferay.portal.kernel.portlet.SettingsConfigurationAction;
019    import com.liferay.portal.kernel.servlet.SessionErrors;
020    import com.liferay.portal.kernel.util.Constants;
021    import com.liferay.portal.kernel.util.GetterUtil;
022    import com.liferay.portal.kernel.util.ParamUtil;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
025    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
026    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
027    
028    import javax.portlet.ActionRequest;
029    import javax.portlet.ActionResponse;
030    import javax.portlet.PortletConfig;
031    
032    /**
033     * @author Jorge Ferrer
034     * @author Sergio Gonz??lez
035     */
036    public class ConfigurationActionImpl extends SettingsConfigurationAction {
037    
038            @Override
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 (Validator.isNotNull(cmd)) {
047                            validate(actionRequest);
048                    }
049    
050                    super.processAction(portletConfig, actionRequest, actionResponse);
051            }
052    
053            protected void validate(ActionRequest actionRequest) throws Exception {
054                    validateDisplayStyleViews(actionRequest);
055                    validateRootFolder(actionRequest);
056            }
057    
058            protected void validateDisplayStyleViews(ActionRequest actionRequest) {
059                    String displayViews = GetterUtil.getString(
060                            getParameter(actionRequest, "displayViews"));
061    
062                    if (Validator.isNull(displayViews)) {
063                            SessionErrors.add(actionRequest, "displayViewsInvalid");
064                    }
065            }
066    
067            protected void validateRootFolder(ActionRequest actionRequest)
068                    throws Exception {
069    
070                    long rootFolderId = GetterUtil.getLong(
071                            getParameter(actionRequest, "rootFolderId"));
072    
073                    if (rootFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
074                            try {
075                                    DLAppLocalServiceUtil.getFolder(rootFolderId);
076                            }
077                            catch (Exception e) {
078                                    if (e instanceof NoSuchFolderException ||
079                                            e instanceof NoSuchRepositoryEntryException) {
080    
081                                            SessionErrors.add(actionRequest, "rootFolderIdInvalid");
082                                    }
083                                    else {
084                                            throw e;
085                                    }
086                            }
087                    }
088            }
089    
090    }