19 package org.turro.attach.www;
21 import com.lowagie.text.DocumentException;
22 import java.io.IOException;
23 import java.io.UnsupportedEncodingException;
24 import java.net.URLEncoder;
25 import java.util.HashMap;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import org.amic.util.string.Cipher;
33 import org.turro.attach.db.AttachPU;
34 import org.turro.attach.entity.Attachment;
35 import org.turro.auth.Authentication;
36 import org.turro.elephant.context.ElephantContext;
37 import org.turro.elephant.context.IConstructor;
38 import org.turro.elephant.direct.DirectContent;
39 import org.turro.elephant.direct.DirectContents;
40 import org.turro.elephant.direct.IDirectContent;
41 import org.turro.log.SystemLogType;
42 import org.turro.log.SystemLogger;
48 @DirectContent(identifier=
"attachment-show")
52 Map<String, String> downKeys = (Map<String, String>) constructor.
getSessionAttribute(
"downKeys");
53 if(downKeys ==
null) {
54 downKeys =
new HashMap<>();
56 String key = Cipher.digest(attachment.
getId() +
"", 40);
57 downKeys.put(key, attachment.
getId() +
"");
65 Map<String, String> downKeys = (Map<String, String>) constructor.
getSessionAttribute(
"downKeys");
66 if(downKeys ==
null) {
67 downKeys =
new HashMap<>();
69 String key = Cipher.digest(attachment.
getId() +
"", 40);
70 downKeys.put(key, attachment.
getId() +
"");
73 "/_internal/js/pdfjs/web/roviewer.html?file=" +
75 }
catch (UnsupportedEncodingException ex) {
80 return createURL(constructor, attachment);
89 public boolean itsMe(String
id) {
90 return getIdentifier().equals(
id);
94 public boolean myTurn(HttpServletRequest request) {
99 public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
100 Map downKeys = (Map) request.getSession().getAttribute(
"downKeys");
101 if(downKeys !=
null) {
102 String value = (String) downKeys.get(request.getParameter(
"id"));
105 if(attachment !=
null) {
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() +
"");
134 response.getOutputStream().write(bytes);
137 }
catch (IOException | DocumentException ex) {
String getFileContentType()
byte[] getContentModified(IContact contact)
String getFileExtension()
static String createROURL(IConstructor constructor, Attachment attachment)
static String getIdentifier()
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
boolean myTurn(HttpServletRequest request)
static String createURL(IConstructor constructor, Attachment attachment)
static IContact getIContact()
static String getRootWebPath()
static String logMsg(String msg)
static boolean isYourTurn(HttpServletRequest request, String path)
static final String DIRECT_CONTENT_PATH
static ISystemLogger getInstance()
void setSessionAttribute(String key, Object value)
Object getSessionAttribute(String key)
void doLog(SystemLogType type, Object entity, String comment, Serializable data)