Six Dimensions Supports the Apache Sling Project: Resource.hasChildren

By Daniel Klco Daniel Klco on 
This was also posted on: http://labs.sixdimensions.com/blog/dan-klco/2013-11-18/six-dimensions-supports-apache-sling-project-resourcehaschildren, however 6D Global Technologies decided to remove my authoring credit which seems unethical.

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.


Tags


comments powered by Disqus