Package org.silverpeas.core.web.http
Class PreparedDownload
- java.lang.Object
-
- org.silverpeas.core.web.http.PreparedDownload
-
- All Implemented Interfaces:
Serializable
public class PreparedDownload extends Object implements Serializable
Prepared download means a download in two time.In a first time, from an AJAX request, a download is prepared and saved into a temporary file.
A JSON response is returned containing an object with the attributepreparedDownloadUrl
.In a second time, the prepared file is downloaded from
preparedDownloadUrl
and deleted from temporary files.The main objective of that is to get more control on UI in order to manage user navigation on file download.
- Author:
- silveryocha
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PreparedDownload(String fileName, String contentType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PreparedDownload
getFrom(javax.servlet.http.HttpServletRequest request)
Gets from the given request thePreparedDownload
instance registered into the session if any.static Optional<PreparedDownload>
getPreparedDownloadToPerform(javax.servlet.http.HttpServletRequest request, String fileName, String contentType)
Gets a newPreparedDownload
instance ifPREPARED_DOWNLOAD
is detected into request parameters.Writer
getWriter(String charset)
Gets the writer into which the content MUST be written.void
sendDetails(javax.servlet.http.HttpServletResponse response)
Sends the identifier into the response and put into sessions cache thisPreparedDownload
instance.void
sendTo(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Sends the prepared file into response with a download context.
-
-
-
Method Detail
-
getPreparedDownloadToPerform
public static Optional<PreparedDownload> getPreparedDownloadToPerform(javax.servlet.http.HttpServletRequest request, String fileName, String contentType)
Gets a newPreparedDownload
instance ifPREPARED_DOWNLOAD
is detected into request parameters.- Parameters:
request
- the request.fileName
- the filename which will be downloaded.contentType
- the content type of the content which will be downloaded.- Returns:
- an optional
PreparedDownload
instance.
-
getFrom
public static PreparedDownload getFrom(javax.servlet.http.HttpServletRequest request)
Gets from the given request thePreparedDownload
instance registered into the session if any.- Parameters:
request
- the request.- Returns:
- a
PreparedDownload
instance.
-
getWriter
public Writer getWriter(String charset) throws IOException
Gets the writer into which the content MUST be written.- Parameters:
charset
- the character encoding to set to the writer.- Returns:
- a
Writer
instance. - Throws:
IOException
- on technical error.
-
sendDetails
public void sendDetails(javax.servlet.http.HttpServletResponse response) throws IOException
Sends the identifier into the response and put into sessions cache thisPreparedDownload
instance.- Parameters:
response
- the response.- Throws:
IOException
- on technical error.
-
sendTo
public void sendTo(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Sends the prepared file into response with a download context.After a successful or an unsuccessful send, the file is deleted.
- Parameters:
request
- a request.response
- a response.
-
-