Interface Resource

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String RESOURCE_TYPE_NON_EXISTING
      The special resource type for resource instances representing nonexisting resources (value is "sling:nonexisting").
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      @Nullable Resource getChild​(@NotNull java.lang.String relPath)
      Returns the child at the given relative path of this resource or null if no such child exists.
      @NotNull java.lang.Iterable<Resource> getChildren()
      Returns an iterable of the direct children of this resource.
      @NotNull java.lang.String getName()
      Returns the name of this resource.
      @Nullable Resource getParent()
      Returns the parent resource or null if this resource represents the root of the resource tree.
      @NotNull java.lang.String getPath()
      Returns the absolute path of this resource in the resource tree.
      @NotNull ResourceMetadata getResourceMetadata()
      Returns the meta data of this resource.
      @NotNull ResourceResolver getResourceResolver()
      Returns the ResourceResolver from which this resource has been retrieved.
      @Nullable java.lang.String getResourceSuperType()
      Returns the super type of the resource if the resource defines its own super type.
      @NotNull java.lang.String getResourceType()
      The resource type is meant to point to rendering/processing scripts, editing dialogs, etc.
      @NotNull ValueMap getValueMap()
      Returns a value map for this resource.
      boolean hasChildren()
      Checks if the resource has any child resources.
      boolean isResourceType​(java.lang.String resourceType)
      Is just a shortcut for getResourceResolver().isResourceType(this, resourceType).
      @NotNull java.util.Iterator<Resource> listChildren()
      Returns an iterator of the direct children of this resource.
    • Method Detail

      • getPath

        @NotNull
        @NotNull java.lang.String getPath()
        Returns the absolute path of this resource in the resource tree.
        Returns:
        The resource path
      • getName

        @NotNull
        @NotNull java.lang.String getName()
        Returns the name of this resource. The name of a resource is the last segment of the path.
        Returns:
        The resource name
        Since:
        2.1 (Sling API Bundle 2.2.0)
      • getParent

        @Nullable
        @Nullable Resource getParent()
        Returns the parent resource or null if this resource represents the root of the resource tree.
        Returns:
        The parent resource or null.
        Throws:
        SlingException - If an error occurs trying to get the resource object from the path.
        java.lang.IllegalStateException - if the resource resolver has already been closed}.
        Since:
        2.1 (Sling API Bundle 2.1.0)
        See Also:
        ResourceResolver.getParent(Resource)
      • listChildren

        @NotNull
        @NotNull java.util.Iterator<Resource> listChildren()
        Returns an iterator of the direct children of this resource.

        This method is a convenience and returns exactly the same resources as calling getResourceResolver().listChildren(resource).

        Returns:
        An iterator for child resources.
        Throws:
        SlingException - If an error occurs trying to get the resource iterator.
        java.lang.IllegalStateException - if the resource resolver has already been closed}.
        Since:
        2.1 (Sling API Bundle 2.1.0)
        See Also:
        ResourceResolver.listChildren(Resource)
      • getChildren

        @NotNull
        @NotNull java.lang.Iterable<Resource> getChildren()
        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).

        Returns:
        An iterable for child resources
        Throws:
        SlingException - If an error occurs trying to get the resource iterator.
        java.lang.IllegalStateException - if the resource resolver has already been closed}.
        Since:
        2.2 (Sling API Bundle 2.2.0)
        See Also:
        ResourceResolver.getChildren(Resource)
      • getChild

        @Nullable
        @Nullable Resource getChild​(@NotNull
                                    @NotNull java.lang.String relPath)
        Returns the child at the given relative path of this resource or null if no such child exists.

        This method is a convenience and returns exactly the same resources as calling getResourceResolver().getResource(resource, relPath).

        Parameters:
        relPath - relative path to the child resource
        Returns:
        The child resource or null
        Throws:
        SlingException - If an error occurs trying to get the resource object from the path.
        java.lang.IllegalStateException - if the resource resolver has already been closed}.
        Since:
        2.1 (Sling API Bundle 2.1.0)
        See Also:
        ResourceResolver.getResource(Resource, String)
      • getResourceType

        @NotNull
        @NotNull java.lang.String getResourceType()
        The resource type is meant to point to rendering/processing scripts, editing dialogs, etc. It is usually a path in the repository, where scripts and other tools definitions are found, but the ResourceResolver is free to set this to any suitable value such as the primary node type of the JCR node from which the resource is created.

        If the resource instance represents a resource which is not actually existing, this method returns RESOURCE_TYPE_NON_EXISTING.

        Returns:
        The resource type
      • getResourceSuperType

        @Nullable
        @Nullable java.lang.String getResourceSuperType()
        Returns the super type of the resource if the resource defines its own super type. Otherwise null is returned. A resource might return a resource super type to overwrite the resource type hierarchy. If a client is interested in the effective resource super type of a resource, it should call ResourceResolver.getParentResourceType(Resource).
        Returns:
        The super type of the resource or null.
        Throws:
        java.lang.IllegalStateException - if this resource resolver has already been closed.
      • hasChildren

        boolean hasChildren()
        Checks if the resource has any child resources.
        Returns:
        true if the resource has any child resources
        Throws:
        java.lang.IllegalStateException - if this resource resolver has already been closed.
        Since:
        2.4.4 (Sling API Bundle 2.5.0)
      • isResourceType

        boolean isResourceType​(java.lang.String resourceType)
        Is just a shortcut for getResourceResolver().isResourceType(this, resourceType).
        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:
        ResourceResolver.isResourceType(Resource, String)
      • getResourceMetadata

        @NotNull
        @NotNull ResourceMetadata getResourceMetadata()
        Returns the meta data of this resource. The concrete data contained in the ResourceMetadata object returned is implementation specific except for the ResourceMetadata.RESOLUTION_PATH property which is required to be set to the part of the request URI used to resolve the resource.
        Returns:
        The resource meta data
        See Also:
        ResourceMetadata
      • getResourceResolver

        @NotNull
        @NotNull ResourceResolver getResourceResolver()
        Returns the ResourceResolver from which this resource has been retrieved.
        Returns:
        The resource resolver
      • getValueMap

        @NotNull
        @NotNull ValueMap getValueMap()
        Returns a value map for this resource. The value map allows to read the properties of the resource.
        Returns:
        A value map
        Since:
        2.5 (Sling API Bundle 2.7.0)