/** * Create a new {@link XWikiDavResourceFactory}. */ public XWikiDavResourceFactory(ServletContext servletContext) throws ServletException { this.lockManager = new SimpleLockManager(); this.servletContext = servletContext; }
/** * Looks for a valid lock at the given path or a deep lock present with * a parent path. * * @param path * @return */ private ActiveLock getLock(String path) { ActiveLock lock = locks.get(path); if (lock != null) { // check if not expired if (lock.isExpired()) { lock = null; } } if (lock == null) { // check, if child of deep locked parent if (!path.equals("/")) { ActiveLock parentLock = getLock(getParentPath(path)); if (parentLock != null && parentLock.isDeep()) { lock = parentLock; } } } return lock; }
if (isDescendant(key, resourcePath)) { ActiveLock l = locks.get(key); if (l.isDeep() || (key.equals(getParentPath(resourcePath)) && !resource.isCollection())) { throw new DavException(DavServletResponse.SC_LOCKED, "Resource '" + resource.getResourcePath() + "' already inherits a lock by its collection."); } else if (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 + "'.");
/** * Recursivly tries to find the lock * * @param path * @return */ private ActiveLock getLock(String path) { ActiveLock lock = (ActiveLock) locks.get(path); if (lock != null) { // check if not expired if (lock.isExpired()) { lock = null; } } if (lock == null) { // check, if child of deep locked parent if (!path.equals("/")) { ActiveLock parentLock = getLock(Text.getRelativeParent(path, 1)); if (parentLock != null && parentLock.isDeep()) { lock = parentLock; } } } return lock; }
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 + "'.");
/** * Return true, if the resource with the given memberPath is a internal * non-collection member of the given resource, thus affected by a * non-deep lock present on the resource. * * @param resource * @param memberPath * @return */ private static boolean isInternalMember(DavResource resource, String memberPath) { if (resource.getResourcePath().equals(getParentPath(memberPath))) { // find the member with the given path DavResourceIterator it = resource.getMembers(); while (it.hasNext()) { DavResource member = it.nextResource(); if (member.getResourcePath().equals(memberPath)) { // return true if that member is not a collection return !member.isCollection(); } } } return false; }
if (isDescendant(key, resourcePath)) { ActiveLock l = locks.get(key); if (l.isDeep() || (key.equals(getParentPath(resourcePath)) && !resource.isCollection())) { throw new DavException(DavServletResponse.SC_LOCKED, "Resource '" + resource.getResourcePath() + "' already inherits a lock by its collection."); } else if (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 + "'.");
/** * Returns the lock applying to the given resource or <code>null</code> if * no lock can be found. * * @param type * @param scope * @param resource * @return lock that applies to the given resource or <code>null</code>. */ public synchronized ActiveLock getLock(Type type, Scope scope, DavResource resource) { if (!(Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope))) { return null; } return getLock(resource.getResourcePath()); }
/** * Return true, if the resource with the given memberPath is a internal * non-collection member of the given resource, thus affected by a * non-deep lock present on the resource. * * @param resource * @param memberPath * @return */ private static boolean isInternalMember(DavResource resource, String memberPath) { if (resource.getResourcePath().equals(getParentPath(memberPath))) { // find the member with the given path DavResourceIterator it = resource.getMembers(); while (it.hasNext()) { DavResource member = it.nextResource(); if (member.getResourcePath().equals(memberPath)) { // return true if that member is not a collection return !member.isCollection(); } } } return false; }
/** * Returns the lock applying to the given resource or <code>null</code> if * no lock can be found. * * @param type * @param scope * @param resource * @return lock that applies to the given resource or <code>null</code>. */ public synchronized ActiveLock getLock(Type type, Scope scope, DavResource resource) { if (!(Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope))) { return null; } return getLock(resource.getResourcePath()); }
/** * Looks for a valid lock at the given path or a deep lock present with * a parent path. * * @param path * @return */ private ActiveLock getLock(String path) { ActiveLock lock = locks.get(path); if (lock != null) { // check if not expired if (lock.isExpired()) { lock = null; } } if (lock == null) { // check, if child of deep locked parent if (!path.equals("/")) { ActiveLock parentLock = getLock(getParentPath(path)); if (parentLock != null && parentLock.isDeep()) { lock = parentLock; } } } return lock; }
/** * Returns the <code>LockManager</code>. If no lock manager has * been set or created a new instance of {@link SimpleLockManager} is * returned. * * @return the lock manager */ public LockManager getLockManager() { if (lockManager == null) { lockManager = new SimpleLockManager(); } return lockManager; }
/** * Returns the lock applying to the given resource or <code>null</code> if * no lock can be found. * * @param type * @param scope * @param resource * @return lock that applies to the given resource or <code>null</code>. */ public synchronized ActiveLock getLock(Type type, Scope scope, DavResource resource) { if (!(Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope))) { return null; } return getLock(resource.getResourcePath()); }
/** * * @param lockInfo * @param lockToken * @param resource * @return * @throws DavException * @see DavResource#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, String) */ public ActiveLock refreshLock(LockInfo lockInfo, String lockToken, DavResource resource) throws DavException { ActiveLock lock = getLock(lockInfo.getType(), lockInfo.getScope(), resource); if (lock == null) { throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED); } else if (!lock.getToken().equals(lockToken)) { throw new DavException(DavServletResponse.SC_LOCKED); } lock.setTimeout(lockInfo.getTimeout()); return lock; }
/** * * @param lockInfo * @param lockToken * @param resource * @return * @throws DavException * @see DavResource#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, String) */ public ActiveLock refreshLock(LockInfo lockInfo, String lockToken, DavResource resource) throws DavException { ActiveLock lock = getLock(lockInfo.getType(), lockInfo.getScope(), resource); if (lock == null) { throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED); } else if (!lock.getToken().equals(lockToken)) { throw new DavException(DavServletResponse.SC_LOCKED); } lock.setTimeout(lockInfo.getTimeout()); return lock; }
/** * * @param lockInfo * @param lockToken * @param resource * @return * @throws DavException * @see DavResource#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, String) */ public ActiveLock refreshLock(LockInfo lockInfo, String lockToken, DavResource resource) throws DavException { ActiveLock lock = getLock(lockInfo.getType(), lockInfo.getScope(), resource); if (lock == null) { throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED); } else if (!lock.getToken().equals(lockToken)) { throw new DavException(DavServletResponse.SC_LOCKED); } lock.setTimeout(lockInfo.getTimeout()); return lock; }