100 Map downKeys = (Map) request.getSession().getAttribute(
"downKeys");
101 if(downKeys !=
null) {
102 String value = (String) downKeys.get(request.getParameter(
"id"));
104 Attachment attachment =
new AttachPU().find(Attachment.class, Long.parseLong(value));
105 if(attachment !=
null) {
107 String contentType = attachment.getFileContentType();
108 String fileName = attachment.getFileName();
110 response.setHeader(
"pragma",
"no-cache");
111 response.setHeader(
"Cache-control",
"no-cache, no-store, must-revalidate");
112 response.setHeader(
"Expires",
"01 Apr 1995 01:10:10 GMT");
114 if(contentType!=
null) {
115 response.setContentType(contentType);
118 if(fileName !=
null) {
119 fileName = fileName.substring(fileName.lastIndexOf(
'\\')+1);
120 fileName = fileName.substring(fileName.lastIndexOf(
'/')+1);
122 StringBuilder contentDisposition =
new StringBuilder();
124 contentDisposition.append(
"filename=\"");
125 contentDisposition.append(fileName);
126 contentDisposition.append(
"\"");
128 response.setHeader(
"Content-Disposition", contentDisposition.toString());
129 response.setHeader(
"Content-Lenght", attachment.getFileSize() +
"");
132 byte[] bytes = attachment.getContentModified(Authentication.getIContact());
134 response.getOutputStream().write(bytes);
135 SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO,
"/attachment/" + attachment.getId(),
"downloaded",
null);
137 }
catch (IOException | DocumentException ex) {
138 Logger.getLogger(AttachDownload.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);