BrightSide Workbench Full Report + Source Code
org.turro.attach.www.AttachDownload Class Reference
Inheritance diagram for org.turro.attach.www.AttachDownload:
Collaboration diagram for org.turro.attach.www.AttachDownload:

Public Member Functions

boolean itsMe (String id)
 
boolean myTurn (HttpServletRequest request)
 
void execute (ServletContext context, HttpServletRequest request, HttpServletResponse response)
 

Static Public Member Functions

static String createURL (IConstructor constructor, Attachment attachment)
 
static String createROURL (IConstructor constructor, Attachment attachment)
 
static String getIdentifier ()
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 49 of file AttachDownload.java.

Member Function Documentation

◆ createROURL()

static String org.turro.attach.www.AttachDownload.createROURL ( IConstructor  constructor,
Attachment  attachment 
)
static

Definition at line 62 of file AttachDownload.java.

62  {
63  if("pdf".equalsIgnoreCase(attachment.getFileExtension())) {
64  try {
65  Map<String, String> downKeys = (Map<String, String>) constructor.getSessionAttribute("downKeys");
66  if(downKeys == null) {
67  downKeys = new HashMap<>();
68  }
69  String key = Cipher.digest(attachment.getId() + "", 40);
70  downKeys.put(key, attachment.getId() + "");
71  constructor.setSessionAttribute("downKeys", downKeys);
72  return ElephantContext.getRootWebPath() +
73  "/_internal/js/pdfjs/web/roviewer.html?file=" +
74  ElephantContext.getRootWebPath() + DirectContents.DIRECT_CONTENT_PATH + getIdentifier() + "?id" + URLEncoder.encode("=", "UTF-8") + key;
75  } catch (UnsupportedEncodingException ex) {
76  Logger.getLogger(AttachDownload.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
77  return null;
78  }
79  } else {
80  return createURL(constructor, attachment);
81  }
82  }
static String createURL(IConstructor constructor, Attachment attachment)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createURL()

static String org.turro.attach.www.AttachDownload.createURL ( IConstructor  constructor,
Attachment  attachment 
)
static

Definition at line 51 of file AttachDownload.java.

51  {
52  Map<String, String> downKeys = (Map<String, String>) constructor.getSessionAttribute("downKeys");
53  if(downKeys == null) {
54  downKeys = new HashMap<>();
55  }
56  String key = Cipher.digest(attachment.getId() + "", 40);
57  downKeys.put(key, attachment.getId() + "");
58  constructor.setSessionAttribute("downKeys", downKeys);
59  return ElephantContext.getRootWebPath() + DirectContents.DIRECT_CONTENT_PATH + getIdentifier() + "?id=" + key;
60  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute()

void org.turro.attach.www.AttachDownload.execute ( ServletContext  context,
HttpServletRequest  request,
HttpServletResponse  response 
)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 99 of file AttachDownload.java.

99  {
100  Map downKeys = (Map) request.getSession().getAttribute("downKeys");
101  if(downKeys != null) {
102  String value = (String) downKeys.get(request.getParameter("id"));
103  if(value != null) {
104  Attachment attachment = new AttachPU().find(Attachment.class, Long.parseLong(value));
105  if(attachment != null) {
106  try {
107  String contentType = attachment.getFileContentType();
108  String fileName = attachment.getFileName();
109 
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");
113 
114  if(contentType!=null) {
115  response.setContentType(contentType);
116  }
117 
118  if(fileName != null) {
119  fileName = fileName.substring(fileName.lastIndexOf('\\')+1);
120  fileName = fileName.substring(fileName.lastIndexOf('/')+1);
121 
122  StringBuilder contentDisposition = new StringBuilder();
123 
124  contentDisposition.append("filename=\"");
125  contentDisposition.append(fileName);
126  contentDisposition.append("\"");
127 
128  response.setHeader("Content-Disposition", contentDisposition.toString());
129  response.setHeader("Content-Lenght", attachment.getFileSize() + "");
130  }
131 
132  byte[] bytes = attachment.getContentModified(Authentication.getIContact());//LoadContent.getContent(attachment);
133  if (bytes != null) {
134  response.getOutputStream().write(bytes);
135  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/attachment/" + attachment.getId(), "downloaded", null);
136  }
137  } catch (IOException | DocumentException ex) {
138  Logger.getLogger(AttachDownload.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
139  }
140  }
141  }
142  }
143  }
Here is the call graph for this function:

◆ getIdentifier()

static String org.turro.attach.www.AttachDownload.getIdentifier ( )
static

Definition at line 84 of file AttachDownload.java.

84  {
85  return AttachDownload.class.getAnnotation(DirectContent.class).identifier();
86  }

◆ itsMe()

boolean org.turro.attach.www.AttachDownload.itsMe ( String  id)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 89 of file AttachDownload.java.

89  {
90  return getIdentifier().equals(id);
91  }

◆ myTurn()

boolean org.turro.attach.www.AttachDownload.myTurn ( HttpServletRequest  request)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 94 of file AttachDownload.java.

94  {
95  return DirectContents.isYourTurn(request, getIdentifier());
96  }
Here is the call graph for this function:

The documentation for this class was generated from the following file: