Coverage Report - org.kuali.student.common.ui.server.gwt.ExportDocumentDownload
 
Classes in this File Line Coverage Branch Coverage Complexity
ExportDocumentDownload
0%
0/22
0%
0/2
2
 
 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  0
 public class ExportDocumentDownload extends HttpServlet {
 14  
 
 15  0
     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  
             // If PDF is generated to to temp file, read it
 21  0
             String exportId = request.getParameter("exportId");
 22  0
             String format = request.getParameter("format");
 23  
             // Get from session the byte array that was cached by the GWT Servlet
 24  0
             byte[] bytes = (byte[]) request.getSession().getAttribute(exportId);
 25  
 
 26  0
             sendPDF(response, bytes, format);
 27  0
         } catch (Exception ex) {
 28  
             // TODO Nina how must we handle exceptions here??
 29  
             // do something here
 30  0
         }
 31  0
     }
 32  
 
 33  
     void sendPDF(HttpServletResponse response, byte[] bytes, String format) throws IOException {
 34  0
         ServletOutputStream stream = response.getOutputStream();
 35  0
         if (format.equals(ExportUtils.PDF)) {
 36  0
             response.setContentType("application/pdf");
 37  0
             response.addHeader("Content-Type", "application/pdf");
 38  0
             response.addHeader("Content-Disposition", "inline; filename=export.pdf");
 39  0
             response.setContentLength((int) bytes.length);
 40  
         } else {
 41  0
             response.setContentType("application/ms-word");
 42  0
             response.addHeader("Content-Type", "application/ms-word");
 43  0
             response.addHeader("Content-Disposition", "inline; filename=export.doc");
 44  0
             response.setContentLength((int) bytes.length);
 45  
         }
 46  0
         stream.write(bytes);
 47  0
         stream.close();
 48  0
     }
 49  
 }