Search in sources :

Example 1 with ListFolderErrorException

use of com.dropbox.core.v2.files.ListFolderErrorException in project dropbox-sdk-java by dropbox.

the class Main method main.

public static void main(String[] args) throws DbxException, IOException {
    // Create Dropbox client
    DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial");
    DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
    // Instantiate factory and set shared factory
    DbxRequestUtil.sharedCallbackFactory = new DbxExampleGlobalCallbackFactory();
    try {
        // Get files and folder metadata from Dropbox root directory
        client.files().listFolder("/does/not/exist/folder/");
    } catch (ListFolderErrorException ex) {
        System.err.println("STANDARD ROUTE ERROR HANDLER: " + ex.errorValue + "\n");
    } catch (DbxException ex) {
        System.err.println("STANDARD NETWORK ERROR HANDLER: " + ex + "\n");
    }
    try {
        // Get files and folder metadata from Dropbox root directory
        client.auth().tokenRevoke();
        client.files().listFolder("/does/not/exist");
    } catch (ListFolderErrorException ex) {
        System.err.println("STANDARD ROUTE ERROR HANDLER2: " + ex.errorValue + "\n");
    } catch (DbxException ex) {
        System.err.println("STANDARD NETWORK ERROR HANDLER2: " + ex + "\n");
    }
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig) ListFolderErrorException(com.dropbox.core.v2.files.ListFolderErrorException) DbxException(com.dropbox.core.DbxException)

Example 2 with ListFolderErrorException

use of com.dropbox.core.v2.files.ListFolderErrorException in project dropbox-sdk-java by dropbox.

the class DropboxBrowse method renderFolder.

private void renderFolder(HttpServletResponse response, User user, DbxClientV2 dbxClient, String path) throws IOException {
    // Get the folder listing from Dropbox.
    TreeMap<String, Metadata> children = new TreeMap<String, Metadata>();
    ListFolderResult result;
    try {
        try {
            result = dbxClient.files().listFolder(path);
        } catch (ListFolderErrorException ex) {
            if (ex.errorValue.isPath()) {
                if (checkPathError(response, path, ex.errorValue.getPathValue()))
                    return;
            }
            throw ex;
        }
        while (true) {
            for (Metadata md : result.getEntries()) {
                if (md instanceof DeletedMetadata) {
                    children.remove(md.getPathLower());
                } else {
                    children.put(md.getPathLower(), md);
                }
            }
            if (!result.getHasMore())
                break;
            try {
                result = dbxClient.files().listFolderContinue(result.getCursor());
            } catch (ListFolderContinueErrorException ex) {
                if (ex.errorValue.isPath()) {
                    if (checkPathError(response, path, ex.errorValue.getPathValue()))
                        return;
                }
                throw ex;
            }
        }
    } catch (DbxException ex) {
        common.handleDbxException(response, user, ex, "listFolder(" + jq(path) + ")");
        return;
    }
    FormProtection fp = FormProtection.start(response);
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = new PrintWriter(IOUtil.utf8Writer(response.getOutputStream()));
    out.println("<html>");
    out.println("<head><title>" + escapeHtml4(path) + "- Web File Browser</title></head>");
    out.println("<body>");
    fp.insertAntiRedressHtml(out);
    out.println("<h2>Path: " + escapeHtml4(path) + "</h2>");
    // Upload form
    out.println("<form action='/upload' method='post' enctype='multipart/form-data'>");
    fp.insertAntiCsrfFormField(out);
    out.println("<label for='file'>Upload file:</label> <input name='file' type='file'/>");
    out.println("<input type='submit' value='Upload'/>");
    out.println("<input name='targetFolder' type='hidden' value='" + escapeHtml4(path) + "'/>");
    out.println("</form>");
    // Listing of folder contents.
    out.println("<ul>");
    for (Metadata child : children.values()) {
        String href = "/browse?path=" + DbxRequestUtil.encodeUrlParam(child.getPathLower());
        out.println("  <li><a href='" + escapeHtml4(href) + "'>" + escapeHtml4(child.getName()) + "</a></li>");
    }
    out.println("</ul>");
    out.println("</body>");
    out.println("</html>");
    out.flush();
}
Also used : ListFolderContinueErrorException(com.dropbox.core.v2.files.ListFolderContinueErrorException) ListFolderErrorException(com.dropbox.core.v2.files.ListFolderErrorException) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) FileMetadata(com.dropbox.core.v2.files.FileMetadata) Metadata(com.dropbox.core.v2.files.Metadata) ListFolderResult(com.dropbox.core.v2.files.ListFolderResult) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) TreeMap(java.util.TreeMap) DbxException(com.dropbox.core.DbxException) PrintWriter(java.io.PrintWriter)

Aggregations

DbxException (com.dropbox.core.DbxException)2 ListFolderErrorException (com.dropbox.core.v2.files.ListFolderErrorException)2 DbxRequestConfig (com.dropbox.core.DbxRequestConfig)1 DbxClientV2 (com.dropbox.core.v2.DbxClientV2)1 DeletedMetadata (com.dropbox.core.v2.files.DeletedMetadata)1 FileMetadata (com.dropbox.core.v2.files.FileMetadata)1 FolderMetadata (com.dropbox.core.v2.files.FolderMetadata)1 ListFolderContinueErrorException (com.dropbox.core.v2.files.ListFolderContinueErrorException)1 ListFolderResult (com.dropbox.core.v2.files.ListFolderResult)1 Metadata (com.dropbox.core.v2.files.Metadata)1 PrintWriter (java.io.PrintWriter)1 TreeMap (java.util.TreeMap)1