*/
public ActionForward renameFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled())
log.debug("rename the file.");
FileSystemForm fileSystemForm = (FileSystemForm) form;
checkLaunchSession(request, response, fileSystemForm);
ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
if (fwd != null) {
return fwd;
}
VFSResource sourceResource = null;
VFSResource destResource = null;
try {
sourceResource = getResourceForPath(fileSystemForm.getLaunchSession(),
request,
response,
fileSystemForm.getPath() + "/" + fileSystemForm.getFileName());
destResource = getResourceForPath(fileSystemForm.getLaunchSession(), request, response, fileSystemForm.getPath() + "/"
+ fileSystemForm.getNewName());
if (sourceResource == null) {
throw new Exception("Could not locate source resource '" + fileSystemForm.getPath()
+ "/"
+ fileSystemForm.getFileName()
+ "'");
}
if (destResource == null) {
throw new Exception("Could not locate destination resource '" + fileSystemForm.getPath()
+ "/"
+ fileSystemForm.getNewName()
+ "'");
}
if(sourceResource.getFullPath().equals(destResource.getFullPath())) {
return mapping.findForward("list");
}
fwd = checkMount(destResource, mapping, fileSystemForm, request);
if (fwd != null) {
return fwd;
}
sourceResource.move(destResource, true);
if (sourceResource.getMount().getStore().getProvider().isFireEvents()) {
CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessRenameEvent(this,
fileSystemForm.getLaunchSession(),
request,
fileSystemForm.getPath(),
fileSystemForm.getFullURI(),
sourceResource.getDisplayName(),
destResource.getDisplayName(),
null));
}
} catch (DAVAuthenticationRequiredException e) {
AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm());
return null;
} catch (Exception e) {
if (sourceResource != null && destResource != null) {
if (sourceResource.getMount().getStore().getProvider().isFireEvents()) {
CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessRenameEvent(this,
fileSystemForm.getLaunchSession(),
request,
fileSystemForm.getPath(),
fileSystemForm.getFullURI(),
sourceResource.getDisplayName(),
destResource.getDisplayName(),
e));
}
}