Pages

Sunday, March 1, 2015

How to get the child Pages of a root Page through Java API -AEM/ Adobe CQ5

How to get the child Pages of a root Page through Java API - AEM/Adobe CQ5

This post will explain how to get the child Pages of a root Page through Java API in Adobe Experience Manager(AEM)

public static PageFilter getPageFilter() {
PageFilter pf = new PageFilter();
return pf;
}

public static Iterator<Page> getPageIterator(Page page){
Iterator<Page> children = page. listChildren(getPageFilter());
return children;
}

Filter can be changed to restrict child pages e.g Get the child pages created only with the template "/apps/sample/templates/samplePage"

public static PageFilter getPageFilter() {
PageFilter pf = new PageFilter() {
public boolean includes(Page p) {
ValueMap props = p.getProperties();
String templatePath = props.get("cq:template",String.class);
if("/apps/sample/templates/samplePage".equals(templatePath))
{
return true;
} else
{
return false;
}
}
};
return pf;
}






No comments:

Post a Comment