如何从CQ DAM中查找未使用的图像

时间:2016-02-03 21:02:36

标签: cq5

有没有办法从CQ DAM找到未使用的资产?目前,我们的CQ实例已累积了大量资产,至少有25%的资产尚未被使用。我们的CQ实例在Windows上运行(5.6)。是否有更清洁的方法来做同样的事情?

谢谢, Santhosh

3 个答案:

答案 0 :(得分:2)

您可以使用以下XPATH查询来获取所有资产:

/jcr:root/content/dam//*[@jcr:primaryType='dam:Asset']

使用QueryManger,您可以获得资产节点列表:

Workspace workspace = session.getWorkspace();
QueryManager qm = workspace.getQueryManager();
Query query = qm.createQuery(xpathQuery, Query.XPATH);
QueryResult queryResult = query.execute();
result = queryResult.getNodes();

接下来,您需要获取每个资产的路径并验证是否已使用:

while(result.hasNext()) {
    Node assetNode = result.nextNode();
    String assetPath = assetNode.getPath();
}

要验证是否使用了资产,您需要再次运行xpath:

/jcr:root/content/mywebsite//*[@fileReference='putAssetPathHere']

现在result.hasNext() == true表示使用资产

答案 1 :(得分:2)

另一种解决方案是使用ReferenceSearch

for (String path : paths) {
    if (resourceResolver.getResource(path) != null) {
        Map<String, ReferenceSearch.Info> searchResult = referenceSearch.search(resourceResolver, path);

        if (searchResult.isEmpty()) {
            //path is unused asset
        }

        //get used pages
        for (Map.Entry<String, ReferenceSearch.Info> info : searchResult.entrySet()) {
            info.getKey();//will return page path
        }

        //get used properties paths
        for (Map.Entry<String, ReferenceSearch.Info> info : searchResult.entrySet()) {
            for (String prop : info.getValue().getProperties()) {
                //prop is property path
            }
        }
    }
}

答案 2 :(得分:0)

对我来说,以下代码有效。 帮助链接:http://wemcode.wemblog.com/get_asset_reference_in_page

String damPath = "/content/dam/geometrixx/offices/basel kitchen.jpg";

   for (ReferenceSearch.Info info: new ReferenceSearch().search(resourceResolver, damPath).values()) {

  for (String p: info.getProperties()) {

           out.println("Path is "+info.getPage().getPath());

       }