DAVResponse resp = new DAVResponse(null, resource.getResourceURI().getRequestURI(), response, null, exception.getResponseCode());
return resp;
}
public void validateResourceState(LinkedList ifHeaders, DAVResource resource, DAVLockInfoProvider provider, DAVLockScope lockScope, int flags) throws DAVException {
DAVLock lock = null;
if (provider != null) {
try {
lock = provider.getLock(resource);
} catch (DAVException dave) {
throw new DAVException("The locks could not be queried for verification against a possible \"If:\" header.", null,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, SVNLogType.NETWORK, Level.FINE, dave, null, null, 0, null);
}
}
boolean seenLockToken = false;
if (lockScope == DAVLockScope.EXCLUSIVE) {
if (lock != null) {
throw new DAVException("Existing lock(s) on the requested resource prevent an exclusive lock.", ServletDAVHandler.SC_HTTP_LOCKED, 0);
}
seenLockToken = true;
} else if (lockScope == DAVLockScope.SHARED) {
if (lock.getScope() == DAVLockScope.EXCLUSIVE) {
throw new DAVException("The requested resource is already locked exclusively.", ServletDAVHandler.SC_HTTP_LOCKED, 0);
}
seenLockToken = true;
} else {
seenLockToken = lock == null;
}
if (ifHeaders == null || ifHeaders.isEmpty()) {
if (seenLockToken) {
return;
}
throw new DAVException("This resource is locked and an \"If:\" header was not supplied to allow access to the resource.",
ServletDAVHandler.SC_HTTP_LOCKED, 0);
}
DAVIFHeader ifHeader = (DAVIFHeader) ifHeaders.getFirst();
if (lock == null && ifHeader.isDummyHeader()) {
if ((flags & ServletDAVHandler.DAV_VALIDATE_IS_PARENT) != 0) {
return;
}
throw new DAVException("The locktoken specified in the \"Lock-Token:\" header is invalid because this resource has no outstanding locks.",
HttpServletResponse.SC_BAD_REQUEST, 0);
}
String eTag = resource.getETag();
String uri = DAVPathUtil.dropTraillingSlash(resource.getResourceURI().getRequestURI());
int numThatAppy = 0;
String reason = null;
Iterator ifHeadersIter = ifHeaders.iterator();
for (;ifHeadersIter.hasNext();) {
ifHeader = (DAVIFHeader) ifHeadersIter.next();
if (ifHeader.getURI() != null && !uri.equals(ifHeader.getURI())) {
continue;
}
++numThatAppy;
LinkedList stateList = ifHeader.getStateList();
boolean doContinue = false;
for (Iterator stateListIter = stateList.iterator(); stateListIter.hasNext();) {
DAVIFState state = (DAVIFState) stateListIter.next();
if (state.getType() == DAVIFStateType.IF_ETAG) {
String currentETag = null;
String givenETag = null;
String stateETag = state.getETag();
if (stateETag.startsWith("W/")) {
givenETag = stateETag.substring(2);
} else {
givenETag = stateETag;
}
if (eTag.startsWith("W/")) {
currentETag = eTag.substring(2);
} else {
currentETag = eTag;
}
boolean eTagsDoNotMatch = !givenETag.equals(currentETag);
if (state.getCondition() == DAVIFState.IF_CONDITION_NORMAL && eTagsDoNotMatch) {
reason = "an entity-tag was specified, but the resource's actual ETag does not match.";
doContinue = true;
break;
} else if (state.getCondition() == DAVIFState.IF_CONDITION_NOT && !eTagsDoNotMatch) {
reason = "an entity-tag was specified using the \"Not\" form, but the resource's actual ETag matches the provided entity-tag.";
doContinue = true;
break;
}
} else if (state.getType() == DAVIFStateType.IF_OPAQUE_LOCK) {
if (provider == null) {
if (state.getCondition() == DAVIFState.IF_CONDITION_NOT) {
continue;
}
reason = "a State-token was supplied, but a lock database is not available for to provide the required lock.";
doContinue = true;
break;
}
boolean matched = false;
if (lock != null) {
if (!lock.getLockToken().equals(state.getLockToken())) {
continue;
}
seenLockToken = true;
if (state.getCondition() == DAVIFState.IF_CONDITION_NOT) {
reason = "a State-token was supplied, which used a \"Not\" condition. The State-token was found in the locks on this resource";
doContinue = true;
break;
}
String lockAuthUser = lock.getAuthUser();
String requestUser = resource.getUserName();
if (lockAuthUser != null && (requestUser == null || !lockAuthUser.equals(requestUser))) {
throw new DAVException("User \"{0}\" submitted a locktoken created by user \"{1}\".",
new Object[] { requestUser, lockAuthUser }, HttpServletResponse.SC_FORBIDDEN, 0);
}