1
22
23 package com.liferay.portlet.communities.action;
24
25 import com.liferay.portal.NoSuchGroupException;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.security.auth.PrincipalException;
28 import com.liferay.portal.service.LayoutServiceUtil;
29 import com.liferay.portal.struts.ActionConstants;
30 import com.liferay.portal.struts.PortletAction;
31 import com.liferay.portlet.ActionResponseImpl;
32 import com.liferay.util.servlet.ServletResponseUtil;
33 import com.liferay.util.servlet.SessionErrors;
34
35 import javax.portlet.ActionRequest;
36 import javax.portlet.ActionResponse;
37 import javax.portlet.PortletConfig;
38 import javax.portlet.RenderRequest;
39 import javax.portlet.RenderResponse;
40
41 import javax.servlet.http.HttpServletResponse;
42
43 import org.apache.commons.logging.Log;
44 import org.apache.commons.logging.LogFactory;
45 import org.apache.struts.action.ActionForm;
46 import org.apache.struts.action.ActionForward;
47 import org.apache.struts.action.ActionMapping;
48
49
56 public class ExportPagesAction extends PortletAction {
57
58 public void processAction(
59 ActionMapping mapping, ActionForm form, PortletConfig config,
60 ActionRequest req, ActionResponse res)
61 throws Exception {
62
63 try {
64 long groupId = ParamUtil.getLong(req, "groupId");
65 boolean privateLayout = ParamUtil.getBoolean(req, "privateLayout");
66 String fileName = ParamUtil.getString(req, "exportFileName");
67
68 byte[] byteArray = LayoutServiceUtil.exportLayouts(
69 groupId, privateLayout, req.getParameterMap());
70
71 HttpServletResponse httpRes =
72 ((ActionResponseImpl)res).getHttpServletResponse();
73
74 ServletResponseUtil.sendFile(httpRes, fileName, byteArray);
75
76 setForward(req, ActionConstants.COMMON_NULL);
77 }
78 catch (Exception e) {
79 _log.error(e, e);
80 }
81 }
82
83 public ActionForward render(
84 ActionMapping mapping, ActionForm form, PortletConfig config,
85 RenderRequest req, RenderResponse res)
86 throws Exception {
87
88 try {
89 ActionUtil.getGroup(req);
90 }
91 catch (Exception e) {
92 if (e instanceof NoSuchGroupException ||
93 e instanceof PrincipalException) {
94
95 SessionErrors.add(req, e.getClass().getName());
96
97 return mapping.findForward("portlet.communities.error");
98 }
99 else {
100 throw e;
101 }
102 }
103
104 return mapping.findForward(
105 getForward(req, "portlet.communities.export_pages"));
106 }
107
108 private static Log _log = LogFactory.getLog(ExportPagesAction.class);
109
110 }