001
014
015 package com.liferay.portlet.communities.action;
016
017 import com.liferay.portal.LARFileException;
018 import com.liferay.portal.LARTypeException;
019 import com.liferay.portal.LayoutImportException;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.kernel.servlet.SessionErrors;
023 import com.liferay.portal.kernel.upload.UploadPortletRequest;
024 import com.liferay.portal.kernel.util.ParamUtil;
025 import com.liferay.portal.service.LayoutServiceUtil;
026 import com.liferay.portal.util.PortalUtil;
027
028 import java.io.File;
029
030 import javax.portlet.ActionRequest;
031 import javax.portlet.ActionResponse;
032 import javax.portlet.PortletConfig;
033
034 import org.apache.struts.action.ActionForm;
035 import org.apache.struts.action.ActionMapping;
036
037
041 public class ImportPagesAction extends EditPagesAction {
042
043 public void processAction(
044 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
045 ActionRequest actionRequest, ActionResponse actionResponse)
046 throws Exception {
047
048 try {
049 UploadPortletRequest uploadRequest =
050 PortalUtil.getUploadPortletRequest(actionRequest);
051
052 long groupId = ParamUtil.getLong(uploadRequest, "groupId");
053 boolean privateLayout = ParamUtil.getBoolean(
054 uploadRequest, "privateLayout");
055 File file = uploadRequest.getFile("importFileName");
056
057 if (!file.exists()) {
058 throw new LARFileException("Import file does not exist");
059 }
060
061 LayoutServiceUtil.importLayouts(
062 groupId, privateLayout, actionRequest.getParameterMap(), file);
063
064 addSuccessMessage(actionRequest, actionResponse);
065 }
066 catch (Exception e) {
067 if ((e instanceof LARFileException) ||
068 (e instanceof LARTypeException)) {
069
070 SessionErrors.add(actionRequest, e.getClass().getName());
071 }
072 else {
073 _log.error(e, e);
074
075 SessionErrors.add(
076 actionRequest, LayoutImportException.class.getName());
077 }
078 }
079 }
080
081 private static Log _log = LogFactoryUtil.getLog(ImportPagesAction.class);
082
083 }