1 package net.stff.ical.gui.struts.actions;
2
3 import java.io.IOException;
4
5 import javax.servlet.ServletException;
6 import javax.servlet.ServletOutputStream;
7 import javax.servlet.http.HttpServletResponse;
8
9 import net.stff.ical.beans.CalendarData;
10 import net.stff.ical.beans.ICal;
11 import net.stff.util.SessionObject;
12
13 import org.apache.struts.action.Action;
14 import org.apache.struts.action.ActionForm;
15 import org.apache.struts.action.ActionForward;
16 import org.apache.struts.action.ActionMapping;
17
18 /***
19 * A struts action class that displays a Calendar
20 *
21 * @author Bernd Eickhoff
22 * @created 9. Juni 2003
23 * @company <a href="www.stoffwechsel.net">stoffwechsel</a>
24 */
25 public final class IcalAction extends Action {
26
27 public ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
28
29 String name= request.getParameter("cal");
30 SessionObject so = SessionObject.get(request);
31 CalendarData data = (CalendarData)so.getObject("icalData", request);
32 data.setUser(request.getRemoteUser());
33 ICal cal= data.getManager().getCalendar(name, request.getRemoteUser());
34
35
36 String representation= cal.toString();
37 response.reset();
38 response.setHeader("Content-Type", "text/calendar");
39 response.setHeader("Content-Disposition", "attachment; filename="+name+".ics");
40 response.setHeader("Content-length", Long.toString(representation.length()));
41
42 ServletOutputStream sos= response.getOutputStream();
43 sos.print(representation);
44 return null;
45 }
46 }
47