public class HierarchyNodeInheritanceValueMap extends ValueMapWrapper implements InheritanceValueMap
InheritanceValueMap for a given Resource that will look
inside the jcr:content of ancestor hierarchy nodes for inherited
values.
Alternatively, if no resource is available and no inheritance is needed, just
a ValueMap can be wrapped.
This is to be used inside hierarchy nodes such as pages, that have their
inner content stored under jcr:content. First the property is
searched inside the current resource under the given name, which behaves
exactly like get(String, Class) and ValueMapWrapper.get(String, Object).
For example:
/content/parent/page/jcr:content/footer/image/@width.
If not found locally, then the relative path to the next containing
jcr:content starting with the current resource is taken, for
example footer/image. Then the ancestors will be walked step by
step to find parent hierarchy nodes (= parent pages). The property will then
be looked up at those parent nodes under the relative path inside their
jcr:content nodes.
For example: /content/parent/jcr:content/footer/image/@width.
The first hit will be used.
This does not look inside the page nodes themselves (such as
/content/parent) nor in any node without a
jcr:content node. It also does not search in parent
"components", such as footer/@width in this example.
| Constructor and Description |
|---|
HierarchyNodeInheritanceValueMap(Resource resource)
Will wrap the
ValueMap returned by
resource.adaptTo(ValueMap.class), or use an empty map if
resource is null or if it doesn't adapt to a ValueMap. |
HierarchyNodeInheritanceValueMap(ValueMap map)
|
| Modifier and Type | Method and 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.
|
protected static java.lang.String |
getInnerPath(Resource resource)
Returns the page local path (aka localstruct).
|
protected static Resource |
getNextExistingParent(Resource resource)
Returns the next existing ancestor.
|
protected <T> T |
getParentPageValue(java.lang.String innerPath,
java.lang.String name,
java.lang.Class<T> type) |
clear, containsKey, containsValue, entrySet, get, get, isEmpty, keySet, put, putAll, remove, size, toString, valuespublic HierarchyNodeInheritanceValueMap(Resource resource)
ValueMap returned by
resource.adaptTo(ValueMap.class), or use an empty map if
resource 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 an HierarchyNodeInheritanceValueMap as well.resource - the resource to start frompublic HierarchyNodeInheritanceValueMap(ValueMap map)
Resource for a ValueMap is not
available and no inheritance is needed. Using the inheritance-enabled
getter
methods will behave exactly like
the normal ValueMap getters.map - a ValueMap to wrappublic <T> T get(java.lang.String name,
java.lang.Class<T> type)
ValueMapget in interface ValueMapget in class ValueMapWrappername - The name of the propertytype - The class of the typenull if
non existing or can't be converted.public <T> T getInherited(java.lang.String name,
java.lang.Class<T> type)
InheritanceValueMapThe exact inheritance mechanism depends on the implementation.
getInherited in interface InheritanceValueMapname - The name of the propertytype - The class of the typenull if
non existing or can't be converted.public <T> T getInherited(java.lang.String name,
T defaultValue)
InheritanceValueMapThe exact inheritance mechanism depends on the implementation.
getInherited in interface InheritanceValueMapname - 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 is null any existing property is not
converted.protected <T> T getParentPageValue(java.lang.String innerPath,
java.lang.String name,
java.lang.Class<T> type)
protected static java.lang.String getInnerPath(Resource resource)
protected static Resource getNextExistingParent(Resource resource)