View Javadoc

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  @Deprecated
14  public class ExportDocumentDownload extends HttpServlet {
15  
16      final Logger LOG = Logger.getLogger(ExportDocumentDownload.class);
17      private static final long serialVersionUID = 1L;
18  
19      public void doGet(HttpServletRequest request, HttpServletResponse response) {
20          try {
21              // If PDF is generated to to temp file, read it
22              String exportId = request.getParameter("exportId");
23              String format = request.getParameter("format");
24              // Get from session the byte array that was cached by the GWT Servlet
25              byte[] bytes = (byte[]) request.getSession().getAttribute(exportId);
26  
27              sendPDF(response, bytes, format);
28          } catch (Exception ex) {
29              // TODO Nina how must we handle exceptions here??
30              // do something here
31          }
32      }
33  
34      void sendPDF(HttpServletResponse response, byte[] bytes, String format) throws IOException {
35          ServletOutputStream stream = response.getOutputStream();
36          if (format.equals(ExportUtils.PDF)) {
37              response.setContentType("application/pdf");
38              response.addHeader("Content-Type", "application/pdf");
39              response.addHeader("Content-Disposition", "inline; filename=export.pdf");
40              response.setContentLength((int) bytes.length);
41          } else if (format.equals(ExportUtils.XLS)) {
42              response.setContentType("application/xls");
43              response.addHeader("Content-Type", "application/xls");
44              response.addHeader("Content-Disposition", "inline; filename=export.xls");
45              response.setContentLength((int) bytes.length);
46          } else {
47              response.setContentType("application/ms-word");
48              response.addHeader("Content-Type", "application/ms-word");
49              response.addHeader("Content-Disposition", "inline; filename=export.doc");
50              response.setContentLength((int) bytes.length);
51          }
52          stream.write(bytes);
53          stream.close();
54      }
55  }