1 package org
.argeo
.eclipse
.ui
.specific
;
3 import java
.io
.IOException
;
5 import javax
.servlet
.ServletException
;
6 import javax
.servlet
.http
.HttpServletResponse
;
8 import org
.argeo
.ArgeoException
;
9 import org
.eclipse
.rwt
.RWT
;
10 import org
.eclipse
.rwt
.service
.IServiceHandler
;
12 public class DownloadServiceHandler
implements IServiceHandler
{
14 private FileProvider provider
;
16 public DownloadServiceHandler(FileProvider provider
) {
17 this.provider
= provider
;
20 public void service() throws IOException
, ServletException
{
21 // Which file to download?
22 String fileName
= RWT
.getRequest().getParameter("filename");
23 String fileId
= RWT
.getRequest().getParameter("fileid");
25 // Get the file content
26 byte[] download
= provider
.getByteArrayFileFromId(fileId
);
28 // Send the file in the response
29 HttpServletResponse response
= RWT
.getResponse();
30 response
.setContentType("application/octet-stream");
31 response
.setContentLength(download
.length
);
32 String contentDisposition
= "attachment; filename=\"" + fileName
+ "\"";
33 response
.setHeader("Content-Disposition", contentDisposition
);
35 response
.getOutputStream().write(download
);
36 } catch (IOException ioe
) {
37 throw new ArgeoException("Error while writing the file " + fileName
38 + " to the servlet response", ioe
);