我是露天新手。我需要将文件夹循环到子文件夹和相应文件夹中包含的文件,以便在父文件夹上执行的操作也必须显示在子文件夹上。该方法必须以递归方式调用,但我没有得到任何线索如何继续进一步
请指导我。感谢..
答案 0 :(得分:1)
在我看来,您似乎在理解如何为文件夹创建递归操作时遇到问题。我会试着给你一个如何处理这个问题的例子。鉴于我的例子可能不是最好的。
public static final String NAME = "Demo-Folder";
public static final String PARAM_ASPECT_NAME = "folder-name";
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void executeImpl(Action action, NodeRef actionUponNodeRef)
{
ChildAssociationRef childAssociationRef = nodeService.getPrimaryParent(actionUponNodeRef);
System.out.println("****The folder is***** "+ childAssociationRef);
iterateThroughChildren(childAssociationRef);
}
public void iterateThroughChildren(ChildAssociationRef childAssocRef)
{
System.out.println("****The folder is***** "+ childAssocRef);
NodeRef childNodeRef = childAssocRef.getChildRef();
List<ChildAssociationRef> children = nodeService.getChildAssocs(childNodeRef);
for (ChildAssociationRef childAssoc : children)
{
childAssoc.getChildRef();
// Use childNodeRef here.
System.out.println("******Documents inside are******"+ childAssoc);
// This call recurses the method with the new child.
iterateThroughChildren(childAssoc);
// If there are no children then the list will be empty and so this will be skipped.
}
}
我使用了上面的代码,并将其扩展为包含一个名为iterateThroughChildren
的新方法,该方法接受ChildAssociationRef
并获取子项并迭代它们。在迭代期间,子项被传递回方法以允许子项被迭代,依此类推,直到没有子项(意味着您在分支的末尾)。这允许您遍历整个树结构。