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