Class FileResource

All Implemented Interfaces:
Adaptable, Resource

@Adaptable(adaptableClass=Resource.class,adapters={@Adapter({java.io.File.class,java.net.URL.class}),@Adapter(condition="If the resource is an FsResource and is a readable file.",value=java.io.InputStream.class)}) public final class FileResource extends AbstractResource
The FsResource represents a file system file or folder as a Sling Resource.
  • Method Details

    • getPath

      @NotNull public @NotNull String getPath()
      Returns the path of this resource
      Returns:
      The resource path
    • getResourceMetadata

      @NotNull public @NotNull ResourceMetadata getResourceMetadata()
      Returns the resource meta data for this resource containing the file length, last modification time and the resource path (same as getPath()).
      Returns:
      The resource meta data
      See Also:
    • getResourceResolver

      @NotNull public @NotNull ResourceResolver getResourceResolver()
      Returns the resource resolver which cause this resource object to be created.
      Returns:
      The resource resolver
    • getResourceSuperType

      public String getResourceSuperType()
      Description copied from interface: Resource
      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.
    • getResourceType

      @NotNull public @NotNull String getResourceType()
      Description copied from interface: Resource
      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.RESOURCE_TYPE_NON_EXISTING.

      Returns:
      The resource type
    • adaptTo

      @Nullable public <AdapterType> AdapterType adaptTo(@NotNull @NotNull Class<AdapterType> type)
      Returns an adapter for this resource. This implementation supports File, InputStream and URL plus those supported by the adapter manager.
      Specified by:
      adaptTo in interface Adaptable
      Overrides:
      adaptTo in class SlingAdaptable
      Type Parameters:
      AdapterType - The generic type to which this resource 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 resource cannot adapt to the requested type
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getValueMap

      public ValueMap getValueMap()
      Description copied from class: AbstractResource
      This method calls Adaptable.adaptTo(Class) with the ValueMap class as an argument. If the adaptTo method returns a map, this map is returned. If the resource is not adaptable to a value map, next an adaption to Map is tried and if this is successful the map is wrapped as a value map. If the adaptions are not successful an empty value map is returned.
      Specified by:
      getValueMap in interface Resource
      Overrides:
      getValueMap in class AbstractResource
      Returns:
      A value map
      See Also: