| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.web.servlets; |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
import java.io.IOException; |
| 23 |
|
|
| 24 |
|
import javax.servlet.ServletConfig; |
| 25 |
|
import javax.servlet.ServletException; |
| 26 |
|
import javax.servlet.ServletOutputStream; |
| 27 |
|
import javax.servlet.http.HttpServletRequest; |
| 28 |
|
import javax.servlet.http.HttpServletResponse; |
| 29 |
|
import javax.servlet.http.HttpSession; |
| 30 |
|
|
| 31 |
|
import org.apache.log4j.Logger; |
| 32 |
|
import org.apache.struts.action.ActionErrors; |
| 33 |
|
import org.apache.struts.action.ActionMessage; |
| 34 |
|
import org.apache.struts.action.ActionMessages; |
| 35 |
|
import org.itracker.model.IssueAttachment; |
| 36 |
|
import org.itracker.model.User; |
| 37 |
|
import org.itracker.services.IssueService; |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@deprecated |
| 41 |
|
|
|
|
|
| 0% |
Uncovered Elements: 58 (58) |
Complexity: 12 |
Complexity Density: 0.29 |
|
| 42 |
|
public class AttachmentDownloadController extends GenericController { |
| 43 |
|
|
| 44 |
|
private static final Logger logger = Logger.getLogger(AttachmentDownloadController.class); |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
private static final long serialVersionUID = 1L; |
| 49 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 50 |
0
|
public AttachmentDownloadController() {... |
| 51 |
|
} |
| 52 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 53 |
0
|
public void init(ServletConfig config) {... |
| 54 |
|
} |
| 55 |
|
|
|
|
|
| 0% |
Uncovered Elements: 55 (55) |
Complexity: 10 |
Complexity Density: 0.24 |
|
| 56 |
0
|
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {... |
| 57 |
0
|
ServletOutputStream out = null; |
| 58 |
|
|
| 59 |
0
|
if(! isLoggedInWithRedirect(request, response)) { |
| 60 |
0
|
return; |
| 61 |
|
} |
| 62 |
|
|
| 63 |
0
|
HttpSession session = request.getSession(); |
| 64 |
0
|
User user = (User) session.getAttribute("user"); |
| 65 |
0
|
try { |
| 66 |
0
|
IssueService issueService = getITrackerServices(request.getSession().getServletContext() ).getIssueService(); |
| 67 |
|
|
| 68 |
0
|
Integer attachmentId = null; |
| 69 |
0
|
IssueAttachment attachment = null; |
| 70 |
|
|
| 71 |
0
|
try { |
| 72 |
0
|
attachmentId = new Integer((request.getParameter("id") == null ? "-1" : (request.getParameter("id")))); |
| 73 |
0
|
attachment = issueService.getIssueAttachment(attachmentId); |
| 74 |
|
} catch(NumberFormatException nfe) { |
| 75 |
0
|
if(logger.isDebugEnabled()) { |
| 76 |
0
|
logger.debug("Invalid attachmentId " + request.getParameter("id") + " specified."); |
| 77 |
|
} |
| 78 |
|
} |
| 79 |
|
|
| 80 |
0
|
if(attachment == null) { |
| 81 |
0
|
ActionErrors errors = new ActionErrors(); |
| 82 |
0
|
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidattachment")); |
| 83 |
0
|
saveMessages(request, errors); |
| 84 |
0
|
forward("/themes/defaulttheme/error.jsp", request, response); |
| 85 |
0
|
return; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
0
|
if(! issueService.canViewIssue(attachment.getIssue().getId(), user)) { |
| 89 |
0
|
forward("/themes/defaulttheme/unauthorized.jsp", request, response); |
| 90 |
0
|
return; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
0
|
byte[] fileData = issueService.getIssueAttachmentData(attachmentId); |
| 94 |
0
|
if(fileData == null) { |
| 95 |
0
|
ActionErrors errors = new ActionErrors(); |
| 96 |
0
|
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.missingattachmentdata")); |
| 97 |
0
|
saveMessages(request, errors); |
| 98 |
0
|
forward("/themes/defaulttheme/error.jsp", request, response); |
| 99 |
0
|
return; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
0
|
response.setContentType(attachment.getType()); |
| 103 |
0
|
response.setHeader("Content-Disposition", "inline; filename=" + attachment.getOriginalFileName() + ""); |
| 104 |
0
|
out = response.getOutputStream(); |
| 105 |
0
|
logger.debug("Displaying attachment " + attachment.getId() + " of type " + attachment.getType() + " to client. Attachment size: " + fileData.length); |
| 106 |
0
|
out.write(fileData); |
| 107 |
|
} catch(IOException ioe) { |
| 108 |
0
|
logger.info("Unable to display attachment.", ioe); |
| 109 |
|
} catch(Exception e) { |
| 110 |
0
|
logger.error( e.getMessage(), e ); |
| 111 |
|
} finally { |
| 112 |
0
|
if(out != null) { |
| 113 |
0
|
out.flush(); |
| 114 |
0
|
out.close(); |
| 115 |
|
} |
| 116 |
|
} |
| 117 |
|
|
| 118 |
0
|
return; |
| 119 |
|
} |
| 120 |
|
} |