通过路径获取 Alfresco NodeRef

问题描述 投票:0回答:4

我想获取存储在 Alfresco 中的文档(或空间)的 NodeRef。

我的代码是用 Java 编写的,在 Alfresco 中运行(例如在 AMP 中)。

怎么办?

java lucene alfresco
4个回答
3
投票

最简单的方法可能是使用 NodeLocatorServiceXPath 定位器名称 + 一个 xpath 表达式

在引擎盖下,它使用了搜索服务,但它为您解决了很多复杂问题!

要使用它,将

NodeLocatorService
注入到你的 bean 中,然后执行以下操作:

 Map<String,Serializable> params = new HashMap<>();
 params.put("query", "/x:path/to:node/pa:th");
 NodeRef nodeRef = nodeLocatorService.getNode("xpath",null,params);

Other NodeLocators exist 用于其他查找,它也可以远程使用 via

/alfresco/service/api/nodelocator/{node_locator_name}?params


3
投票

以下Java方法获取您指定的Alfresco文档或空间的NodeRef:

/**
 * Get a NodeRef by its path.
 * @path as displayed by the Node Browser.
 * @return the NodeRef, or null if no NodeRef matches this path.
 */
private NodeRef getNode(String path) {
    logger.debug("Getting NodeRef for path:\"" + path + "\"");
    ResultSet results = null;
    try {
        StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
        results = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE,
            "PATH:\"" + path + "\"");
        if (results.length() == 0) {
            logger.debug("Zero matches for path: " + path);
            return null;
        }
        NodeRef nodeRef = results.getNodeRef(0);
        logger.debug("NodeRef for \"" + path + "\" is " + nodeRef);
        return nodeRef;
    }
    catch(Exception e) {
        logger.debug("Exception while searching for path: " + path, e);
        if (results != null) {
            results.close();
        }
        return null; // The node does not exist
    }
    finally {
        if (results != null) {
            results.close();
        }
    }
}

private SearchService searchService; // Be sure to set this, probably via Spring.

请注意

path
中的每个级别必须:

  • 有一个命名空间
  • 被ISO9075转义(Java代码:
    ISO9075.encode(level)

例子:

  • /app:company_home/app:dictionary/app:space_templates/cm:MyTemplate
  • /app:company_home/app:shared/cm:abc/cm:def/cm:My_x0020_Document.txt
  • /app:company_home/app:shared/cm:_x0031_23

要找出特定文档或文件夹的路径,节点浏览器(在管理工具中)是您的朋友:

我在公共领域上面制作方法,如果您发现任何可以改进的地方,请修复或评论,谢谢! :-)


0
投票

路径查询,但不是最快的,特别是如果你在 Lucene 上。你应该想出其他方法来找到你要找的东西。


0
投票

使用 GET /nodes /{nodeId}

只需提供根文件夹常量 Id,就像我在图像中所做的那样 然后提供文件相对路径

© www.soinside.com 2019 - 2024. All rights reserved.