public ActionForward confirmUpload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
if (log.isDebugEnabled())
log.debug("Execute file upload.");
UploadForm uploadForm = (UploadForm) form;
int uploadId = uploadForm.getUploadId();
UploadDetails upload = CoreUtil.getUpload(request.getSession(), uploadId);
if (upload == null) {
throw new Exception("No file upload details configured for upload id " + uploadId + ".");
}
int sessionTimeoutBlockId = LogonControllerFactory.getInstance().addSessionTimeoutBlock(request.getSession(),
"Upload request.");
try {
UploadHandler handler = UploadHandlerFactory.getInstance().getUploader(upload.getType());
if (handler == null) {
throw new Exception("No handler for upload type " + upload.getType());
}
request.setAttribute(Constants.REQ_ATTR_UPLOAD_DETAILS, new Integer(uploadId));
ActionForward fwd = handler.performUpload(request, response, upload, uploadForm.getUploadFile());
ActionMessages msgs = new ActionMessages();
if(upload.getResourcePath()==null) {
msgs.add(Globals.MESSAGE_KEY, new BundleActionMessage("vfs", "upload.info.fileUploadedNoPath", uploadForm.getUploadFile()
.getFileName()));
} else {
msgs.add(Globals.MESSAGE_KEY, new BundleActionMessage("vfs", "upload.info.fileUploaded", uploadForm.getUploadFile()
.getFileName(), upload.getResourcePath()));
}
saveMessages(request, msgs);
request.setAttribute(Constants.REQ_ATTR_UPLOAD_DETAILS, uploadId);
uploadForm.setUploadId(uploadId);
return fwd;
}
catch (CoreException ce) {
log.error("Failed to upload.", ce);
ActionMessages errs = getErrors(request);
errs.add(Globals.ERROR_KEY, ce.getBundleActionMessage());
saveErrors(request, errs);
if (null != upload.getUploadedForward())
return new RedirectWithMessages(upload.getUploadedForward(), request);
else
throw ce;
}
catch (Exception e) {
log.error("Failed to upload.", e);
ActionMessages msgs = new ActionMessages();
msgs.add(Globals.MESSAGE_KEY, new BundleActionMessage("vfs", "upload.info.fileNotUploaded", e.getMessage()));
saveErrors(request, msgs);
if (null != upload.getUploadedForward())
return upload.getUploadedForward();
else
throw e;
} finally {
LogonControllerFactory.getInstance().removeSessionTimeoutBlock(request.getSession(), sessionTimeoutBlockId);
}