} else if(!destination.getPermissions().validate(user, Permission.WRITE))
} else { if(!destination.getPermissions().validate(user, Permission.WRITE))
	public void copyResource(DocumentImpl doc, Collection destination, String newName) 	throws PermissionDeniedException, LockException {		if (readOnly)			throw new PermissionDeniedException(DATABASE_IS_READ_ONLY);	    Collection collection = doc.getCollection();	    if(!collection.getPermissions().validate(user, Permission.READ))	        throw new PermissionDeniedException("Insufficient privileges to copy resource " +	                doc.getFileName());	    if(!doc.getPermissions().validate(user, Permission.READ))	    	throw new PermissionDeniedException("Insufficient privileges to copy resource " +	                doc.getFileName());	    if(newName == null) {            int p = doc.getFileName().lastIndexOf('/');            newName = doc.getFileName().substring(p + 1);        }	    Lock lock = null;	    try {	        lock = collectionsDb.getLock();	        lock.acquire(Lock.WRITE_LOCK);	        // check if the move would overwrite a collection	        if(getCollection(destination.getName() + '/' + newName) != null)	            throw new PermissionDeniedException("A resource can not replace an existing collection");	        DocumentImpl oldDoc = destination.getDocument(this, newName);	        if(oldDoc != null) {	            if(!destination.getPermissions().validate(user, Permission.UPDATE))	                throw new PermissionDeniedException("Resource with same name exists in target " +	                		"collection and update is denied");	            if(!oldDoc.getPermissions().validate(user, Permission.UPDATE))	                throw new PermissionDeniedException("Resource with same name exists in target " +	                		"collection and update is denied");	            collection.removeDocument(this, oldDoc.getFileName());	        } else	            if(!destination.getPermissions().validate(user, Permission.WRITE))	    	        throw new PermissionDeniedException("Insufficient privileges on target collection " +	    	                destination.getName());	        	        DocumentImpl newDoc = new DocumentImpl(this, newName, destination);	        newDoc.copyOf(doc);	        copyResource(doc, newDoc);	        flush();	        destination.addDocument(this, doc);	        saveCollection(destination);		} catch (TriggerException e) {			throw new PermissionDeniedException(e.getMessage());		} finally {	    	lock.release();	    }	}