com.liferay.document.library.web.internal.portlet.action.ValidateRootFolderConfigurationAction.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.document.library.web.internal.portlet.action.ValidateRootFolderConfigurationAction.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.document.library.web.internal.portlet.action;

import com.liferay.document.library.kernel.exception.NoSuchFolderException;
import com.liferay.document.library.kernel.model.DLFolderConstants;
import com.liferay.document.library.kernel.service.DLAppLocalServiceUtil;
import com.liferay.portal.kernel.exception.NoSuchRepositoryEntryException;
import com.liferay.portal.kernel.portlet.BaseJSPSettingsConfigurationAction;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;

/**
 * @author Jorge Ferrer
 * @author Sergio Gonzlez
 */
public abstract class ValidateRootFolderConfigurationAction extends BaseJSPSettingsConfigurationAction {

    @Override
    public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
            ActionResponse actionResponse) throws Exception {

        String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

        if (Validator.isNotNull(cmd)) {
            validate(actionRequest);
        }

        super.processAction(portletConfig, actionRequest, actionResponse);
    }

    protected void validate(ActionRequest actionRequest) throws Exception {
        validateRootFolder(actionRequest);
    }

    protected void validateRootFolder(ActionRequest actionRequest) throws Exception {

        long rootFolderId = GetterUtil.getLong(getParameter(actionRequest, "rootFolderId"));

        if (rootFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
            try {
                DLAppLocalServiceUtil.getFolder(rootFolderId);
            } catch (Exception e) {
                if (e instanceof NoSuchFolderException || e instanceof NoSuchRepositoryEntryException) {

                    SessionErrors.add(actionRequest, "rootFolderIdInvalid");
                } else {
                    throw e;
                }
            }
        }
    }

}