简体   繁体   English

如何在Alfresco中获得所有文件夹的孩子?

[英]How to get all childrens of folder in Alfresco?

I am trying to get all the children of folder (folder created in Alfresco server) using the following code 我正在尝试使用以下代码获取文件夹(在Alfresco服务器中创建的文件夹)的所有子项

//Path is the path to the location of the folder in alfresco server
String folderId = session.getObjectByPath(path).getId();
Folder folder = (Folder) session.getObject(folderId);
if(folder.getChildren()!= null) {
  ItemIterable<CmisObject> childFolderIterable = folder.getChildren();
  if(childFolderIterable.getHasMoreItems()) {
    Iterator<?> childFolders = childFolderIterable.iterator();
    while(childFolders.hasNext()) {
      Folder subChildFolder = (Folder) childFolders.next();
      getChildrenRepositories(subChildFolder);              
    }
  }
}

Now my question is that folder at Alfresco contains 2 different sub-folders but the following code childFolderIterable.getHasMoreItems() returns false. 现在我的问题是Alfresco的文件夹包含2个不同的子文件夹,但是以下代码childFolderIterable.getHasMoreItems()返回false。

Can someone please look into this and guide me where I am wrong or is there any appropriate way to find the children of the folder? 有人可以调查一下,并指导我哪里不对吗,或者有什么合适的方法可以找到文件夹的子级?

Also it can be done in the following way: 也可以通过以下方式完成:

 for(CmisObject obj: folder.getChildren()) {
        System.out.println("Name: " + obj.getName());
        System.out.println("Id: " + obj.getId());
        System.out.println("Type: " + getType(obj.getType()));
        System.out.println();
    }

The getHasMoreItems() method documentation says: getHasMoreItems()方法文档说:

Returns whether the repository contains additional items beyond the page of items already fetched. 返回存储库中是否包含除已提取项目页面之外的其他项目。 Returns: true => further page requests will be made to the repository 返回值:true =>将向存储库发出其他页面请求

If it returns false, it means that the page you fetched by calling getChildren() contains already all children of this folder and no further requests (to get the remaining children) are required. 如果返回false,则意味着您通过调用getChildren()获取的页面已包含此文件夹的所有子项,并且不需要进一步的请求(获取剩余的子项)。 If you have a folder with a lot of children you can use the operation context to page the results. 如果您的文件夹中有很多子项,则可以使用操作上下文来分页结果。 The OpenCMIS project site provides an appropriate example . OpenCMIS项目站点提供了适当的示例

If you use no paging, then simply call: 如果不使用分页,则只需调用:

Iterator<CmisObject> it = folder.getChildren().iterator();

while(it.hasNext()) {
  CmisObject object = it.next();

  // Do something with the child object
}

The iterator should provide the two children you are looking for. 迭代器应提供您要查找的两个子代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM