com.dropbox.core.v2.files.ListFolderResult Java Examples

The following examples show how to use com.dropbox.core.v2.files.ListFolderResult. 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: Dropbox.java    From financisto with GNU General Public License v2.0 6 votes vote down vote up
List<String> listFiles() throws Exception {
    if (authSession()) {
        try {
            List<String> files = new ArrayList<String>();
            ListFolderResult listFolderResult = dropboxClient.files().listFolder("");
            for (Metadata metadata : listFolderResult.getEntries()) {
                String name = metadata.getName();
                if (name.endsWith(".backup")) {
                    files.add(name);
                }
            }
            Collections.sort(files, new Comparator<String>() {
                @Override
                public int compare(String s1, String s2) {
                    return s2.compareTo(s1);
                }
            });
            return files;
        } catch (Exception e) {
            Log.e("Financisto", "Dropbox: Something wrong", e);
            throw new ImportExportException(R.string.dropbox_error, e);
        }
    } else {
        throw new ImportExportException(R.string.dropbox_auth_error);
    }
}
 
Example #2
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 #3
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 #4
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 #5
Source File: DropboxListService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
private void parse(final Path directory, final ListProgressListener listener, final AttributedList<Path> children, final ListFolderResult result)
    throws ConnectionCanceledException {
    for(Metadata md : result.getEntries()) {
        final Path child = this.parse(directory, md);
        if(child == null) {
            continue;
        }
        children.add(child);
        listener.chunk(directory, children);
    }
}
 
Example #6
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;
    }
}
 
Example #7
Source File: ListFolderTask.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
protected void onPostExecute(ListFolderResult result) {
    super.onPostExecute(result);

    if (mException != null) {
        mCallback.onError(mException);
    } else {
        mCallback.onDataLoaded(result);
    }
}
 
Example #8
Source File: ListFolderTask.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
protected ListFolderResult doInBackground(String... params) {
    try {
        return mDbxClient.files().listFolder(params[0]);
    } catch (DbxException e) {
        mException = e;
    }

    return null;
}
 
Example #9
Source File: FilesActivity.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
protected void loadData() {

    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setCancelable(false);
    dialog.setMessage("Loading");
    dialog.show();

    new ListFolderTask(DropboxClientFactory.getClient(), new ListFolderTask.Callback() {
        @Override
        public void onDataLoaded(ListFolderResult result) {
            dialog.dismiss();

            mFilesAdapter.setFiles(result.getEntries());
        }

        @Override
        public void onError(Exception e) {
            dialog.dismiss();

            Log.e(TAG, "Failed to list folder.", e);
            Toast.makeText(FilesActivity.this,
                    "An error has occurred",
                    Toast.LENGTH_SHORT)
                    .show();
        }
    }).execute(mPath);
}
 
Example #10
Source File: ListFolderTask.java    From dropbox-sdk-java with MIT License votes vote down vote up
void onDataLoaded(ListFolderResult result);