Class FilteringResourceWrapper
- java.lang.Object
-
- org.apache.sling.api.resource.ResourceWrapper
-
- com.adobe.granite.ui.components.FilteringResourceWrapper
-
- Direct Known Subclasses:
WCMFilteringResourceWrapper
public class FilteringResourceWrapper extends ResourceWrapper
A ResourceWrapper that filters its descendant resources based ongranite:hide
BooleanEL property.This wrapper needs to be applied to the container resource, such as the page root resource, and the dialog root resource.
It is also smart enough to handle include component. In that case, if the resource type is
granite/ui/components/coral/foundation/include
, the included resource will also be wrapped by this class, allowing the descendant resources of the included resource to usegranite:hide
property.For example given the following content structure:
+ /mycontainer - sling:resourceType = "my/container" + item1 - sling:resourceType = "my/item" + item2 - sling:resourceType = "my/item" - granite:hide = true + item3 - sling:resourceType = "my/item" + item4 - sling:resourceType = "granite/ui/components/coral/foundation/include" - path = "/mycontainer2" + /mycontainer2 - sling:resourceType = "my/container2" + item1 - sling:resourceType = "my/item" + item2 - sling:resourceType = "my/item" - granite:hide = true
Assuming that
my/container
resource type implementation usesFilteringResourceWrapper
to wrap its resource (/mycontainer
resource),/mycontainer/item2
and/mycontainer2/item2
will be excluded during traversal transparently, as if they are not there in the first place.
-
-
Field Summary
-
Fields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING
-
-
Constructor Summary
Constructors Constructor Description FilteringResourceWrapper(Resource resource, ExpressionResolver expressionResolver, SlingHttpServletRequest request)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource
getChild(String relPath)
Returns the value of callinggetChild
on thewrapped resource
.Iterable<Resource>
getChildren()
Returns an iterable of the direct children of this resource.String
getResourceType()
Returns the value of callinggetResourceType
on thewrapped resource
.boolean
hasChildren()
Returns the value of callinghasChildren
on thewrapped resource
.Iterator<Resource>
listChildren()
Returns the value of callinglistChildren
on thewrapped resource
.-
Methods inherited from class org.apache.sling.api.resource.ResourceWrapper
adaptTo, getName, getParent, getPath, getResource, getResourceMetadata, getResourceResolver, getResourceSuperType, getValueMap, isResourceType, toString
-
-
-
-
Constructor Detail
-
FilteringResourceWrapper
public FilteringResourceWrapper(@Nonnull Resource resource, @Nonnull ExpressionResolver expressionResolver, @Nonnull SlingHttpServletRequest request)
-
-
Method Detail
-
getChild
public Resource getChild(String relPath)
Description copied from class:ResourceWrapper
Returns the value of callinggetChild
on thewrapped resource
.- Specified by:
getChild
in interfaceResource
- Overrides:
getChild
in classResourceWrapper
- Parameters:
relPath
- relative path to the child resource- Returns:
- The child resource or
null
- See Also:
ResourceResolver.getResource(Resource, String)
-
listChildren
public Iterator<Resource> listChildren()
Description copied from class:ResourceWrapper
Returns the value of callinglistChildren
on thewrapped resource
.- Specified by:
listChildren
in interfaceResource
- Overrides:
listChildren
in classResourceWrapper
- Returns:
- An iterator for child resources.
- See Also:
ResourceResolver.listChildren(Resource)
-
getChildren
public Iterable<Resource> getChildren()
Description copied from interface:Resource
Returns an iterable of the direct children of this resource.This method is a convenience and returns exactly the same resources as calling
getResourceResolver().getChildren(resource)
.- Specified by:
getChildren
in interfaceResource
- Overrides:
getChildren
in classResourceWrapper
- Returns:
- An iterable for child resources
- See Also:
Resource.getChildren()
-
hasChildren
public boolean hasChildren()
Description copied from class:ResourceWrapper
Returns the value of callinghasChildren
on thewrapped resource
.- Specified by:
hasChildren
in interfaceResource
- Overrides:
hasChildren
in classResourceWrapper
- Returns:
true
if the resource has any child resources
-
getResourceType
public String getResourceType()
Description copied from class:ResourceWrapper
Returns the value of callinggetResourceType
on thewrapped resource
.- Specified by:
getResourceType
in interfaceResource
- Overrides:
getResourceType
in classResourceWrapper
- Returns:
- The resource type
-
-