Java Code Examples for com.dropbox.core.v2.files.ListFolderResult#getHasMore()

The following examples show how to use com.dropbox.core.v2.files.ListFolderResult#getHasMore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropboxListService.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
    try {
        final AttributedList<Path> children = new AttributedList<>();
        ListFolderResult result;
        final DbxRawClientV2 client;
        this.parse(directory, listener, children, result = new DbxUserFilesRequests(session.getClient(directory)).listFolder(containerService.getKey(directory)));
        // If true, then there are more entries available. Pass the cursor to list_folder/continue to retrieve the rest.
        while(result.getHasMore()) {
            this.parse(directory, listener, children, result = new DbxUserFilesRequests(session.getClient(directory)).listFolderContinue(result.getCursor()));
        }
        return children;
    }
    catch(DbxException e) {
        throw new DropboxExceptionMappingService().map("Listing directory {0} failed", e, directory);
    }
}
 
Example 2
Source File: DropboxDirectory.java    From sling-whiteboard with Apache License 2.0 6 votes vote down vote up
@Override
public @NotNull List<RemoteResourceReference> getChildren() {
    ArrayList<RemoteResourceReference> children = new ArrayList<>();
    ListFolderResult result;
    try {
        result = client.files().listFolder(metadata.getPathLower());
        boolean hasMoreResults = true;
        while (hasMoreResults) {
            for (Metadata entry : result.getEntries()) {
                if (!(entry instanceof DeletedMetadata)) {
                    children.add(new DropboxResourceReference(dropboxStorageProvider, entry));
                }
            }
            result = client.files().listFolderContinue(result.getCursor());
            hasMoreResults = result.getHasMore();
        }
    } catch (ListFolderContinueErrorException e) {
        LOGGER.error(String.format("Cannot read all children of folder %s.", metadata.getPathLower()), e);
    } catch (
            DbxException ex) {
        LOGGER.error(String.format("Cannot access path %s on Dropbox.", metadata.getPathLower()), ex);
    }
    return children;
}
 
Example 3
Source File: Main.java    From dropbox-sdk-java with MIT License 6 votes vote down vote up
/**
 * Prints changes made to a folder in Dropbox since the given
 * cursor was retrieved.
 *
 * @param dbxClient Dropbox client to use for fetching folder changes
 * @param cursor lastest cursor received since last set of changes
 *
 * @return latest cursor after changes
 */
private static String printChanges(DbxClientV2 client, String cursor)
    throws DbxApiException, DbxException {

    while (true) {
        ListFolderResult result = client.files()
            .listFolderContinue(cursor);
        for (Metadata metadata : result.getEntries()) {
            String type;
            String details;
            if (metadata instanceof FileMetadata) {
                FileMetadata fileMetadata = (FileMetadata) metadata;
                type = "file";
                details = "(rev=" + fileMetadata.getRev() + ")";
            } else if (metadata instanceof FolderMetadata) {
                FolderMetadata folderMetadata = (FolderMetadata) metadata;
                type = "folder";
                details = folderMetadata.getSharingInfo() != null ? "(shared)" : "";
            } else if (metadata instanceof DeletedMetadata) {
                type = "deleted";
                details = "";
            } else {
                throw new IllegalStateException("Unrecognized metadata type: " + metadata.getClass());
            }

            System.out.printf("\t%10s %24s \"%s\"\n", type, details, metadata.getPathLower());
        }
        // update cursor to fetch remaining results
        cursor = result.getCursor();

        if (!result.getHasMore()) {
            break;
        }
    }

    return cursor;
}
 
Example 4
Source File: DbxFileActions.java    From Open-LaTeX-Studio with MIT License 5 votes vote down vote up
/**
 * @return List with user's files or empty List if error occurs
 */
public List<DbxEntryDto> getDbxTexEntries(DbxClientV2 client) {
    List<DbxEntryDto> dbxEntries = new ArrayList<>();

    if (client == null) {
        return dbxEntries;
    }

    try {
        ListFolderResult result = client.files().listFolderBuilder("").withRecursive(true).start();
        while (true) {
            for (Metadata metadata : result.getEntries()) {
                if (metadata instanceof FileMetadata) {
                    String name = metadata.getName();
                    if (name.endsWith(TEX_EXTENSION)) {
                        dbxEntries.add(new DbxEntryDto((FileMetadata) metadata));
                    }
                }
            }

            if (!result.getHasMore()) {
                break;
            }

            result = client.files().listFolderContinue(result.getCursor());
        }
    } catch (DbxException ex) {
        DbxUtil.showDbxAccessDeniedPrompt();
        dbxEntries = new ArrayList<>(); //Empty list
    } finally {
        return dbxEntries;
    }
}