Package org.apache.sling.api.resource
Class ResourceWrapper
java.lang.Object
org.apache.sling.api.resource.ResourceWrapper
The
ResourceWrapper
is a wrapper for any Resource
delegating all method calls to the wrapped resource by default. Extensions of
this class may overwrite any method to return different values as
appropriate.-
Field Summary
Fields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING
-
Constructor Summary
ConstructorDescriptionResourceWrapper
(@NotNull Resource resource) Creates a new wrapper instance delegating all method calls to the givenresource
. -
Method Summary
Modifier and TypeMethodDescription<AdapterType>
AdapterTypeReturns the value of callingadaptTo
on thewrapped resource
.Returns the value of callinggetChild
on thewrapped resource
.Returns an iterable of the direct children of this resource.@NotNull String
getName()
Returns the value of callinggetName
on thewrapped resource
.Returns the value of callinggetParent
on thewrapped resource
.@NotNull String
getPath()
Returns the value of callinggetPath
on thewrapped resource
.@NotNull Resource
Returns theResource
wrapped by this instance.@NotNull ResourceMetadata
Returns the value of callinggetResourceMetadata
on thewrapped resource
.@NotNull ResourceResolver
Returns the value of callinggetResourceResolver
on thewrapped resource
.Returns the value of callinggetResourceSuperType
on thewrapped resource
.@NotNull String
Returns the value of callinggetResourceType
on thewrapped resource
.@NotNull ValueMap
Returns a value map for this resource.boolean
Returns the value of callinghasChildren
on thewrapped resource
.boolean
isResourceType
(String resourceType) Returns the value of callingisResourceType
on thewrapped resource
.Returns the value of callinglistChildren
on thewrapped resource
.toString()
Returns a string representation of this wrapper consisting of the class' simple name, theresource type
andpath
as well as the string representation of thewrapped resource
.
-
Constructor Details
-
ResourceWrapper
Creates a new wrapper instance delegating all method calls to the givenresource
.- Parameters:
resource
- The resource to wrap
-
-
Method Details
-
getResource
Returns theResource
wrapped by this instance. This method can be overwritten by subclasses if required. All methods implemented by this class use this method to get the resource object.- Returns:
- The resource wrapped by this instance.
-
getPath
Returns the value of callinggetPath
on thewrapped resource
. -
getName
Returns the value of callinggetName
on thewrapped resource
. -
getParent
Returns the value of callinggetParent
on thewrapped resource
. -
getChild
Returns the value of callinggetChild
on thewrapped resource
. -
listChildren
Returns the value of callinglistChildren
on thewrapped resource
.- Specified by:
listChildren
in interfaceResource
- Returns:
- An iterator for child resources.
- Since:
- 2.1.0 (Sling API Bundle 2.1.0)
- See Also:
-
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
- Returns:
- An iterable for child resources
- See Also:
-
getResourceMetadata
Returns the value of callinggetResourceMetadata
on thewrapped resource
.- Specified by:
getResourceMetadata
in interfaceResource
- Returns:
- The resource meta data
- See Also:
-
getResourceResolver
Returns the value of callinggetResourceResolver
on thewrapped resource
.- Specified by:
getResourceResolver
in interfaceResource
- Returns:
- The resource resolver
-
getResourceType
Returns the value of callinggetResourceType
on thewrapped resource
.- Specified by:
getResourceType
in interfaceResource
- Returns:
- The resource type
-
getResourceSuperType
Returns the value of callinggetResourceSuperType
on thewrapped resource
.- Specified by:
getResourceSuperType
in interfaceResource
- Returns:
- The super type of the resource or
null
.
-
hasChildren
public boolean hasChildren()Returns the value of callinghasChildren
on thewrapped resource
.- Specified by:
hasChildren
in interfaceResource
- Returns:
true
if the resource has any child resources- Since:
- 2.4.4 (Sling API Bundle 2.5.0)
-
isResourceType
Returns the value of callingisResourceType
on thewrapped resource
.- Specified by:
isResourceType
in interfaceResource
- Parameters:
resourceType
- the resource type to check this resource against- Returns:
true
if the resource type or any of the resource's super type(s) equals the given resource type,false
otherwise;false
can also be returned ifresourceType
is null- Since:
- 2.1.0 (Sling API Bundle 2.1.0)
- See Also:
-
adaptTo
Returns the value of callingadaptTo
on thewrapped resource
.- Specified by:
adaptTo
in interfaceAdaptable
- Type Parameters:
AdapterType
- The generic type to which this object is adapted to- Parameters:
type
- The Class object of the target type, such asjavax.jcr.Node.class
orjava.io.File.class
- Returns:
- The adapter target or
null
if the object cannot adapt to the requested type
-
getValueMap
Description copied from interface:Resource
Returns a value map for this resource. The value map allows to read the properties of the resource.- Specified by:
getValueMap
in interfaceResource
- Returns:
- A value map
- See Also:
-
toString
Returns a string representation of this wrapper consisting of the class' simple name, theresource type
andpath
as well as the string representation of thewrapped resource
.
-