if (uploadFile == null || uploadFile.getFileName() == null || uploadFile.getFileName().trim().equals("")) {
return upload.getUploadedForward();
}
LaunchSession launchSession = null;
VFSResource res = null;
try {
// Get the launch session
SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
launchSession = session == null ? null : LaunchSessionFactory.getInstance().getLaunchSession(session, upload.getExtraAttribute2());
if(launchSession == null) {
throw new Exception("No launch session.");
}
launchSession.checkAccessRights(null, session);
res = DAVServlet.getDAVResource(launchSession, request, response, upload.getResourcePath() + "/" + uploadFile.getFileName());
res.getFile().exists();
InputStream in = uploadFile.getInputStream();
OutputStream out = res.getOutputStream();
try {
byte[] buf = new byte[4096];
int read;
while (true) {
read = in.read(buf, 0, buf.length);
if (read == -1) {
break;
}
out.write(buf, 0, read);
}
} finally {
in.close();
out.close();
}
if (res.getMount().getStore().getProvider().isFireEvents()) {
CoreServlet.getServlet().fireCoreEvent(
NetworkPlaceResourceType.getResourceAccessUploadEvent(this, launchSession, request, res.getFullPath(), res.getFile().getName().getURI(), uploadFile
.getFileName(), null));
}
return upload.getUploadedForward();
} catch (Exception e) {
if (res != null && res.getMount().getStore().getProvider().isFireEvents()) {
CoreServlet.getServlet().fireCoreEvent(
NetworkPlaceResourceType.getResourceAccessUploadEvent(this, launchSession, request, res.getFullPath(), res.getFile().getName().getURI(), uploadFile
.getFileName(), e));
}
/*
* Close the stream so the client gets an error straight away rather
* than having to wait for the file to upload