code: private void gatherDescendants(
          CmsCmisCallContext context,
          CmsObject cms,
          CmsResource folder,
          List<ObjectInFolderContainer> list,
          boolean foldersOnly,
          int depth,
          Set<String> filter,
          boolean includeAllowableActions,
          boolean includePathSegments) {
  
          try {
              CmsCmisResourceHelper helper = getResourceHelper();
              List<CmsResource> children = cms.getResourcesInFolder(cms.getSitePath(folder), CmsResourceFilter.DEFAULT);
              Collections.sort(children, new Comparator<CmsResource>() {
  
                  public int compare(CmsResource a, CmsResource b) {
  
                      return a.getName().compareTo(b.getName());
                  }
              });
              // iterate through children
              for (CmsResource child : children) {
  
                  // folders only?
                  if (foldersOnly && !child.isFolder()) {
                      continue;
                  }
  
                  // add to list
                  ObjectInFolderDataImpl objectInFolder = new ObjectInFolderDataImpl();
                  objectInFolder.setObject(
                      helper.collectObjectData(
                          context,
                          cms,
                          child,
                          filter,
                          "cmis:none",
                          includeAllowableActions,
                          false,
                          IncludeRelationships.NONE));
                  if (includePathSegments) {
                      objectInFolder.setPathSegment(child.getName());
                  }
  
                  ObjectInFolderContainerImpl container = new ObjectInFolderContainerImpl();
                  container.setObject(objectInFolder);
  
                  list.add(container);
  
                  // move to next level
                  if ((depth != 1) && child.isFolder()) {
                      container.setChildren(new ArrayList<ObjectInFolderContainer>());
                      gatherDescendants(
                          context,
                          cms,
                          child,
                          container.getChildren(),
                          foldersOnly,
                          depth - 1,
                          filter,
                          includeAllowableActions,
                          includePathSegments);
                  }
              }
          } catch (CmsException e) {
              handleCmsException(e);
          }
      }
docs: Helper method to collect the descendants of a given folder.<p>
  
  @param context the call context
  @param cms the CMS context
  @param folder the parent folder
  @param list the list to which the descendants should be added
  @param foldersOnly flag to exclude files from the result
  @param depth the maximum depth
  @param filter the property filter
  @param includeAllowableActions flag to include allowable actions
  @param includePathSegments flag to include path segments