AEM / CQ5 - livecopy - 如何获取给定页面路径(在本例中为蓝图)的 Live Copy 页面列表(如果有)

AEM / CQ5 - livecopy - how to get the list of live copy pages (if any), for a given page path(which is blueprint in this case)

我想获取任何给定蓝图页面的 Live Copy 页面列表。所以,如果我给了一个页面路径,我应该能够列出它的所有实时副本(如果有的话)。这可以用任何 API 来实现吗?

官方可以获取资源(页面)的Live副本API

您只需要使用 LiveRelationshipManager.getLiveRelationships 即可获得实时关系。

根据您使用的 AEM 版本、BluePrint 设置的复杂性和 LiveCopy 继承(和取消)的深度,这 API 可能会对性能产生影响。

  • 对于 AEM 6.0 SP3 之前的版本,它会非常慢并且没有完全优化。
  • AEM 6.1 SP1 一直到最新版本,此 API 针对性能进行了优化。

实际上,它应该return 与通过 CQ 蓝图管理器屏幕可见的相同数据。

需要进行以下步骤

  • 添加依赖到pom.xml

    <dependency>
         <groupId>com.day.cq.wcm</groupId>
         <artifactId>cq-msm-api</artifactId>
         <version>5.7.2</version>
         <scope>provided</scope>
    </dependency>       
    
  • 添加两个引用

    @Reference
    private ResourceResolverFactory resolverFactory;
    
    @Reference
    LiveRelationshipManager liveRelManager;
    
  • 在需要liveCopy列表的地方添加代码。

     List<LiveCopy> liveCopyList = new ArrayList();
        try {
            ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
            String givenPageOrBlueprint = "/content/we-retail/ca/en/experience/climbing-in-the-massif-du-mont-blanc";
            Resource res = resourceResolver.getResource(givenPageOrBlueprint);
            RangeIterator rangeIterator = liveRelManager.getLiveRelationships(res,"",null);
            while (rangeIterator.hasNext())
            {
                LiveRelationship liveCopy =(LiveRelationship) rangeIterator.next();
                liveCopyList.add(liveCopy.getLiveCopy());
    
            }
    
        } catch (Exception e) {
            e.printStackTrace();
        }