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.exportimport.action;
016    
017    import com.liferay.portal.NoSuchGroupException;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.servlet.SessionErrors;
020    import com.liferay.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.security.auth.PrincipalException;
022    import com.liferay.portal.struts.PortletAction;
023    import com.liferay.portlet.exportimport.configuration.ExportImportConfigurationFactory;
024    import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
025    import com.liferay.portlet.sites.action.ActionUtil;
026    
027    import javax.portlet.PortletConfig;
028    import javax.portlet.RenderRequest;
029    import javax.portlet.RenderResponse;
030    
031    import org.apache.struts.action.ActionForm;
032    import org.apache.struts.action.ActionForward;
033    import org.apache.struts.action.ActionMapping;
034    
035    /**
036     * @author Levente Hud??k
037     */
038    public class ConfirmationExportImportConfigurationAction extends PortletAction {
039    
040            @Override
041            public ActionForward render(
042                            ActionMapping actionMapping, ActionForm actionForm,
043                            PortletConfig portletConfig, RenderRequest renderRequest,
044                            RenderResponse renderResponse)
045                    throws Exception {
046    
047                    try {
048                            long exportImportConfigurationId = ParamUtil.getLong(
049                                    renderRequest, "exportImportConfigurationId");
050    
051                            if (exportImportConfigurationId <= 0) {
052                                    createExportImportConfiguration(renderRequest);
053                            }
054    
055                            ActionUtil.getGroup(renderRequest);
056                    }
057                    catch (Exception e) {
058                            if (e instanceof NoSuchGroupException ||
059                                    e instanceof PrincipalException) {
060    
061                                    SessionErrors.add(renderRequest, e.getClass());
062    
063                                    return actionMapping.findForward("portlet.export_import.error");
064                            }
065                            else {
066                                    throw e;
067                            }
068                    }
069    
070                    return actionMapping.findForward(
071                            getForward(renderRequest, "portlet.export_import.confirmation"));
072            }
073    
074            protected void createExportImportConfiguration(RenderRequest renderRequest)
075                    throws PortalException {
076    
077                    ExportImportConfiguration exportImportConfiguration = null;
078    
079                    boolean localPublishing = ParamUtil.getBoolean(
080                            renderRequest, "localPublishing");
081    
082                    if (localPublishing) {
083                            exportImportConfiguration =
084                                    ExportImportConfigurationFactory.
085                                            buildDefaultLocalPublishingExportImportConfiguration(
086                                                    renderRequest);
087                    }
088                    else {
089                            exportImportConfiguration =
090                                    ExportImportConfigurationFactory.
091                                            buildDefaultRemotePublishingExportImportConfiguration(
092                                                    renderRequest);
093                    }
094    
095                    renderRequest.setAttribute(
096                            "exportImportConfigurationId",
097                            exportImportConfiguration.getExportImportConfigurationId());
098            }
099    
100    }