this.resourceFactory = resourceFactory;
}
public String processForm( Map<String, String> parameters, Map<String, FileItem> files ) throws BadRequestException, NotAuthorizedException {
String dest = parameters.get( "destination");
if( dest == null ) {
throw new BadRequestException(this, "The destination parameter is null");
} else if (dest.trim().length() == 0 ) {
throw new BadRequestException(this, "The destination parameter is empty");
}
Path pDest = Path.path( dest );
if( pDest == null ) {
throw new BadRequestException(this, "Couldnt parse the destination header, returned null from: " + dest);
}
String parentPath = "/";
if( pDest.getParent() != null ) {
parentPath = pDest.getParent().toString();
}
Resource rDestParent = resourceFactory.getResource( host, parentPath);
if( rDestParent == null ) throw new BadRequestException( wrapped, "The destination parent does not exist");
if(rDestParent instanceof CollectionResource ) {
CollectionResource colDestParent = (CollectionResource) rDestParent;
if( colDestParent.child( pDest.getName()) == null ) {
try {
System.out.println("move to: " + colDestParent.getName());
wrapped.moveTo( colDestParent, pDest.getName() );
} catch( ConflictException ex ) {
log.warn( "Exception copying to: " + pDest.getName(), ex);
throw new BadRequestException( rDestParent, "conflict: " + ex.getMessage());
}
return null;
} else {
log.warn( "destination already exists: " + pDest.getName() + " in folder: " + colDestParent.getName());
throw new BadRequestException( rDestParent, "File already exists");
}
} else {
throw new BadRequestException( wrapped, "The destination parent is not a collection resource");
}
}