Search in sources :

Example 1 with Scope

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

the class RepositoryServiceImpl method retrieveLockInfo.

private LockInfo retrieveLockInfo(LockDiscovery lockDiscovery, SessionInfo sessionInfo, NodeId nodeId, NodeId parentId) throws RepositoryException {
    checkSessionInfo(sessionInfo);
    List<ActiveLock> activeLocks = lockDiscovery.getValue();
    ActiveLock activeLock = null;
    for (ActiveLock l : activeLocks) {
        Scope sc = l.getScope();
        if (l.getType() == Type.WRITE && (Scope.EXCLUSIVE.equals(sc) || sc == ItemResourceConstants.EXCLUSIVE_SESSION)) {
            if (activeLock != null) {
                throw new RepositoryException("Node " + saveGetIdString(nodeId, sessionInfo) + " contains multiple exclusive write locks.");
            } else {
                activeLock = l;
            }
        }
    }
    if (activeLock == null) {
        log.debug("No lock present on node " + saveGetIdString(nodeId, sessionInfo));
        return null;
    }
    NodeId holder = null;
    String lockroot = activeLock.getLockroot();
    if (activeLock.getLockroot() != null) {
        holder = uriResolver.getNodeId(lockroot, sessionInfo);
    }
    if (activeLock.isDeep() && holder == null && parentId != null) {
        // deep lock, parent known, but holder is not
        LockInfo pLockInfo = getLockInfo(sessionInfo, parentId);
        if (pLockInfo != null) {
            return pLockInfo;
        }
    }
    return new LockInfoImpl(activeLock, holder == null ? nodeId : holder, ((SessionInfoImpl) sessionInfo).getAllLockTokens());
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Scope(org.apache.jackrabbit.webdav.lock.Scope) AuthScope(org.apache.http.auth.AuthScope) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) LockInfo(org.apache.jackrabbit.spi.LockInfo)

Example 2 with Scope

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

the class RepositoryServiceImpl method lock.

@Override
public LockInfo lock(SessionInfo sessionInfo, NodeId nodeId, boolean deep, boolean sessionScoped, long timeoutHint, String ownerHint) throws RepositoryException {
    HttpLock request = null;
    try {
        checkSessionInfo(sessionInfo);
        long davTimeout = (timeoutHint == Long.MAX_VALUE) ? INFINITE_TIMEOUT : timeoutHint * 1000;
        String ownerInfo = (ownerHint == null) ? sessionInfo.getUserID() : ownerHint;
        String uri = getItemUri(nodeId, sessionInfo);
        Scope scope = (sessionScoped) ? ItemResourceConstants.EXCLUSIVE_SESSION : Scope.EXCLUSIVE;
        request = new HttpLock(uri, new org.apache.jackrabbit.webdav.lock.LockInfo(scope, Type.WRITE, ownerInfo, davTimeout, deep));
        HttpResponse response = execute(request, sessionInfo);
        String lockToken = request.getLockToken(response);
        ((SessionInfoImpl) sessionInfo).addLockToken(lockToken, sessionScoped);
        LockDiscovery disc = request.getResponseBodyAsLockDiscovery(response);
        return retrieveLockInfo(disc, sessionInfo, nodeId, null);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) LockDiscovery(org.apache.jackrabbit.webdav.lock.LockDiscovery) Scope(org.apache.jackrabbit.webdav.lock.Scope) AuthScope(org.apache.http.auth.AuthScope) LockInfo(org.apache.jackrabbit.spi.LockInfo) HttpLock(org.apache.jackrabbit.webdav.client.methods.HttpLock)

Aggregations

RepositoryException (javax.jcr.RepositoryException)2 AuthScope (org.apache.http.auth.AuthScope)2 LockInfo (org.apache.jackrabbit.spi.LockInfo)2 Scope (org.apache.jackrabbit.webdav.lock.Scope)2 IOException (java.io.IOException)1 HttpResponse (org.apache.http.HttpResponse)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 DavException (org.apache.jackrabbit.webdav.DavException)1 HttpLock (org.apache.jackrabbit.webdav.client.methods.HttpLock)1 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)1 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)1