BrightSide Workbench Full Report + Source Code
org.turro.elephant.download.ContentDownload Class Reference
Inheritance diagram for org.turro.elephant.download.ContentDownload:
Collaboration diagram for org.turro.elephant.download.ContentDownload:

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, ContentStream onDownload)
 
static String getIdentifier ()
 

Static Public Attributes

static final MimetypesFileTypeMap MIME_TYPES_FILE_MAP = new MimetypesFileTypeMap()
 

Detailed Description

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

Definition at line 46 of file ContentDownload.java.

Member Function Documentation

◆ createURL()

static String org.turro.elephant.download.ContentDownload.createURL ( IConstructor  constructor,
ContentStream  onDownload 
)
static

Definition at line 51 of file ContentDownload.java.

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

◆ execute()

void org.turro.elephant.download.ContentDownload.execute ( ServletContext  context,
HttpServletRequest  request,
HttpServletResponse  response 
)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 77 of file ContentDownload.java.

77  {
78  Map<String, Predicate<ContentStream>> downKeys = (Map<String, Predicate<ContentStream>>) request.getSession().getAttribute(CONTENT_DOWNLOAD_KEY);
79  if(downKeys != null) {
80  ContentStream onDownload = (ContentStream) downKeys.get(request.getParameter("id"));
81  if(onDownload != null) {
82  try {
83  String fileName = onDownload.getFileName();
84  String contentType = MIME_TYPES_FILE_MAP.getContentType(fileName);
85 
86  response.setHeader("pragma", "no-cache");
87  response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
88  response.setHeader("Expires", "01 Apr 1995 01:10:10 GMT");
89 
90  if(contentType!=null) {
91  response.setContentType(contentType);
92  }
93 
94  if(fileName != null) {
95  fileName = fileName.substring(fileName.lastIndexOf('\\')+1);
96  fileName = fileName.substring(fileName.lastIndexOf('/')+1);
97 
98  StringBuilder contentDisposition = new StringBuilder();
99 
100  contentDisposition.append("filename=\"");
101  contentDisposition.append(fileName);
102  contentDisposition.append("\"");
103 
104  response.setHeader("Content-Disposition", contentDisposition.toString());
105  response.setHeader("Content-Lenght", onDownload.getFileSize() + "");
106  }
107 
108  IOUtils.copy(onDownload.getInputStream(), response.getOutputStream());
109 
110  SystemLogger.info()
111  .entityPath("/file" + ElephantContext.getRelativePath(onDownload.getAbsolutePath()))
112  .entityName(fileName).comment("downloaded")
113  .log();
114  } catch (IOException ex) {
115  Logger.getLogger(ContentDownload.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
116  }
117  }
118  }
119  }
static final MimetypesFileTypeMap MIME_TYPES_FILE_MAP
Here is the call graph for this function:

◆ getIdentifier()

static String org.turro.elephant.download.ContentDownload.getIdentifier ( )
static

Definition at line 62 of file ContentDownload.java.

62  {
63  return ContentDownload.class.getAnnotation(DirectContent.class).identifier();
64  }

◆ itsMe()

boolean org.turro.elephant.download.ContentDownload.itsMe ( String  id)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 67 of file ContentDownload.java.

67  {
68  return getIdentifier().equals(id);
69  }

◆ myTurn()

boolean org.turro.elephant.download.ContentDownload.myTurn ( HttpServletRequest  request)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 72 of file ContentDownload.java.

72  {
73  return DirectContents.isYourTurn(request, getIdentifier());
74  }
Here is the call graph for this function:

Member Data Documentation

◆ MIME_TYPES_FILE_MAP

final MimetypesFileTypeMap org.turro.elephant.download.ContentDownload.MIME_TYPES_FILE_MAP = new MimetypesFileTypeMap()
static

Definition at line 49 of file ContentDownload.java.


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