1 package org.kuali.student.common.ui.server.gwt;
2
3 import java.io.IOException;
4
5 import javax.servlet.ServletOutputStream;
6 import javax.servlet.http.HttpServlet;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9
10 import org.apache.log4j.Logger;
11 import org.kuali.student.common.ui.client.util.ExportUtils;
12
13 public class ExportDocumentDownload extends HttpServlet {
14
15 final Logger LOG = Logger.getLogger(ExportDocumentDownload.class);
16 private static final long serialVersionUID = 1L;
17
18 public void doGet(HttpServletRequest request, HttpServletResponse response) {
19 try {
20
21 String exportId = request.getParameter("exportId");
22 String format = request.getParameter("format");
23
24 byte[] bytes = (byte[]) request.getSession().getAttribute(exportId);
25
26 sendPDF(response, bytes, format);
27 } catch (Exception ex) {
28
29
30 }
31 }
32
33 void sendPDF(HttpServletResponse response, byte[] bytes, String format) throws IOException {
34 ServletOutputStream stream = response.getOutputStream();
35 if (format.equals(ExportUtils.PDF)) {
36 response.setContentType("application/pdf");
37 response.addHeader("Content-Type", "application/pdf");
38 response.addHeader("Content-Disposition", "inline; filename=export.pdf");
39 response.setContentLength((int) bytes.length);
40 } else {
41 response.setContentType("application/ms-word");
42 response.addHeader("Content-Type", "application/ms-word");
43 response.addHeader("Content-Disposition", "inline; filename=export.doc");
44 response.setContentLength((int) bytes.length);
45 }
46 stream.write(bytes);
47 stream.close();
48 }
49 }