import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
-import org.argeo.ArgeoException;
import org.eclipse.rap.rwt.service.ServiceHandler;
/**
String uri = request.getParameter(PARAM_FILE_URI);
// Set the Metadata
- response.setContentType("application/octet-stream");
response.setContentLength((int) getFileLength(uri));
if (fileName == null || "".equals(fileName.trim()))
fileName = getFileName(uri);
+ response.setContentType(getMimeTypeFromName(fileName));
String contentDisposition = "attachment; filename=\"" + fileName + "\"";
response.setHeader("Content-Disposition", contentDisposition);
return FileUtils.readFileToByteArray(new File(
getFilePathFromUri(uri)));
} catch (IOException ioe) {
- throw new ArgeoException("Error getting the file at " + uri,
- ioe);
+ throw new SingleSourcingException("Error getting the file at "
+ + uri, ioe);
}
}
return null;
private String getFilePathFromUri(String uri) {
return uri.substring((FILE_SCHEME + SCHEME_HOST_SEPARATOR).length());
}
+
+ /** Overwrite to precise the content type */
+ protected String getMimeTypeFromName(String fileName) {
+ return "application/octet-stream";
+ }
}
\ No newline at end of file