// check lock-null resources
try {
if (isLockNull(sourceUri)) {
int statusCode = WebdavStatus.SC_NOT_FOUND;
sendError( statusCode, "lock-null resource", new Object[]{sourceUri} );
throw new WebdavException( statusCode );
}
}
catch (ServiceAccessException e) {
int statusCode = getErrorCode((Exception)e);
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
// check destination URI
UriHandler destUh = UriHandler.getUriHandler(destinationUri);
if( VersionControlMethod.VERSIONCONTROL_EXCLUDEPATH != null && VersionControlMethod.VERSIONCONTROL_EXCLUDEPATH.length() > 0 ) {
UriHandler exUh = UriHandler.getUriHandler( VersionControlMethod.VERSIONCONTROL_EXCLUDEPATH );
if( exUh.isAncestorOf(destUh) )
isInVersioncontrolExcludePath = true;
}
if (destUh.isRestrictedUri()) {
boolean sendError = true;
if( destUh.isWorkspaceUri() ||
destUh.isWorkingresourceUri()
) {
// COPY on existing WSs or WRs is *not* restricted !!!
try {
content.retrieve(slideToken, destinationUri);
sendError = false;
}
catch( ServiceAccessException x ) {
int statusCode = getErrorCode((SlideException)x);
sendError( statusCode, x );
throw new WebdavException( statusCode );
}
catch( SlideException x ) {};
}
if( sendError ) {
int statusCode = WebdavStatus.SC_FORBIDDEN;
sendError( statusCode, getClass().getName()+".restrictedDestinationUri", new Object[]{destinationUri} );
throw new WebdavException( statusCode );
}
}
try {
// compare resource types of source and destination
boolean sameResourceType = isSameResourcetype();
int depth = requestHeaders.getDepth(INFINITY);
if (depth != 0 && depth != INFINITY) {
int sc = WebdavStatus.SC_PRECONDITION_FAILED;
sendError( sc, "Invalid header Depth: "+depth );
throw new WebdavException( sc );
}
boolean recursive = (depth == INFINITY);
if (overwrite && sameResourceType) {
macroParameters = new MacroParameters(recursive, true, false);
}
else if (overwrite && !sameResourceType) {
macroParameters = new MacroParameters(recursive, true, true);
}
else {
macroParameters = new MacroParameters(recursive, false, false);
}
boolean destinationExistsBefore = exists( destinationUri );
if (!overwrite && destinationExistsBefore) {
int statusCode = WebdavStatus.SC_PRECONDITION_FAILED;
sendError( statusCode, getClass().getName()+".noOverwrite", new Object[]{destinationUri} );
throw new WebdavException( statusCode );
}
macro.copy(slideToken, sourceUri, destinationUri, macroParameters, this, this, null, this);
if (overwrite && destinationExistsBefore) {
resp.setStatus(WebdavStatus.SC_NO_CONTENT);
} else {
resp.setStatus(WebdavStatus.SC_CREATED);
}
} catch (MacroException e) {
if(generateMultiStatusResponse(isCollection, e, requestUri)) {
String errorMessage = generateErrorMessage(e);
// Write it on the servlet writer
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
try {
resp.setContentType(TEXT_XML_UTF_8);
resp.getWriter().write(errorMessage);
} catch(IOException ex) {
// Critical error ... Servlet container is dead or something
int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
} else {
// Returning 207 on non-collection requests is generally
// considered bad. So let's not do it, since this way
// makes clients generally behave better.
SlideException exception = (SlideException)e.enumerateExceptions().nextElement();
if (exception instanceof PreconditionViolationException) {
try {
sendPreconditionViolation((PreconditionViolationException)exception);
} catch(IOException ex) {
// Critical error ... Servlet container is dead or something
int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
}
else {
int statusCode = getErrorCode( exception );
sendError( statusCode, exception );
throw new WebdavException( statusCode );
}
}
//
// make sure the transaction is aborted
// throw any WebDAV exception to indicate the transaction wants to be aborted
//
throw new WebdavException(WebdavStatus.SC_ACCEPTED, false);
}
catch (WebdavException e) {
throw e;
}
catch (SlideException e) {
int statusCode = getErrorCode( e );
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
}