Search in sources :

Example 6 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class TxLockManagerImpl method getLock.

/**
     * Return the lock applied to the given resource or <code>null</code>
     *
     * @param type
     * @param scope
     * @param resource
     * @return lock applied to the given resource or <code>null</code>
     * @see LockManager#getLock(Type, Scope, DavResource)
     *      todo: is it correct to return one that specific lock, the current session is token-holder of?
     */
public ActiveLock getLock(Type type, Scope scope, TransactionResource resource) {
    ActiveLock lock = null;
    if (TransactionConstants.TRANSACTION.equals(type)) {
        String[] sessionTokens = resource.getSession().getLockTokens();
        int i = 0;
        while (lock == null && i < sessionTokens.length) {
            String lockToken = sessionTokens[i];
            lock = getLock(lockToken, scope, resource);
            i++;
        }
    }
    return lock;
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) TxActiveLock(org.apache.jackrabbit.webdav.transaction.TxActiveLock)

Example 7 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class DefaultItemCollection method unlock.

/**
     * Remove the write lock from this resource by unlocking the underlying
     * {@link javax.jcr.Node node}.
     *
     * @param lockToken
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.DavResource#unlock(String)
     * @see javax.jcr.Node#unlock()
     */
@Override
public void unlock(String lockToken) throws DavException {
    ActiveLock lock = getWriteLock();
    if (lock != null && lockToken.equals(lock.getToken())) {
        try {
            ((Node) item).unlock();
            getSession().removeReference(lock.getToken());
        } catch (RepositoryException e) {
            throw new JcrDavException(e);
        }
    } else {
        super.unlock(lockToken);
    }
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 8 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class DefaultItemCollection method lock.

/**
     * Creates a lock on this resource by locking the underlying
     * {@link javax.jcr.Node node}. Except for the {@link org.apache.jackrabbit.webdav.lock.LockInfo#isDeep()} }
     * all information included in the <code>LockInfo</code> object is ignored.
     * Lock timeout is defined by JCR implementation.
     *
     * @param reqLockInfo
     * @return lock object representing the lock created on this resource.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.DavResource#lock(org.apache.jackrabbit.webdav.lock.LockInfo)
     * @see Node#lock(boolean, boolean)
     */
@Override
public ActiveLock lock(LockInfo reqLockInfo) throws DavException {
    if (!isLockable(reqLockInfo.getType(), reqLockInfo.getScope())) {
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
    }
    if (Type.WRITE.equals(reqLockInfo.getType())) {
        if (!exists()) {
            log.warn("Cannot create a write lock for non-existing JCR node (" + getResourcePath() + ")");
            throw new DavException(DavServletResponse.SC_NOT_FOUND);
        }
        try {
            boolean sessionScoped = EXCLUSIVE_SESSION.equals(reqLockInfo.getScope());
            long timeout = reqLockInfo.getTimeout();
            if (timeout == LockInfo.INFINITE_TIMEOUT) {
                timeout = Long.MAX_VALUE;
            } else {
                timeout = timeout / 1000;
            }
            javax.jcr.lock.LockManager lockMgr = getRepositorySession().getWorkspace().getLockManager();
            Lock jcrLock = lockMgr.lock((item).getPath(), reqLockInfo.isDeep(), sessionScoped, timeout, reqLockInfo.getOwner());
            ActiveLock lock = new JcrActiveLock(jcrLock);
            // add reference to DAVSession for this lock
            getSession().addReference(lock.getToken());
            return lock;
        } catch (RepositoryException e) {
            // UnsupportedRepositoryOperationException should not occur...
            throw new JcrDavException(e);
        }
    } else {
        return super.lock(reqLockInfo);
    }
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) DavException(org.apache.jackrabbit.webdav.DavException) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) RepositoryException(javax.jcr.RepositoryException) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Lock(javax.jcr.lock.Lock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)

Example 9 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class DavResourceImpl method lock.

/**
     * @see DavResource#lock(LockInfo)
     */
public ActiveLock lock(LockInfo lockInfo) throws DavException {
    ActiveLock lock = null;
    if (isLockable(lockInfo.getType(), lockInfo.getScope())) {
        // TODO: deal with existing locks, that may have been created, before the node was jcr-lockable...
        if (isJcrLockable()) {
            try {
                javax.jcr.lock.LockManager lockMgr = node.getSession().getWorkspace().getLockManager();
                long timeout = lockInfo.getTimeout();
                if (timeout == LockInfo.INFINITE_TIMEOUT) {
                    timeout = Long.MAX_VALUE;
                } else {
                    timeout = timeout / 1000;
                }
                // try to execute the lock operation
                Lock jcrLock = lockMgr.lock(node.getPath(), lockInfo.isDeep(), false, timeout, lockInfo.getOwner());
                if (jcrLock != null) {
                    lock = new JcrActiveLock(jcrLock);
                }
            } catch (RepositoryException e) {
                throw new JcrDavException(e);
            }
        } else {
            // create a new webdav lock
            lock = lockManager.createLock(lockInfo, this);
        }
    } else {
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Unsupported lock type or scope.");
    }
    return lock;
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) RepositoryException(javax.jcr.RepositoryException) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Lock(javax.jcr.lock.Lock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) SupportedLock(org.apache.jackrabbit.webdav.lock.SupportedLock)

Example 10 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class DefaultItemCollection method refreshLock.

/**
     * Refreshes the lock on this resource. With this implementation the
     * {@link javax.jcr.lock lock} present on the underlying {@link javax.jcr.Node node}
     * is refreshed. The timeout indicated by the <code>LockInfo</code>
     * object is ignored.
     *
     * @param reqLockInfo LockInfo as build from the request.
     * @param lockToken
     * @return the updated lock info object.
     * @throws org.apache.jackrabbit.webdav.DavException in case the lock could not be refreshed.
     * @see org.apache.jackrabbit.webdav.DavResource#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, String)
     * @see javax.jcr.lock.Lock#refresh()
     */
@Override
public ActiveLock refreshLock(LockInfo reqLockInfo, String lockToken) throws DavException {
    if (lockToken == null) {
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
    }
    ActiveLock lock = getLock(reqLockInfo.getType(), reqLockInfo.getScope());
    if (lock == null) {
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No lock with the given scope/type present on this resource.");
    }
    if (Type.WRITE.equals(lock.getType())) {
        try {
            Lock jcrLock = ((Node) item).getLock();
            jcrLock.refresh();
            return new JcrActiveLock(jcrLock);
        } catch (RepositoryException e) {
            /*
                  NOTE: LockException is only thrown by Lock.refresh()
                        the lock exception thrown by Node.getLock() was circumvented
                        by the init test if there is a lock applied...
                  NOTE: UnsupportedRepositoryOperationException should not occur
                */
            throw new JcrDavException(e);
        }
    } else {
        return super.refreshLock(reqLockInfo, lockToken);
    }
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) RepositoryException(javax.jcr.RepositoryException) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Lock(javax.jcr.lock.Lock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)

Aggregations

ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)12 RepositoryException (javax.jcr.RepositoryException)6 DavException (org.apache.jackrabbit.webdav.DavException)6 JcrActiveLock (org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)6 Lock (javax.jcr.lock.Lock)4 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 TxActiveLock (org.apache.jackrabbit.webdav.transaction.TxActiveLock)3 ArrayList (java.util.ArrayList)2 Node (javax.jcr.Node)2 SupportedLock (org.apache.jackrabbit.webdav.lock.SupportedLock)2 DeleteContextImpl (org.apache.jackrabbit.server.io.DeleteContextImpl)1 DeleteManager (org.apache.jackrabbit.server.io.DeleteManager)1 LockInfo (org.apache.jackrabbit.spi.LockInfo)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 CodedUrlHeader (org.apache.jackrabbit.webdav.header.CodedUrlHeader)1 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)1 LockInfo (org.apache.jackrabbit.webdav.lock.LockInfo)1 Scope (org.apache.jackrabbit.webdav.lock.Scope)1 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)1 TransactionResource (org.apache.jackrabbit.webdav.transaction.TransactionResource)1