Good to Know: InheritanceValueMap

Published on by Dan KlcoPicture of Me Dan Klco
This was also posted on: labs.sixdimensions.com, however 6D Global Technologies decided to remove my authoring credit, which seems unethical.

The InheritanceValueMap is a new interface introduced in CQ 5.4.  This interface is meant to make it much easier for developers to access properties inherited from parent pages. 

To do this, the interface provides two methods, getInherited(String,Class) and getInherited(String, Object), each of these methods will check for a value on the current resource and then check up the page hierarchy for another page with a value on the same content attribute.  It will only attempt to retrieve values at the same page content path

Unlike the PersistableValueMap, resources and nodes cannot be directly adapted into InheritanceValueMaps.  To create an instance of the InheritanceValueMap, create an instance of the class HierarchyNodeInheritanceValueMap and pass in the current resource, for example:

InheritanceValueMap iProperties = new HierarchyNodeInheritanceValueMap(resource);String value = iProperties.getInherited("myProp",String.class);

Based on the hierarchy:

/mypage
    > mypage2
        > mypage3

If an InheritanceValueMap is used to retrieve the property jcr:content/footer/image/@width, the following properties would be checked, in order from bottom to top:

/mypage/jcr:content/footer/image/@width
    > mypage2/jcr:content/footer/image/@width
        > mypage3/jcr:content/footer/image/@width

Using the InheritanceValueMap, it is much easier for developers to access inherited values and build components which use inherited properties.


Tags

Adobe CQ  

comments powered by Disqus