Package org.apache.sling.api.resource
Class ResourceWrapper
- java.lang.Object
-
- org.apache.sling.api.resource.ResourceWrapper
-
- Direct Known Subclasses:
DownloadResource
,FilteringResourceWrapper
,Paragraph
,ValueMapResourceWrapper
public class ResourceWrapper extends java.lang.Object implements Resource
TheResourceWrapper
is a wrapper for anyResource
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
Constructors Constructor Description ResourceWrapper(@NotNull Resource resource)
Creates a new wrapper instance delegating all method calls to the givenresource
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <AdapterType>
AdapterTypeadaptTo(@NotNull java.lang.Class<AdapterType> type)
Returns the value of callingadaptTo
on thewrapped resource
.Resource
getChild(@NotNull java.lang.String relPath)
Returns the value of callinggetChild
on thewrapped resource
.@NotNull java.lang.Iterable<Resource>
getChildren()
Returns an iterable of the direct children of this resource.@NotNull java.lang.String
getName()
Returns the value of callinggetName
on thewrapped resource
.Resource
getParent()
Returns the value of callinggetParent
on thewrapped resource
.@NotNull java.lang.String
getPath()
Returns the value of callinggetPath
on thewrapped resource
.@NotNull Resource
getResource()
Returns theResource
wrapped by this instance.@NotNull ResourceMetadata
getResourceMetadata()
Returns the value of callinggetResourceMetadata
on thewrapped resource
.@NotNull ResourceResolver
getResourceResolver()
Returns the value of callinggetResourceResolver
on thewrapped resource
.java.lang.String
getResourceSuperType()
Returns the value of callinggetResourceSuperType
on thewrapped resource
.@NotNull java.lang.String
getResourceType()
Returns the value of callinggetResourceType
on thewrapped resource
.@NotNull ValueMap
getValueMap()
Returns a value map for this resource.boolean
hasChildren()
Returns the value of callinghasChildren
on thewrapped resource
.boolean
isResourceType(java.lang.String resourceType)
Returns the value of callingisResourceType
on thewrapped resource
.@NotNull java.util.Iterator<Resource>
listChildren()
Returns the value of callinglistChildren
on thewrapped resource
.java.lang.String
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 Detail
-
ResourceWrapper
public ResourceWrapper(@NotNull @NotNull Resource resource)
Creates a new wrapper instance delegating all method calls to the givenresource
.- Parameters:
resource
- The resource to wrap
-
-
Method Detail
-
getResource
@NotNull public @NotNull Resource 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
@NotNull public @NotNull java.lang.String getPath()
Returns the value of callinggetPath
on thewrapped resource
.
-
getName
@NotNull public @NotNull java.lang.String getName()
Returns the value of callinggetName
on thewrapped resource
.
-
getParent
public Resource getParent()
Returns the value of callinggetParent
on thewrapped resource
.- Specified by:
getParent
in interfaceResource
- Returns:
- The parent resource or
null
. - Since:
- 2.1.0 (Sling API Bundle 2.1.0)
- See Also:
ResourceResolver.getParent(Resource)
-
getChild
public Resource getChild(@NotNull @NotNull java.lang.String relPath)
Returns the value of callinggetChild
on thewrapped resource
.- Specified by:
getChild
in interfaceResource
- Parameters:
relPath
- relative path to the child resource- Returns:
- The child resource or
null
- Since:
- 2.1.0 (Sling API Bundle 2.1.0)
- See Also:
ResourceResolver.getResource(Resource, String)
-
listChildren
@NotNull public @NotNull java.util.Iterator<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:
ResourceResolver.listChildren(Resource)
-
getChildren
@NotNull public @NotNull java.lang.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
- Returns:
- An iterable for child resources
- See Also:
Resource.getChildren()
-
getResourceMetadata
@NotNull public @NotNull ResourceMetadata getResourceMetadata()
Returns the value of callinggetResourceMetadata
on thewrapped resource
.- Specified by:
getResourceMetadata
in interfaceResource
- Returns:
- The resource meta data
- See Also:
ResourceMetadata
-
getResourceResolver
@NotNull public @NotNull ResourceResolver getResourceResolver()
Returns the value of callinggetResourceResolver
on thewrapped resource
.- Specified by:
getResourceResolver
in interfaceResource
- Returns:
- The resource resolver
-
getResourceType
@NotNull public @NotNull java.lang.String getResourceType()
Returns the value of callinggetResourceType
on thewrapped resource
.- Specified by:
getResourceType
in interfaceResource
- Returns:
- The resource type
-
getResourceSuperType
public java.lang.String 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
public boolean isResourceType(java.lang.String resourceType)
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:
ResourceResolver.isResourceType(Resource, String)
-
adaptTo
public <AdapterType> AdapterType adaptTo(@NotNull @NotNull java.lang.Class<AdapterType> type)
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
@NotNull public @NotNull ValueMap 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:
Resource.getValueMap()
-
toString
public java.lang.String 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
.- Overrides:
toString
in classjava.lang.Object
-
-