RepositoryCapabilities interface provides isGetFolderTreeSupported’
to check whether an application can able to retrieve the folder tree by using
getFolderTree method.
Following application prints complte folder hierarchy, if
repository supports isGetFolderTreeSupported.
TestCmis.java
package com.sample.util; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.chemistry.opencmis.client.api.FileableCmisObject; import org.apache.chemistry.opencmis.client.api.Folder; import org.apache.chemistry.opencmis.client.api.Session; import org.apache.chemistry.opencmis.client.api.SessionFactory; import org.apache.chemistry.opencmis.client.api.Tree; import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl; import org.apache.chemistry.opencmis.commons.SessionParameter; import org.apache.chemistry.opencmis.commons.data.RepositoryInfo; import org.apache.chemistry.opencmis.commons.enums.BindingType; public class TestCmis { private static String serverURL = "http://localhost:8080/chemistry-opencmis-server-inmemory-1.1.0/browser"; private static String repositoryId = "A1"; public static Session getSession() { Map<String, String> parameters = new HashMap<>(); parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value()); parameters.put(SessionParameter.USER, ""); parameters.put(SessionParameter.PASSWORD, ""); parameters.put(SessionParameter.REPOSITORY_ID, repositoryId); parameters.put(SessionParameter.BROWSER_URL, serverURL); SessionFactory sessionFactory = SessionFactoryImpl.newInstance(); return sessionFactory.createSession(parameters); } public static void printHierarchy(List<Tree<FileableCmisObject>> objects, String space) { for (Tree<FileableCmisObject> obj : objects) { FileableCmisObject fileableObj = obj.getItem(); System.out.println(space + fileableObj.getName()); Folder folder = (Folder) fileableObj; printHierarchy(folder.getFolderTree(-1), " " + space); } } public static void main(String args[]) { Session session = getSession(); RepositoryInfo repoInfo = session.getRepositoryInfo(); boolean isFolderTreeSupported = repoInfo.getCapabilities().isGetFolderTreeSupported(); if (!isFolderTreeSupported) { System.out.println("Folder tree capability is not supported"); return; } Folder rootFolder = session.getRootFolder(); List<Tree<FileableCmisObject>> fileableCmisObjects = rootFolder.getFolderTree(2); printHierarchy(fileableCmisObjects, ""); } }
Output
RootFolder My_Folder-0-0 My_Folder-1-0 My_Folder-2-0 My_Folder-2-1 My_Folder-1-1 My_Folder-2-0 My_Folder-2-1 My_Folder-0-1 My_Folder-1-0 My_Folder-2-0 My_Folder-2-1 My_Folder-1-1 My_Folder-2-0 My_Folder-2-1
No comments:
Post a Comment