String host = request.getHostHeader();
String urlToCreateOrUpdate = HttpManager.decodeUrl( request.getAbsolutePath() );
log.debug( "process request: host: " + host + " url: " + urlToCreateOrUpdate );
Path path = Path.path( urlToCreateOrUpdate );
urlToCreateOrUpdate = path.toString();
Resource existingResource = manager.getResourceFactory().getResource( host, urlToCreateOrUpdate );
ReplaceableResource replacee;
StorageErrorReason storageErr = null;
if( existingResource != null ) {
//Make sure the parent collection is not locked by someone else
if( handlerHelper.isLockedOut( request, existingResource ) ) {
log.warn( "resource is locked, but not by the current user" );
respondLocked( request, response, existingResource );
return;
}
Resource parent = manager.getResourceFactory().getResource( host, path.getParent().toString() );
if( parent instanceof CollectionResource ) {
CollectionResource parentCol = (CollectionResource) parent;
storageErr = handlerHelper.checkStorageOnReplace( request, parentCol, existingResource, host );
} else {
log.warn( "parent exists but is not a collection resource: " + path.getParent() );
}
} else {
CollectionResource parentCol = putHelper.findNearestParent( manager, host, path );
storageErr = handlerHelper.checkStorageOnAdd( request, parentCol, path.getParent(), host );
}
if( storageErr != null ) {
respondInsufficientStorage( request, response, storageErr );
return;
}
if( existingResource != null && existingResource instanceof ReplaceableResource ) {
replacee = (ReplaceableResource) existingResource;
} else {
replacee = null;
}
if( replacee != null ) {
if( log.isTraceEnabled() ) {
log.trace( "replacing content in: " + replacee.getName() + " - " + replacee.getClass() );
}
long t = System.currentTimeMillis();
try {
manager.onProcessResourceStart( request, response, replacee );
processReplace( manager, request, response, replacee );
} finally {
t = System.currentTimeMillis() - t;
manager.onProcessResourceFinish( request, response, replacee, t );
}
} else {
// either no existing resource, or its not replaceable. check for folder
String nameToCreate = path.getName();
CollectionResource folderResource = findOrCreateFolders( manager, host, path.getParent() );
if( folderResource != null ) {
long t = System.currentTimeMillis();
try {
if( folderResource instanceof PutableResource ) {