Search in sources :

Example 6 with LockDiscovery

use of org.apache.jackrabbit.webdav.lock.LockDiscovery 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) LockInfo(org.apache.jackrabbit.spi.LockInfo) HttpLock(org.apache.jackrabbit.webdav.client.methods.HttpLock)

Aggregations

LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)6 RepositoryException (javax.jcr.RepositoryException)3 DavException (org.apache.jackrabbit.webdav.DavException)3 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)3 IOException (java.io.IOException)2 HttpResponse (org.apache.http.HttpResponse)2 ResourceType (org.apache.jackrabbit.webdav.property.ResourceType)2 ArrayList (java.util.ArrayList)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 LockInfo (org.apache.jackrabbit.spi.LockInfo)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1 ParentElement (org.apache.jackrabbit.webdav.bind.ParentElement)1 ParentSet (org.apache.jackrabbit.webdav.bind.ParentSet)1 HttpLock (org.apache.jackrabbit.webdav.client.methods.HttpLock)1 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)1 CodedUrlHeader (org.apache.jackrabbit.webdav.header.CodedUrlHeader)1 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)1 LockInfo (org.apache.jackrabbit.webdav.lock.LockInfo)1