this.wrapped = copyableResource;
this.resourceFactory = resourceFactory;
}
public String processForm( Map<String, String> parameters, Map<String, FileItem> files ) throws BadRequestException, NotAuthorizedException {
String dest = parameters.get( "destination");
Path pDest = Path.path( dest );
Resource rDestParent = resourceFactory.getResource( host, pDest.getParent().toString());
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 {
wrapped.copyTo( 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());
throw new BadRequestException( rDestParent, "File already exists");
}
} else {
throw new BadRequestException( wrapped, "The destination parent is not a collection resource");
}