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.BaseJSPSettingsConfigurationAction;
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
037            extends BaseJSPSettingsConfigurationAction {
038    
039            @Override
040            public void processAction(
041                            PortletConfig portletConfig, ActionRequest actionRequest,
042                            ActionResponse actionResponse)
043                    throws Exception {
044    
045                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
046    
047                    if (Validator.isNotNull(cmd)) {
048                            validate(actionRequest);
049                    }
050    
051                    super.processAction(portletConfig, actionRequest, actionResponse);
052            }
053    
054            protected void validate(ActionRequest actionRequest) throws Exception {
055                    validateDisplayStyleViews(actionRequest);
056                    validateRootFolder(actionRequest);
057            }
058    
059            protected void validateDisplayStyleViews(ActionRequest actionRequest) {
060                    String displayViews = GetterUtil.getString(
061                            getParameter(actionRequest, "displayViews"));
062    
063                    if (Validator.isNull(displayViews)) {
064                            SessionErrors.add(actionRequest, "displayViewsInvalid");
065                    }
066            }
067    
068            protected void validateRootFolder(ActionRequest actionRequest)
069                    throws Exception {
070    
071                    long rootFolderId = GetterUtil.getLong(
072                            getParameter(actionRequest, "rootFolderId"));
073    
074                    if (rootFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
075                            try {
076                                    DLAppLocalServiceUtil.getFolder(rootFolderId);
077                            }
078                            catch (Exception e) {
079                                    if (e instanceof NoSuchFolderException ||
080                                            e instanceof NoSuchRepositoryEntryException) {
081    
082                                            SessionErrors.add(actionRequest, "rootFolderIdInvalid");
083                                    }
084                                    else {
085                                            throw e;
086                                    }
087                            }
088                    }
089            }
090    
091    }