Six Dimensions Supports the Apache Sling Project: Resource.hasChildren
Published on by Dan Klco
Recently, I had the chance to shepherd a new feature into the Apache Sling API. This feature adds the method hasChildren
to the Resource
and ResourceResolver
. My colleague, Brian Warner suggested adding this method after struggling to do this in a clean, correct way.
What’s new? The hasChildren method is a convenient shortcut for developers to check whether or not a Resource has child resources. This method returns correctly across different Resource Providers unlike the lower-level API’s such as Node.hasNodes()
. And this method enables developers to check for child Resources easily and intuitively, for example:
if(resource.hasChildren()){
// DO SOMETHING
}
The feature has been added into the Sling codebase, but there is not yet a new release of the Sling API, but this feature will likely make it into CQ6 and I will update this post once the new method becomes available.