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

The following examples show how to use com.dropbox.core.v2.files.FolderMetadata. 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: DropboxSearchFeature.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
protected boolean parse(final Path workdir, final ListProgressListener listener, final AttributedList<Path> list, final SearchV2Result result) throws ConnectionCanceledException {
    final List<SearchMatchV2> matches = result.getMatches();
    for(SearchMatchV2 match : matches) {
        final Metadata metadata = match.getMetadata().getMetadataValue();
        final EnumSet<Path.Type> type;
        if(metadata instanceof FileMetadata) {
            type = EnumSet.of(Path.Type.file);
        }
        else if(metadata instanceof FolderMetadata) {
            type = EnumSet.of(Path.Type.directory);
        }
        else {
            log.warn(String.format("Skip file %s", metadata));
            return true;
        }
        list.add(new Path(metadata.getPathDisplay(), type, attributes.toAttributes(metadata)));
        listener.chunk(workdir, list);
    }
    return false;
}
 
Example #2
Source File: DropboxListService.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
protected Path parse(final Path directory, final Metadata metadata) {
    final EnumSet<Path.Type> type;
    if(metadata instanceof FileMetadata) {
        type = EnumSet.of(Path.Type.file);
    }
    else if(metadata instanceof FolderMetadata) {
        type = EnumSet.of(Path.Type.directory);
        if(StringUtils.isNotBlank(((FolderMetadata) metadata).getSharedFolderId())) {
            type.add(Path.Type.volume);
            type.add(Path.Type.shared);
        }
        else if(directory.isRoot()) {
            // Home folder
            type.add(Path.Type.volume);
        }
    }
    else {
        log.warn(String.format("Skip file %s", metadata));
        return null;
    }
    return new Path(directory, PathNormalizer.name(metadata.getName()), type, attributes.toAttributes(metadata));
}
 
Example #3
Source File: DropboxAttributesFinderFeature.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
protected PathAttributes toAttributes(final Metadata metadata) {
    final PathAttributes attributes = new PathAttributes();
    if(metadata instanceof FileMetadata) {
        final FileMetadata file = (FileMetadata) metadata;
        attributes.setSize(file.getSize());
        attributes.setModificationDate(file.getClientModified().getTime());
        if(file.getFileLockInfo() != null) {
            attributes.setLockId(String.valueOf(file.getFileLockInfo().getIsLockholder()));
        }
    }
    if(metadata instanceof FolderMetadata) {
        final FolderMetadata folder = (FolderMetadata) metadata;
        // All shared folders have a shared_folder_id. This value is identical to the namespace ID for that shared folder
        attributes.setVersionId(folder.getSharedFolderId());
    }
    return attributes;
}
 
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: Dropbox.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void treeList(String parentPath, List<FileMetadata> files) throws DbxException {
	List<Metadata> list = list(parentPath);
	for (Metadata entry : list) {
		if (entry instanceof FolderMetadata)
			treeList(entry.getPathDisplay(), files);
		else
			files.add((FileMetadata) entry);
	}
}
 
Example #6
Source File: DropboxStorageProvider.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public @Nullable Directory getDirectory(@NotNull RemoteResourceReference reference, @Nullable Map<String, Object> authenticationInfo) {
    if (reference instanceof DropboxResourceReference) {
        DropboxResourceReference dropboxResourceReference = (DropboxResourceReference) reference;
        if (dropboxResourceReference.getType() == RemoteResourceReference.Type.DIRECTORY) {
            return new DropboxDirectory(this, (FolderMetadata) dropboxResourceReference.getMetadata());
        }
    }
    return null;
}
 
Example #7
Source File: DropboxFilePickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 5 votes vote down vote up
@NonNull
@Override
public Metadata getPath(@NonNull String path) {
    return FolderMetadata.newBuilder(path, "id")
            .withPathLower(path)
            .build();
}
 
Example #8
Source File: FilesAdapter.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
public void onClick(View v) {

    if (mItem instanceof FolderMetadata) {
        mCallback.onFolderClicked((FolderMetadata) mItem);
    }  else if (mItem instanceof FileMetadata) {
        mCallback.onFileClicked((FileMetadata)mItem);
    }
}
 
Example #9
Source File: FilesAdapter.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public void bind(Metadata item) {
    mItem = item;
    mTextView.setText(mItem.getName());

    // Load based on file path
    // Prepending a magic scheme to get it to
    // be picked up by DropboxPicassoRequestHandler

    if (item instanceof FileMetadata) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        String ext = item.getName().substring(item.getName().indexOf(".") + 1);
        String type = mime.getMimeTypeFromExtension(ext);
        if (type != null && type.startsWith("image/")) {
            mPicasso.load(FileThumbnailRequestHandler.buildPicassoUri((FileMetadata)item))
                    .placeholder(R.drawable.ic_photo_grey_600_36dp)
                    .error(R.drawable.ic_photo_grey_600_36dp)
                    .into(mImageView);
        } else {
            mPicasso.load(R.drawable.ic_insert_drive_file_blue_36dp)
                    .noFade()
                    .into(mImageView);
        }
    } else if (item instanceof FolderMetadata) {
        mPicasso.load(R.drawable.ic_folder_blue_36dp)
                .noFade()
                .into(mImageView);
    }
}
 
Example #10
Source File: FilesActivity.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String path = getIntent().getStringExtra(EXTRA_PATH);
    mPath = path == null ? "" : path;

    setContentView(R.layout.activity_files);

    Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            performWithPermissions(FileAction.UPLOAD);
        }
    });
    //init picaso client
    PicassoClient.init(this,DropboxClientFactory.getClient());
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.files_list);
    mFilesAdapter = new FilesAdapter(PicassoClient.getPicasso(), new FilesAdapter.Callback() {
        @Override
        public void onFolderClicked(FolderMetadata folder) {
            startActivity(FilesActivity.getIntent(FilesActivity.this, folder.getPathLower()));
        }

        @Override
        public void onFileClicked(final FileMetadata file) {
            mSelectedFile = file;
            performWithPermissions(FileAction.DOWNLOAD);
        }
    });
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(mFilesAdapter);

    mSelectedFile = null;
}
 
Example #11
Source File: DropboxDataServlet.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
		IOException {
	try {
		Session session = SessionUtil.validateSession(request);
		User user = session.getUser();

		Dropbox dbox = new Dropbox();
		boolean connected = dbox.login(DropboxServiceImpl.loadAccessToken(user));
		if (!connected)
			throw new IOException("Unable to connect to Dropbox");

		boolean folders = "true".equals(request.getParameter("folders"));

		String parent = request.getParameter("parent");
		if (parent == null)
			parent = "#parent#";

		response.setContentType("text/xml");
		response.setCharacterEncoding("UTF-8");

		// Avoid resource caching
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-store");
		response.setDateHeader("Expires", 0);

		PrintWriter writer = response.getWriter();
		writer.write("<list>");

		if ("#parent#".equals(parent)) {
			writer.print("<entry>");
			writer.print("<path>/</path>");
			writer.print("<parent><![CDATA[" + parent + "]]></parent>");
			writer.print("<name>/</name>");
			writer.print("<type>folder</type>");
			writer.print("<iicon>folder</iicon>");
			writer.print("</entry>");
		} else {
			Metadata ent = dbox.get(parent);
			if ((ent == null && "/".equals(parent)) || (ent != null && ent instanceof FolderMetadata)) {
				List<Metadata> entries = dbox.list(parent);
				for (Metadata entry : entries) {
					if (folders && entry instanceof FileMetadata)
						continue;
					writer.print("<entry>");
					writer.print("<path><![CDATA[" + entry.getPathDisplay() + "]]></path>");
					writer.print("<parent><![CDATA[" + parent + "]]></parent>");
					writer.print("<name><![CDATA[" + entry.getName() + "]]></name>");
					writer.print("<type>" + ((entry instanceof FileMetadata) ? "file" : "folder") + "</type>");
					if (entry instanceof FileMetadata)
						writer.print("<iicon>"
								+ FilenameUtils.getBaseName(IconSelector.selectIcon(FilenameUtils
										.getExtension(entry.getName()).toLowerCase().trim())) + "</iicon>");
					else
						writer.print("<iicon>folder</iicon>");
					writer.print("</entry>");
				}
			}
		}
		writer.write("</list>");
	} catch (Throwable e) {
		log.error(e.getMessage(), e);
		if (e instanceof ServletException)
			throw (ServletException) e;
		else if (e instanceof IOException)
			throw (IOException) e;
		else
			throw new ServletException(e.getMessage(), e);
	}
}
 
Example #12
Source File: DropboxDirectory.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
DropboxDirectory(DropboxStorageProvider dropboxStorageProvider, FolderMetadata metadata) {
    super(dropboxStorageProvider, metadata);
    this.dropboxStorageProvider = dropboxStorageProvider;
    this.metadata = metadata;
    this.client = dropboxStorageProvider.getClient();
}
 
Example #13
Source File: DropboxFilePickerFragment.java    From NoNonsense-FilePicker with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public boolean isDir(@NonNull final Metadata file) {
    return file instanceof FolderMetadata;
}
 
Example #14
Source File: FilesAdapter.java    From dropbox-sdk-java with MIT License votes vote down vote up
void onFolderClicked(FolderMetadata folder);