public abstract class AbstractViewFileServlet
extends javax.servlet.http.HttpServlet
| Constructor and Description |
|---|
AbstractViewFileServlet() |
| Modifier and Type | Method and Description |
|---|---|
protected String |
attachmentQuery(javax.servlet.http.HttpServletRequest request)
Validates that path is valid attachment path.
|
protected void |
copyRange(InputStream is,
OutputStream out,
RangeResponse rangeResponse) |
protected void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected Attachment |
getAttachment(String query)
Looks up the attachment by reading the id from the query string.
|
protected abstract int |
getContentLength(String attachmentPath) |
protected abstract void |
getInputStream(String attachmentPath,
InputStreamConsumer<com.atlassian.fugue.Unit> consumer)
Gets the attachment file (not the file name) that corresponds to the requested attachment.
|
protected ApplicationUser |
getLoggedInUser() |
protected boolean |
loggedInUserHasPermissionToViewAttachment(Attachment attachment)
Checks if the currently logged in user has permission to see the attachemnt.
|
protected abstract void |
setResponseHeaders(javax.servlet.http.HttpServletRequest request,
Optional<RangeResponse> rangeResponse,
javax.servlet.http.HttpServletResponse response)
Sets the content type, content length and "Content-Disposition" header
of the response based on the values of the attachment found.
|
protected abstract boolean |
supportsRangeRequests()
Returns true if this implementation supports RFC 7233 "Range Requests".
|
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, serviceprotected void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
IOException
doGet in class javax.servlet.http.HttpServletjavax.servlet.ServletExceptionIOExceptionprotected abstract int getContentLength(String attachmentPath)
protected abstract boolean supportsRangeRequests()
Returning true means that you must set the appropriate "Content-Range" and "Content-Length" headers for the
partial range we will return in the #setResponseHeaders implementation.
setResponseHeaders(HttpServletRequest, Optional, HttpServletResponse)protected void copyRange(InputStream is, OutputStream out, RangeResponse rangeResponse) throws IOException
IOExceptionprotected final String attachmentQuery(javax.servlet.http.HttpServletRequest request)
request - HTTP requestprotected Attachment getAttachment(String query)
query - eg. '/10000/foo.txt'AttachmentNotFoundException - if no attachment is found after parsing the query string
or if the resulting attachment id does not exist.DataAccessException - if there is a problem accessing the database.protected boolean loggedInUserHasPermissionToViewAttachment(Attachment attachment) throws DataAccessException
attachment - attachment to be checkedDataAccessException - if no such user exists.protected abstract void getInputStream(String attachmentPath, InputStreamConsumer<com.atlassian.fugue.Unit> consumer) throws IOException, PermissionException
attachmentPath - the attachment pathconsumer - a procedure that consumes the stream with the attachment data.DataAccessException - If there is a problem looking up the data to support the attachment.AttachmentNotFoundException - if the attachment does not exist.PermissionException - if the user has insufficient permission to see the attachment.IOException - if there is a problem getting the attachment.NoAttachmentDataException - if the attachment's contents cannot be found.AttachmentReadException - if a problem occurs when the consumer processes the attachment's contents.protected abstract void setResponseHeaders(javax.servlet.http.HttpServletRequest request,
Optional<RangeResponse> rangeResponse,
javax.servlet.http.HttpServletResponse response)
throws InvalidAttachmentPathException,
DataAccessException,
IOException
The rangeResponse parameter will only be present if this Concrete class declares it supports Range Requests, and the request actually contains a Range header.
request - HTTP requestrangeResponse - If present, the partial byte range we will returnresponse - HTTP responseInvalidAttachmentPathExceptionDataAccessExceptionIOExceptionsupportsRangeRequests()protected final ApplicationUser getLoggedInUser()
Copyright © 2002-2017 Atlassian. All Rights Reserved.