Revision: 84
http://treebase.svn.sourceforge.net/treebase/?rev=84&view=rev
Author: rvos
Date: 2009-06-23 11:12:31 +0000 (Tue, 23 Jun 2009)
Log Message:
-----------
Added facility to specify which content type the produced file is (default: "application/x-unknown")
Modified Paths:
--------------
trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/WebUtil.java
Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/WebUtil.java
===================================================================
--- trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/WebUtil.java 2009-06-23 11:10:53 UTC (rev 83)
+++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/WebUtil.java 2009-06-23 11:12:31 UTC (rev 84)
@@ -257,31 +257,43 @@
public static String downloadFile(HttpServletResponse response, String dirPath, String filename)
throws Exception {
+ return downloadFile(response,dirPath,filename,null);
+ }
+
+ public static String downloadFile(HttpServletResponse response, String dirPath, String filename, String contentType)
+ throws Exception {
// to download the file outside of the webapp, we need to call a servlet
// that opens and read the file and display the output to the response object
-
+
/**
* allow a popup dialog to downlaod the result file
*/
byte[] bytes = WebUtil.getBytesFromFile(dirPath, filename);
-
+
response.reset();
- // response.setContentType("application/octet-stream"); // this forces to be downloaded as a
- // binary file
- response.setContentType("application/x-unknown"); // this forces to be downloaded as type
- // of the extension (e.g NEX file for
- // *.nex)
- response.setHeader("Content-Disposition", "inline;filename=" + "\"" + filename + "\"");
- response.setContentType("text/plain"); // offer users option to view or save the file
- response.setHeader("Content-Disposition", "attachment; filename=" + filename);
+
+ if ( null == contentType ) {
+ // response.setContentType("application/octet-stream"); // this forces to be downloaded as a
+ // binary file
+ response.setContentType("application/x-unknown"); // this forces to be downloaded as type
+ // of the extension (e.g NEX file for
+ // *.nex)
+ response.setHeader("Content-Disposition", "inline;filename=" + "\"" + filename + "\"");
+ response.setContentType("text/plain"); // offer users option to view or save the file
+ response.setHeader("Content-Disposition", "attachment; filename=" + filename);
+ }
+ else {
+ response.setContentType(contentType);
+ }
+
response.setContentLength(bytes.length);
-
+
OutputStream outputStream = response.getOutputStream();
outputStream.write(bytes, 0, bytes.length);
outputStream.flush();
outputStream.close();
-
+
return null;
- }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|