Search in sources :

Example 1 with JcrActiveLock

use of org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock in project jackrabbit by apache.

the class DavResourceImpl method getLock.

/**
     * @see DavResource#getLock(Type, Scope)
     */
public ActiveLock getLock(Type type, Scope scope) {
    ActiveLock lock = null;
    if (exists() && Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope)) {
        // try to retrieve the repository lock information first
        try {
            if (node.isLocked()) {
                Lock jcrLock = node.getLock();
                if (jcrLock != null && jcrLock.isLive()) {
                    lock = new JcrActiveLock(jcrLock);
                    String lockroot = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), jcrLock.getNode().getPath(), false).getHref(false);
                    lock.setLockroot(lockroot);
                }
            }
        } catch (RepositoryException e) {
        // LockException (no lock applies) >> should never occur
        // RepositoryException, AccessDeniedException or another error >> ignore
        }
        // could not retrieve a jcr-lock. test if a simple webdav lock is present.
        if (lock == null) {
            lock = lockManager.getLock(type, scope, this);
        }
    }
    return lock;
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) 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 2 with JcrActiveLock

use of org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock in project jackrabbit by apache.

the class LockTimeOutFormatTest method testfmt.

private void testfmt(long jcrtimeout, String expectedString) throws RepositoryException, URISyntaxException, ParserConfigurationException {
    Lock l = new TestLock(jcrtimeout);
    JcrActiveLock al = new JcrActiveLock(l);
    Document d = DomUtil.createDocument();
    Element activeLock = al.toXml(d);
    assertEquals("activelock", activeLock.getLocalName());
    NodeList nl = activeLock.getElementsByTagNameNS("DAV:", "timeout");
    if (expectedString == null) {
        assertEquals(0, nl.getLength());
    } else {
        assertEquals(1, nl.getLength());
        Element timeout = (Element) nl.item(0);
        String t = DomUtil.getText(timeout);
        assertEquals(expectedString, t);
    }
}
Also used : JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) Lock(javax.jcr.lock.Lock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)

Example 3 with JcrActiveLock

use of org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock 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 4 with JcrActiveLock

use of org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock 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 5 with JcrActiveLock

use of org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock 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

Lock (javax.jcr.lock.Lock)5 JcrActiveLock (org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)5 RepositoryException (javax.jcr.RepositoryException)4 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)4 DavException (org.apache.jackrabbit.webdav.DavException)3 SupportedLock (org.apache.jackrabbit.webdav.lock.SupportedLock)2 Node (javax.jcr.Node)1 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1