【问题标题】:how to get page path and title of child and grand child pages in aem如何在aem中获取子页面和大子页面的页面路径和标题
【发布时间】:2021-02-18 06:06:12
【问题描述】:

谁能帮忙?

我有一个根页面的路径,我想检索根页面的所有子页面以及根页面的孙子和孙子页面。我的结构是这样的

rootPage
    |
    |
    |---------childPage
                    |
                    |
                    |---------grandChildPage

【问题讨论】:

标签: java aem aem-6 sling-models


【解决方案1】:

我认为这应该可行。


public static void visitRecursively(Node node, Session currentSession) {
  try{
    NodeIterator list = node.getNodes();

    while(list.hasNext())   {

      Node childNode = list.nextNode();
      // Verify child node for cqPage type
      if((childNode.hasProperty("jcr:primaryType")) && (childNode.getProperty("jcr:primaryType").getValue().getString()).equals("cq:Page") ){
                        
        Node jcrNode = childNode.getNode("jcr:content");
 
        // Iterate some of the page properties
        String articleTitle="";String jcrDesc="";String jcrTitle="";String keywords="";
        if(jcrNode.hasProperty("articleTitle")){

            articleTitle = jcrNode.getProperty("articleTitle").getString();
            log.info("articleTitle--->"+articleTitle);
        }
        if(jcrNode.hasProperty("jcr:description")){
    
            jcrDesc = jcrNode.getProperty("jcr:description").getString();
            log.info("jcr:description--->"+jcrDesc);
        }
        if(jcrNode.hasProperty("jcr:title")){
    
            jcrTitle = jcrNode.getProperty("jcr:title").getString();
            log.info("jcr:title--->"+jcrTitle);
        }
        if(jcrNode.hasProperty("keywords")){

            keywords = jcrNode.getProperty("keywords").getString();
            log.info("keywords--->"+keywords);
        }
 
        String pagePropertiesString = "articleTitle--->"+articleTitle + "jcr:description--->"+jcrDesc+"jcr:title--->"+jcrTitle + "keywords--->"+keywords ;

      log.info("Page Properties :---> Node "+ childNode.getName()+ "Properties : " + pagePropertiesString );
      }
      visitRecursively(childNode,currentSession);
    }
  } catch (RepositoryException rpe){
    log.info("Exception in recursive listing:");
  }

【讨论】:

    【解决方案2】:

    您可以使用 SlingQuery 轻松完成此操作

    final List<Resource> descendantPages = $(rootPage).("cq:Page").asList();
    

    来源:https://sling.apache.org/documentation/bundles/sling-query.html

    或使用普通的 SQL2 查询

    final String query = "SELECT page.* FROM [cq:PageContent] AS page "
        + "WHERE ISDESCENDANTNODE(page, '%s')";
    resolver.findResources(String.format(query, rootPage.getPath()), JCR_SQL2);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      相关资源
      最近更新 更多