com.atlassian.jira.web.servlet
Class ViewAttachmentServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.atlassian.jira.web.servlet.AbstractViewFileServlet
              extended by com.atlassian.jira.web.servlet.ViewAttachmentServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ViewThumbnailServlet

public class ViewAttachmentServlet
extends AbstractViewFileServlet

See Also:
Serialized Form

Constructor Summary
ViewAttachmentServlet()
           
 
Method Summary
protected  Attachment getAttachment(java.lang.String query)
          Looks up the attachment by reading the id from the query string.
protected  java.io.File getFileName(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Returns the file of the attachment.
protected  boolean hasPermissionToViewAttachment(java.lang.String username, Attachment attachment)
          Checks if the given user had permission to see the attachemnt.
 void init(javax.servlet.ServletConfig servletConfig)
           
protected  void setResponseHeaders(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Sets the content type, content length and "Content-Disposition" header of the response based on the values of the attachement found.
 
Methods inherited from class com.atlassian.jira.web.servlet.AbstractViewFileServlet
attachmentPath, doGet, getUserName
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ViewAttachmentServlet

public ViewAttachmentServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig servletConfig)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

getFileName

protected java.io.File getFileName(javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response)
                            throws DataAccessException,
                                   PermissionException
Returns the file of the attachment.

Specified by:
getFileName in class AbstractViewFileServlet
Parameters:
request - HTTP request
response - HTTP response
Returns:
attachment file
Throws:
DataAccessException - if attachment or user cannot be retrieved due to some kind of db access problem.
PermissionException - if user is denied permission to see the attachment

getAttachment

protected Attachment getAttachment(java.lang.String query)
Looks up the attachment by reading the id from the query string.

Parameters:
query - eg. '/10000/foo.txt'
Returns:
attachment found

setResponseHeaders

protected void setResponseHeaders(javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response)
                           throws AttachmentNotFoundException,
                                  java.io.IOException
Sets the content type, content length and "Content-Disposition" header of the response based on the values of the attachement found.

Specified by:
setResponseHeaders in class AbstractViewFileServlet
Parameters:
request - HTTP request
response - HTTP response
Throws:
AttachmentNotFoundException
java.io.IOException

hasPermissionToViewAttachment

protected boolean hasPermissionToViewAttachment(java.lang.String username,
                                                Attachment attachment)
                                         throws DataAccessException
Checks if the given user had permission to see the attachemnt.

Parameters:
username - username of the user who wants to see the attachment
attachment - attachment to be checked
Returns:
true if user can see the attachment, false otherwise
Throws:
DataAccessException - if no such user exists.


Copyright © 2002-2010 Atlassian. All Rights Reserved.