public ActionForward downloadFile(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException {
final GenericApplication application = getDomainObject(request, "applicationExternalId");
final String confirmationCode = (String) getFromRequest(request, "confirmationCode");
final GenericApplicationFile file = getDomainObject(request, "fileExternalId");
if (application != null
&& file != null
&& file.getGenericApplication() == application
&& ((confirmationCode != null && application.getConfirmationCode() != null && application.getConfirmationCode()
.equals(confirmationCode)) || application.getGenericApplicationPeriod().isCurrentUserAllowedToMange())) {
response.setContentType(file.getContentType());
response.addHeader("Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\"");
response.setContentLength(file.getSize().intValue());
final DataOutputStream dos = new DataOutputStream(response.getOutputStream());
dos.write(file.getContent());
dos.close();
} else {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST));
response.getWriter().close();