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.documentlibrary.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.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.util.PortletKeys;
023    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
024    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
025    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
026    
027    import javax.portlet.ActionRequest;
028    import javax.portlet.ActionResponse;
029    import javax.portlet.PortletConfig;
030    
031    /**
032     * @author Jorge Ferrer
033     */
034    public class ConfigurationActionImpl extends DefaultConfigurationAction {
035    
036            @Override
037            public void processAction(
038                            PortletConfig portletConfig, ActionRequest actionRequest,
039                            ActionResponse actionResponse)
040                    throws Exception {
041    
042                    String portletResource = ParamUtil.getString(
043                            actionRequest, "portletResource");
044    
045                    if (portletResource.equals(PortletKeys.DOCUMENT_LIBRARY)) {
046                            validateDisplayStyleViews(actionRequest);
047                    }
048    
049                    validateRootFolder(actionRequest);
050    
051                    super.processAction(portletConfig, actionRequest, actionResponse);
052            }
053    
054            protected void validateDisplayStyleViews(ActionRequest actionRequest)
055                    throws Exception {
056    
057                    String displayViews = GetterUtil.getString(
058                            getParameter(actionRequest, "displayViews"));
059    
060                    if (Validator.isNull(displayViews)) {
061                            SessionErrors.add(actionRequest, "displayViewsInvalid");
062                    }
063            }
064    
065            protected void validateRootFolder(ActionRequest actionRequest)
066                    throws Exception {
067    
068                    long rootFolderId = GetterUtil.getLong(
069                            getParameter(actionRequest, "rootFolderId"));
070    
071                    if (rootFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
072                            try {
073                                    DLAppLocalServiceUtil.getFolder(rootFolderId);
074                            }
075                            catch (NoSuchFolderException nsfe) {
076                                    SessionErrors.add(actionRequest, "rootFolderIdInvalid");
077                            }
078                    }
079            }
080    
081    }