if (lock != null && lock.isExpired()) {
locks.remove(resourcePath);
lock = null;
}
if (lock != null) {
throw new DavException(DavServletResponse.SC_LOCKED, "Resource '" + resource.getResourcePath() + "' already holds a lock.");
}
// test if the new lock would conflict with any lock inherited from the
// collection or with a lock present on any member resource.
for (String key : locks.keySet()) {
// TODO: is check for lock on internal-member correct?
if (Text.isDescendant(key, resourcePath)) {
ActiveLock l = locks.get(key);
if (l.isDeep() || (key.equals(Text.getRelativeParent(resourcePath, 1)) && !resource.isCollection())) {
throw new DavException(DavServletResponse.SC_LOCKED, "Resource '" + resource.getResourcePath() + "' already inherits a lock by its collection.");
}
} else if (Text.isDescendant(resourcePath, key)) {
if (lockInfo.isDeep() || isInternalMember(resource, key)) {
throw new DavException(DavServletResponse.SC_CONFLICT, "Resource '" + resource.getResourcePath() + "' cannot be locked due to a lock present on the member resource '" + key + "'.");
}
}
}
lock = new DefaultActiveLock(lockInfo);