代码之家  ›  专栏  ›  技术社区  ›  AME

如何递归显示所有文件和子文件夹?

  •  0
  • AME  · 技术社区  · 8 年前

    我正在使用 Alfresco Rest Api 但我找不到任何可以返回整个树和所有子文件夹的选项。

    我想转到最后一个文件,即使它“包装”在3个子文件夹中。

    有什么想法吗?

    4 回复  |  直到 8 年前
        1
  •  2
  •   Vikash Patel    8 年前

    请参考 categoryService 列出任何嵌套子文件夹中的所有文件。在这里 nodeRef 是父文件夹的noderef

    使用categoryService,还可以列出文件夹的所有子级。

    Collection<ChildAssociationRef> children = categoryService.getChildren(new NodeRef(nodeRef), CategoryService.Mode.ALL, CategoryService.Depth.ANY);
    
        2
  •  1
  •   Lista    8 年前

    我认为你做不到。

    不过,您可以执行路径查询,因为它的编写方式也可以返回所有子级。

    例如:

    var folder = search.luceneSearch("+PATH:\"/app:company_home/cm:Test_x0020_Folder//*\" AND (TYPE:\"cm:content\" OR TYPE:\"cm:folder\")");
    
        3
  •  1
  •   Krutik Jayswal    8 年前

    创建一个java烘焙webscript,它将返回下面对象的节点。

    public class ReportNode {
    
        private NodeRef currentNode;
        private List<ReportNode> children;
        private Map<String, String> properties = new HashMap<>();
        private boolean isFolder;
        private String name;
        private String type;
        private List<String> aspects;
    //Getter Setters
    }
    

    在上述结构中
    currentNode当前节点 表示列表中的当前节点
    儿童 表示节点的子级

    其他事情都很清楚。

    通过节点爬网将数据填入上述链表结构中。

    用于显示已爬网的数据。您可以使用下面的freemarker模板。

    <#macro recurse_macro nodeRef>
        <ul>
            <li> 
                    <@print_properties reportNode=nodeRef/>
            </li>
         </ul>
    </#macro>
    
    <#macro print_properties reportNode>
            <ul>
                <li> 
                    <a>Properties</a>
                        <ul>
                            <#list reportNode.properties?keys as key> 
                                            <li>${key} : ${reportNode.properties[key]}
                            </#list>
    
                        </ul>
                </li>
             </ul>
    </#macro>
    
    <@recurse_macro nodeRef=nodeRef/>
    

    其中noderef是通过对节点进行爬网创建的链表的根节点。

        4
  •  0
  •   Oussama Werfelli    8 年前

    要检索所有文档,可以使用此服务

    http://localhost:8080/share/service/components/documentlibrary/data/doclist/all/site/XXXX/documentLibrary?filter=all&noCache=1521477198549

    或者,您可以创建自定义webscript并递归获取节点,例如:

    /**
     * 
     * @param type
     * @param nodeRef
     * @return true if node type equals or inherit from type <code>type</code>
     */
    protected boolean hasSubType(QName type, NodeRef nodeRef) {
        List<QName> subTypes = new ArrayList<>();
        subTypes.addAll(dictionaryService.getSubTypes(type, true));
        QName nodeType = nodeService.getType(nodeRef);
        return nodeType.equals(type) || subTypes.contains(nodeType);
    }
    
    private void getNodesRecursive(NodeRef node, List<NodeRef> documents) {
        if (hasSubType(ContentModel.TYPE_FOLDER, node)) {
            List<ChildAssociationRef> children = nodeService.getChildAssocs(node, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
            for (ChildAssociationRef child : children) {
                NodeRef childNode = child.getChildRef();
                if (hasSubType(ContentModel.TYPE_CONTENT, node)) {
                    documents.add(childNode);
                } else if (hasSubType(ContentModel.TYPE_FOLDER, node)) {
                    // documents.add(childNode);
                    getNodesRecursive(childNode, documents);
                }
            }
        } else {
            documents.add(node);
        }
    }