01: package org.enhydra.snapperAdmin.presentation;
02:
03: import java.io.BufferedOutputStream;
04: import java.io.File;
05: import java.io.FileInputStream;
06: import java.io.FileNotFoundException;
07: import org.enhydra.snapperAdmin.Log;
08: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
09: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
10:
11: public class FileDownloadBO {
12:
13: private File fDown = null;
14: private HttpPresentationComms comms = null;
15: private boolean isForDelete = false;
16:
17: public static final String EXCEL_CONTENT_TYPE = "application/vnd.ms-excel";
18: public static final String WORD_CONTENT_TYPE = "application/vnd.ms-word";
19: public static final String HTML_CONTENT_TYPE = "text/html";
20: public static final String PDF_CONTENT_TYPE = "application/pdf";
21: public static final String ZIP_CONTENT_TYPE = "application/x-zip";
22: public static final String RTF_CONTENT_TYPE = "application/rtf";
23: public static final String PPT_CONTENT_TYPE = "application/vnd.ms-powerpoint";
24: public static final String PPS_CONTENT_TYPE = "application/vnd.ms-powerpoint";
25: public static final String EML_CONTENT_TYPE = "application/vnd.ms-outlook";
26:
27: public static final String SXW_CONTENT_TYPE = "application/vnd.sun.xml.writer";
28: public static final String STW_CONTENT_TYPE = "application/vnd.sun.xml.writer.template";
29: public static final String SXG_CONTENT_TYPE = "application/vnd.sun.xml.writer.global";
30: public static final String SXC_CONTENT_TYPE = "application/vnd.sun.xml.calc";
31: public static final String STC_CONTENT_TYPE = "application/vnd.sun.xml.calc.template";
32: public static final String SXI_CONTENT_TYPE = "application/vnd.sun.xml.impress";
33: public static final String STI_CONTENT_TYPE = "application/vnd.sun.xml.impress.template";
34: public static final String SXD_CONTENT_TYPE = "application/vnd.sun.xml.draw";
35: public static final String STD_CONTENT_TYPE = "application/vnd.sun.xml.draw.template";
36: public static final String SXM_CONTENT_TYPE = "application/vnd.sun.xml.math";
37:
38: public FileDownloadBO(File file, HttpPresentationComms comms) {
39: this .fDown = file;
40: this .comms = comms;
41: }
42:
43: public void setContentType(String type)
44: throws HttpPresentationException {
45: this .comms.response.setContentType(type);
46: this .comms.response.setHeader("Content-Disposition",
47: "inline; filename=\"" + fDown.getName() + "\"");
48: }
49:
50: public void download() {
51:
52: FileInputStream fi = null;
53:
54: try {
55: fi = new FileInputStream(fDown);
56:
57: byte[] buffer = new byte[4096];
58: BufferedOutputStream bu = new BufferedOutputStream(
59: comms.response.getOutputStream());
60: int no = fi.read(buffer);
61: while (no > -1) {
62: bu.write(buffer, 0, no);
63: no = fi.read(buffer);
64: }
65: bu.flush();
66: comms.response.flush();
67: } catch (FileNotFoundException e) {
68: Log.logException(e);
69: } catch (Exception e) {
70:
71: } finally {
72: if (fi != null) {
73: try {
74: fi.close();
75: } catch (Exception e) {
76: }
77: fi = null;
78: }
79: }
80: }
81:
82: }
|