Package com.day.cq.commons.inherit
Class HierarchyNodeInheritanceValueMap
- java.lang.Object
-
- com.day.cq.commons.ValueMapWrapper
-
- com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap
-
- All Implemented Interfaces:
InheritanceValueMap
,java.util.Map<java.lang.String,java.lang.Object>
,ValueMap
public class HierarchyNodeInheritanceValueMap extends ValueMapWrapper implements InheritanceValueMap
AnInheritanceValueMap
for a givenResource
that will inherit values from ancestral pages.For example, given:
/content/parent/page/jcr:content/footer/image/@width
, theHierarchyNodeInheritanceValueMap
will search for afooter/image/@width
property in:/content/parent/page/jcr:content/footer/image/@width
/content/parent/jcr:content/footer/image/@width
/content/jcr:content/footer/image/@width
null
.Note that
HierarchyNodeInheritanceValueMap
searches only the page hierarchy. It will not (for instance), look in:/content/parent/page/jcr:content/footer/@width
ComponentInheritanceValueMap
for that functionality.
-
-
Constructor Summary
Constructors Constructor Description HierarchyNodeInheritanceValueMap(Resource resource)
Will wrap theValueMap
returned byresource.adaptTo(ValueMap.class)
, or use an empty map ifresource
is null or if it doesn't adapt to a ValueMap.HierarchyNodeInheritanceValueMap(ValueMap map)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
get(java.lang.String name, java.lang.Class<T> type)
Get a named property and convert it into the given type.<T> T
getInherited(java.lang.String name, java.lang.Class<T> type)
Get a named property and convert it into the given type, and take the properties of parent resources / pages into account, if the property is not found locally.<T> T
getInherited(java.lang.String name, T defaultValue)
Get a named property and convert it into the given type, and take the properties of parent resources / pages into account, if the property is not found locally.-
Methods inherited from class com.day.cq.commons.ValueMapWrapper
clear, containsKey, containsValue, entrySet, get, get, isEmpty, keySet, put, putAll, remove, size, toString, values
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
HierarchyNodeInheritanceValueMap
public HierarchyNodeInheritanceValueMap(Resource resource)
Will wrap theValueMap
returned byresource.adaptTo(ValueMap.class)
, or use an empty map ifresource
is null or if it doesn't adapt to a ValueMap. The inheritance is internally resolved by fetching the parent resource and wrapping it into anHierarchyNodeInheritanceValueMap
as well.- Parameters:
resource
- the resource to start from
-
HierarchyNodeInheritanceValueMap
public HierarchyNodeInheritanceValueMap(ValueMap map)
Use this if the underlyingResource
for aValueMap
is not available and no inheritance is needed. Using the inheritance-enabledgetter
methods
will behave exactly like the normal ValueMap getters.- Parameters:
map
- a ValueMap to wrap
-
-
Method Detail
-
get
public <T> T get(java.lang.String name, java.lang.Class<T> type)
Description copied from interface:ValueMap
Get a named property and convert it into the given type. This method does not support conversion into a primitive type or an array of a primitive type. It should returnnull
in this case.- Specified by:
get
in interfaceValueMap
- Overrides:
get
in classValueMapWrapper
- Type Parameters:
T
- The class of the type- Parameters:
name
- The name of the propertytype
- The class of the type- Returns:
- Return named value converted to type T or
null
if non existing or can't be converted.
-
getInherited
public <T> T getInherited(java.lang.String name, java.lang.Class<T> type)
Description copied from interface:InheritanceValueMap
Get a named property and convert it into the given type, and take the properties of parent resources / pages into account, if the property is not found locally.The exact inheritance mechanism depends on the implementation.
- Specified by:
getInherited
in interfaceInheritanceValueMap
- Type Parameters:
T
- type parameter- Parameters:
name
- The name of the propertytype
- The class of the type- Returns:
- Return named value converted to type T or
null
if non existing or can't be converted.
-
getInherited
public <T> T getInherited(java.lang.String name, T defaultValue)
Description copied from interface:InheritanceValueMap
Get a named property and convert it into the given type, and take the properties of parent resources / pages into account, if the property is not found locally.The exact inheritance mechanism depends on the implementation.
- Specified by:
getInherited
in interfaceInheritanceValueMap
- Type Parameters:
T
- type parameter- Parameters:
name
- The name of the propertydefaultValue
- The default value to use if the named property does not exist or cannot be converted to the requested type. The default value is also used to define the type to convert the value to. If this isnull
any existing property is not converted.- Returns:
- Return named value converted to type T or the default value if non existing or can't be converted.
-
-