Java源码示例:org.apache.jackrabbit.webdav.lock.Scope

示例1
@Override
public void unlock( String lockToken )
    throws DavException
{
    ActiveLock lock = getLock( Type.WRITE, Scope.EXCLUSIVE );
    if ( lock == null )
    {
        throw new DavException( HttpServletResponse.SC_PRECONDITION_FAILED );
    }
    else if ( lock.isLockedByToken( lockToken ) )
    {
        lockManager.releaseLock( lockToken, this );
    }
    else
    {
        throw new DavException( DavServletResponse.SC_LOCKED );
    }
}
 
示例2
@Test
public void testLockIfResourceUnlockable()
    throws Exception
{
    assertEquals( 0, resource.getLocks().length );

    LockInfo info = new LockInfo( Scope.SHARED, Type.WRITE, "/", 0, false );
    try
    {
        lockManager.createLock( info, resource );
        fail( "Did not throw dav exception" );
    }
    catch ( Exception e )
    {
        // Simple lock manager will die
    }
    assertEquals( 0, resource.getLocks().length );
}
 
示例3
@Test
public void testRefreshLockThrowsExceptionIfNoLockIsPresent()
    throws Exception
{
    LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false );

    assertEquals( 0, resource.getLocks().length );

    try
    {
        lockManager.refreshLock( info, "notoken", resource );
        fail( "Did not throw dav exception" );
    }
    catch ( DavException e )
    {
        assertEquals( DavServletResponse.SC_PRECONDITION_FAILED, e.getErrorCode() );
    }

    assertEquals( 0, resource.getLocks().length );
}
 
示例4
@Test
public void testUnlockThrowsDavExceptionIfNotLocked()
    throws Exception
{
    LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false );

    assertEquals( 0, resource.getLocks().length );

    lockManager.createLock( info, resource );

    assertEquals( 1, resource.getLocks().length );

    try
    {
        lockManager.releaseLock( "BLAH", resource );
        fail( "Did not throw DavException" );
    }
    catch ( DavException e )
    {
        assertEquals( DavServletResponse.SC_LOCKED, e.getErrorCode() );
    }

    assertEquals( 1, resource.getLocks().length );
}
 
示例5
/**
 * Fill the property set for this resource.
 * 
 * @see DavResourceImpl#initProperties()
 */
protected void initProperties() {
	if (!propsInitialized) {
		super.initProperties();

		properties.add(new HrefProperty(VERSION_HISTORY, locator.getResourcePath(), true));

		// DAV:auto-version property: there is no auto version, explicit
		// EVENT_CHECKEDOUT is required.
		properties.add(new DefaultDavProperty(AUTO_VERSION, null, false));
	  
		if(resource==null)
			return;
		
		properties.add(new DefaultDavProperty(DavPropertyName.DISPLAYNAME, resource.getName(), false));
		properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTTYPE, AbstractWebdavServlet.getContext().getMimeType(resource.getName()), false));
		
		if (resource.isFolder())
			return;

		SupportedLock supportedLock = new SupportedLock();
		supportedLock.addEntry(Type.WRITE, Scope.EXCLUSIVE);
		properties.add(new DefaultDavProperty(DavPropertyName.SUPPORTEDLOCK, supportedLock, false));

		String baseVHref = getLocatorFromResource(resource).getHref(false);

		if (resource.isCheckedOut() || resource.isLocked()) {
			log.debug("{} is checkedout", resource.getName());
			properties.add(new HrefProperty(CHECKED_OUT, baseVHref, true));
			properties.add(new HrefProperty(VersionResource.PREDECESSOR_SET, locator.getResourcePath(), false));

			DefaultActiveLock activeLock = new DefaultActiveLock();
			activeLock.setOwner(resource.getLockUser());
			properties.add(new DefaultDavProperty(DavPropertyName.LOCKDISCOVERY, activeLock, false));
			properties.add(new DefaultDavProperty("activelock", activeLock, Namespace.XMLNS_NAMESPACE));
		} else {
			properties.add(new HrefProperty(CHECKED_IN, locator.getResourcePath(), true));
		}
	}
}
 
示例6
@Override
public ActiveLock getLock( Type type, Scope scope )
{
    ActiveLock lock = null;
    if ( exists() && Type.WRITE.equals( type ) && Scope.EXCLUSIVE.equals( scope ) )
    {
        lock = lockManager.getLock( type, scope, this );
    }
    return lock;
}
 
示例7
@Test
public void testLock()
    throws Exception
{
    assertEquals( 0, resource.getLocks().length );

    LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false );
    lockManager.createLock( info, resource );

    assertEquals( 1, resource.getLocks().length );
}
 
示例8
@Test
public void testGetLock()
    throws Exception
{
    LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false );
    lockManager.createLock( info, resource );

    assertEquals( 1, resource.getLocks().length );

    // Lock should exist
    assertNotNull( resource.getLock( Type.WRITE, Scope.EXCLUSIVE ) );

    // Lock should not exist
    assertNull( resource.getLock( Type.WRITE, Scope.SHARED ) );
}
 
示例9
public boolean isLockable(Type type, Scope scope) {
    // nothing is lockable at the moment
    return false;
}
 
示例10
public boolean hasLock(Type type, Scope scope) {
    // nothing is lockable at the moment
    throw new UnsupportedOperationException();
}
 
示例11
public ActiveLock getLock(Type type, Scope scope) {
    // nothing is lockable at the moment
    throw new UnsupportedOperationException();
}
 
示例12
@Override
public ActiveLock getLock( Type arg0, Scope arg1 )
{
    return null;
}
 
示例13
@Override
public boolean hasLock( Type arg0, Scope arg1 )
{
    return false;
}
 
示例14
@Override
public boolean isLockable( Type arg0, Scope arg1 )
{
    return false;
}
 
示例15
@Override
public boolean isLockable( Type type, Scope scope )
{
    return Type.WRITE.equals( type ) && Scope.EXCLUSIVE.equals( scope );
}
 
示例16
@Override
public boolean hasLock( Type type, Scope scope )
{
    return getLock( type, scope ) != null;
}
 
示例17
@Override
public ActiveLock[] getLocks()
{
    ActiveLock writeLock = getLock( Type.WRITE, Scope.EXCLUSIVE );
    return ( writeLock != null ) ? new ActiveLock[]{ writeLock } : new ActiveLock[0];
}
 
示例18
@Test
public void testIsLockable()
{
    assertTrue( resource.isLockable( Type.WRITE, Scope.EXCLUSIVE ) );
    assertFalse( resource.isLockable( Type.WRITE, Scope.SHARED ) );
}
 
示例19
@Test
public void testRefreshLock()
    throws Exception
{
    LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false );

    assertEquals( 0, resource.getLocks().length );

    lockManager.createLock( info, resource );

    assertEquals( 1, resource.getLocks().length );

    ActiveLock lock = resource.getLocks()[0];

    lockManager.refreshLock( info, lock.getToken(), resource );

    assertEquals( 1, resource.getLocks().length );
}
 
示例20
@Test
public void testUnlock()
    throws Exception
{
    LockInfo info = new LockInfo( Scope.EXCLUSIVE, Type.WRITE, "/", 0, false );

    assertEquals( 0, resource.getLocks().length );

    lockManager.createLock( info, resource );

    assertEquals( 1, resource.getLocks().length );

    ActiveLock lock = resource.getLocks()[0];

    lockManager.releaseLock( lock.getToken(), resource );

    assertEquals( 0, resource.getLocks().length );
}
 
示例21
/**
 * Checks if a resource can be locked
 * 
 * @param type the type
 * @param scope the scope
 * 
 * @return true if type is {@link Type#WRITE} and scope is
 *         {@link Scope#EXCLUSIVE}
 * @see DavResource#isLockable(org.apache.jackrabbit.webdav.lock.Type,
 *      org.apache.jackrabbit.webdav.lock.Scope)
 */
public boolean isLockable(Type type, Scope scope) {
	return (resource.isCheckedOut() == false);
}
 
示例22
/**
 * @see DavResource#hasLock(org.apache.jackrabbit.webdav.lock.Type,
 *      org.apache.jackrabbit.webdav.lock.Scope)
 * 
 * @return if there is a lock
 */
public boolean hasLock(Type type, Scope scope) {
	return resource.isCheckedOut() == true;
}
 
示例23
/**
 * @see DavResource#getLock(Type, Scope)
 * 
 * @return the active lock
 */
public ActiveLock getLock(Type type, Scope scope) {
	return new DefaultActiveLock();
}