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
TheResourceWrapperis a wrapper for anyResourcedelegating 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 callingadaptToon thewrapped resource.ResourcegetChild(@NotNull java.lang.String relPath)Returns the value of callinggetChildon thewrapped resource.@NotNull java.lang.Iterable<Resource>getChildren()Returns an iterable of the direct children of this resource.@NotNull java.lang.StringgetName()Returns the value of callinggetNameon thewrapped resource.ResourcegetParent()Returns the value of callinggetParenton thewrapped resource.@NotNull java.lang.StringgetPath()Returns the value of callinggetPathon thewrapped resource.@NotNull ResourcegetResource()Returns theResourcewrapped by this instance.@NotNull ResourceMetadatagetResourceMetadata()Returns the value of callinggetResourceMetadataon thewrapped resource.@NotNull ResourceResolvergetResourceResolver()Returns the value of callinggetResourceResolveron thewrapped resource.java.lang.StringgetResourceSuperType()Returns the value of callinggetResourceSuperTypeon thewrapped resource.@NotNull java.lang.StringgetResourceType()Returns the value of callinggetResourceTypeon thewrapped resource.@NotNull ValueMapgetValueMap()Returns a value map for this resource.booleanhasChildren()Returns the value of callinghasChildrenon thewrapped resource.booleanisResourceType(java.lang.String resourceType)Returns the value of callingisResourceTypeon thewrapped resource.@NotNull java.util.Iterator<Resource>listChildren()Returns the value of callinglistChildrenon thewrapped resource.java.lang.StringtoString()Returns a string representation of this wrapper consisting of the class' simple name, theresource typeandpathas 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 theResourcewrapped 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 callinggetPathon thewrapped resource.
-
getName
@NotNull public @NotNull java.lang.String getName()
Returns the value of callinggetNameon thewrapped resource.
-
getParent
public Resource getParent()
Returns the value of callinggetParenton thewrapped resource.- Specified by:
getParentin 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 callinggetChildon thewrapped resource.- Specified by:
getChildin 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 callinglistChildrenon thewrapped resource.- Specified by:
listChildrenin 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:ResourceReturns 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:
getChildrenin interfaceResource- Returns:
- An iterable for child resources
- See Also:
Resource.getChildren()
-
getResourceMetadata
@NotNull public @NotNull ResourceMetadata getResourceMetadata()
Returns the value of callinggetResourceMetadataon thewrapped resource.- Specified by:
getResourceMetadatain interfaceResource- Returns:
- The resource meta data
- See Also:
ResourceMetadata
-
getResourceResolver
@NotNull public @NotNull ResourceResolver getResourceResolver()
Returns the value of callinggetResourceResolveron thewrapped resource.- Specified by:
getResourceResolverin interfaceResource- Returns:
- The resource resolver
-
getResourceType
@NotNull public @NotNull java.lang.String getResourceType()
Returns the value of callinggetResourceTypeon thewrapped resource.- Specified by:
getResourceTypein interfaceResource- Returns:
- The resource type
-
getResourceSuperType
public java.lang.String getResourceSuperType()
Returns the value of callinggetResourceSuperTypeon thewrapped resource.- Specified by:
getResourceSuperTypein interfaceResource- Returns:
- The super type of the resource or
null.
-
hasChildren
public boolean hasChildren()
Returns the value of callinghasChildrenon thewrapped resource.- Specified by:
hasChildrenin interfaceResource- Returns:
trueif 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 callingisResourceTypeon thewrapped resource.- Specified by:
isResourceTypein interfaceResource- Parameters:
resourceType- the resource type to check this resource against- Returns:
trueif the resource type or any of the resource's super type(s) equals the given resource type,falseotherwise;falsecan also be returned ifresourceTypeis 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 callingadaptToon thewrapped resource.- Specified by:
adaptToin 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.classorjava.io.File.class- Returns:
- The adapter target or
nullif the object cannot adapt to the requested type
-
getValueMap
@NotNull public @NotNull ValueMap getValueMap()
Description copied from interface:ResourceReturns a value map for this resource. The value map allows to read the properties of the resource.- Specified by:
getValueMapin 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 typeandpathas well as the string representation of thewrapped resource.- Overrides:
toStringin classjava.lang.Object
-
-