1
19
20 package com.liferay.portlet.calendar.action;
21
22 import com.liferay.portal.kernel.log.Log;
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
24 import com.liferay.portal.kernel.util.ContentTypes;
25 import com.liferay.portal.kernel.util.ParamUtil;
26 import com.liferay.portal.struts.ActionConstants;
27 import com.liferay.portal.struts.PortletAction;
28 import com.liferay.portal.theme.ThemeDisplay;
29 import com.liferay.portal.util.PortalUtil;
30 import com.liferay.portal.util.WebKeys;
31 import com.liferay.portlet.calendar.service.CalEventServiceUtil;
32 import com.liferay.util.servlet.ServletResponseUtil;
33
34 import java.io.BufferedInputStream;
35 import java.io.File;
36 import java.io.FileInputStream;
37 import java.io.InputStream;
38
39 import javax.portlet.ActionRequest;
40 import javax.portlet.ActionResponse;
41 import javax.portlet.PortletConfig;
42
43 import javax.servlet.http.HttpServletResponse;
44
45 import org.apache.struts.action.ActionForm;
46 import org.apache.struts.action.ActionMapping;
47
48
55 public class ExportEventsAction extends PortletAction {
56
57 public void processAction(
58 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
59 ActionRequest actionRequest, ActionResponse actionResponse)
60 throws Exception {
61
62 InputStream is = null;
63
64 try {
65 ThemeDisplay themeDisplay =
66 (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
67
68 long eventId = ParamUtil.getLong(actionRequest, "eventId");
69
70 String exportFileName = ParamUtil.getString(
71 actionRequest, "exportFileName");
72
73 File file = null;
74
75 if (eventId > 0) {
76 file = CalEventServiceUtil.exportEvent(eventId);
77 }
78 else {
79 file = CalEventServiceUtil.exportGroupEvents(
80 themeDisplay.getPlid(), exportFileName);
81 }
82
83 is = new BufferedInputStream(new FileInputStream(file));
84
85 HttpServletResponse response = PortalUtil.getHttpServletResponse(
86 actionResponse);
87
88 ServletResponseUtil.sendFile(
89 response, file.getName(), is, ContentTypes.TEXT_CALENDAR);
90
91 setForward(actionRequest, ActionConstants.COMMON_NULL);
92 }
93 catch (Exception e) {
94 _log.error(e, e);
95 }
96 finally {
97 ServletResponseUtil.cleanUp(is);
98 }
99 }
100
101 private static Log _log = LogFactoryUtil.getLog(ExportEventsAction.class);
102
103 }