Class ResourceWrapper

java.lang.Object
org.apache.sling.api.resource.ResourceWrapper
All Implemented Interfaces:
Adaptable, Resource

public class ResourceWrapper extends Object implements Resource
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.
  • Constructor Details

    • ResourceWrapper

      public ResourceWrapper(@NotNull @NotNull Resource resource)
      Creates a new wrapper instance delegating all method calls to the given resource.
      Parameters:
      resource - The resource to wrap
  • Method Details

    • getResource

      @NotNull public @NotNull Resource getResource()
      Returns the Resource 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 String getPath()
      Returns the value of calling getPath on the wrapped resource.
      Specified by:
      getPath in interface Resource
      Returns:
      The resource path
    • getName

      @NotNull public @NotNull String getName()
      Returns the value of calling getName on the wrapped resource.
      Specified by:
      getName in interface Resource
      Returns:
      The resource name
      Since:
      2.1.0 (Sling API Bundle 2.1.0)
    • getParent

      public Resource getParent()
      Returns the value of calling getParent on the wrapped resource.
      Specified by:
      getParent in interface Resource
      Returns:
      The parent resource or null.
      Since:
      2.1.0 (Sling API Bundle 2.1.0)
      See Also:
    • getChild

      public Resource getChild(@NotNull @NotNull String relPath)
      Returns the value of calling getChild on the wrapped resource.
      Specified by:
      getChild in interface Resource
      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:
    • listChildren

      @NotNull public @NotNull Iterator<Resource> listChildren()
      Returns the value of calling listChildren on the wrapped resource.
      Specified by:
      listChildren in interface Resource
      Returns:
      An iterator for child resources.
      Since:
      2.1.0 (Sling API Bundle 2.1.0)
      See Also:
    • getChildren

      @NotNull public @NotNull 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 interface Resource
      Returns:
      An iterable for child resources
      See Also:
    • getResourceMetadata

      @NotNull public @NotNull ResourceMetadata getResourceMetadata()
      Returns the value of calling getResourceMetadata on the wrapped resource.
      Specified by:
      getResourceMetadata in interface Resource
      Returns:
      The resource meta data
      See Also:
    • getResourceResolver

      @NotNull public @NotNull ResourceResolver getResourceResolver()
      Returns the value of calling getResourceResolver on the wrapped resource.
      Specified by:
      getResourceResolver in interface Resource
      Returns:
      The resource resolver
    • getResourceType

      @NotNull public @NotNull String getResourceType()
      Returns the value of calling getResourceType on the wrapped resource.
      Specified by:
      getResourceType in interface Resource
      Returns:
      The resource type
    • getResourceSuperType

      public String getResourceSuperType()
      Returns the value of calling getResourceSuperType on the wrapped resource.
      Specified by:
      getResourceSuperType in interface Resource
      Returns:
      The super type of the resource or null.
    • hasChildren

      public boolean hasChildren()
      Returns the value of calling hasChildren on the wrapped resource.
      Specified by:
      hasChildren in interface Resource
      Returns:
      true if the resource has any child resources
      Since:
      2.4.4 (Sling API Bundle 2.5.0)
    • isResourceType

      public boolean isResourceType(String resourceType)
      Returns the value of calling isResourceType on the wrapped resource.
      Specified by:
      isResourceType in interface Resource
      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 if resourceType is null
      Since:
      2.1.0 (Sling API Bundle 2.1.0)
      See Also:
    • adaptTo

      public <AdapterType> AdapterType adaptTo(@NotNull @NotNull Class<AdapterType> type)
      Returns the value of calling adaptTo on the wrapped resource.
      Specified by:
      adaptTo in interface Adaptable
      Type Parameters:
      AdapterType - The generic type to which this object is adapted to
      Parameters:
      type - The Class object of the target type, such as javax.jcr.Node.class or java.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 interface Resource
      Returns:
      A value map
      See Also:
    • toString

      public String toString()
      Returns a string representation of this wrapper consisting of the class' simple name, the resource type and path as well as the string representation of the wrapped resource.
      Overrides:
      toString in class Object