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;
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations