private File extractFile(WebResource resource) { if (resource instanceof VFSResource) { VFSResource vResource = (VFSResource) resource; return extractFile(vResource.getItem()); } return null; }
private VFSItem extractItem(WebResource resource) { if (resource instanceof VFSResource) { VFSResource vResource = (VFSResource) resource; return vResource.getItem(); } return null; }
/** * Check to see if a resource is currently write locked. * * @param path Path of the resource * @param ifHeader "If" HTTP header which was included in the request * @return boolean true if the resource is locked (and no appropriate lock token has been found * for at least one of the non-shared locks which are present on the resource). */ public boolean isLocked(WebResource resource, String ifHeader, Identity identity) { // Checking resource locks String path = resource.getPath(); // check if someone else as not set a lock on the resource if (resource instanceof VFSResource) { VFSResource vfsResource = (VFSResource) resource; Long lockedBy = getMetaLockedBy(vfsResource.getItem()); if (lockedBy != null && !lockedBy.equals(identity.getKey())) { return true; } } File file = extractFile(resource); if (file == null) { return false; // lock only file } LockInfo lock = fileLocks.get(file); if (lock != null && lock.hasExpired()) { fileLocks.remove(file); } else if (lock != null) { // At least one of the tokens of the locks must have been given Iterator<String> tokenList = lock.tokens(); boolean tokenMatch = false; while (tokenList.hasNext()) { String token = tokenList.next(); if (ifHeader.indexOf(token) != -1) { tokenMatch = true; break; } } if (!tokenMatch) return true; } // Checking inheritable collection locks Enumeration<LockInfo> collectionLocksList = collectionLocks.elements(); while (collectionLocksList.hasMoreElements()) { lock = collectionLocksList.nextElement(); if (lock.hasExpired()) { collectionLocks.removeElement(lock); } else if (path.startsWith(lock.getWebPath())) { Iterator<String> tokenList = lock.tokens(); boolean tokenMatch = false; while (tokenList.hasNext()) { String token = tokenList.next(); if (ifHeader.indexOf(token) != -1) { tokenMatch = true; break; } } if (!tokenMatch) return true; } } return false; }