}
private void processFileUpload( FileItem f, Map<String, String> params ) throws BadRequestException {
CollectionResource target = null;
if( wrappedResource == null ) {
throw new BadRequestException(this, "collection not found" );
}
target = (CollectionResource) wrappedResource.child( "uploads" );
if( target == null ) {
try {
if( wrappedResource instanceof MakeCollectionableResource ) {
MakeCollectionableResource mk = (MakeCollectionableResource) wrappedResource;
target = mk.createCollection( "uploads" );
} else {
throw new BadRequestException( target, "Cant create subfolder" );
}
} catch( ConflictException ex ) {
throw new RuntimeException( ex );
} catch( NotAuthorizedException ex ) {
throw new RuntimeException( ex );
} catch( BadRequestException ex ) {
throw new RuntimeException( ex );
}
}
String name = FileUtils.sanitiseName(f.getName() );
log.debug( "processFileUpload: " + name );
boolean isFirst = true;
String newName = null;
while( target.child( name ) != null ) {
name = FileUtils.incrementFileName( name, isFirst );
newName = name;
isFirst = false;
}
long size = f.getSize();
try {
if( target instanceof PutableResource ) {
PutableResource putable = (PutableResource) target;
Resource newRes = putable.createNew( name, f.getInputStream(), size, null );
if( newRes != null ) {
log.trace( "created: " + newRes.getName() + " of type: " + newRes.getClass() );
} else {
log.trace( "createNew returned null" );
}
} else {
throw new BadRequestException(target, "Does not implement PutableResource");
}
} catch( ConflictException ex ) {
throw new RuntimeException( ex );
} catch( NotAuthorizedException ex ) {
throw new RuntimeException( ex );