Interface Asset

All Superinterfaces:
Adaptable, Resource

@ProviderType public interface Asset extends Resource
Asset represents a digital resource.

Asset is an extension of a Sling Resource, therefore its adaptable.

Asset is created by AssetManager and can be retrieved either via AssetManager or by adapting a asset Resource to an Asset.

     eg:
     // to create an asset
     AssetManager assetManager = resolver.adaptTo(AssetManager.class);
     Asset newAsset = assetManager.createAsset("/path/to/asset/document.pdf");

     // to get an existing asset
     Asset asset = assetManager.getAsset("/path/to/asset/document.pdf");

     // to get asset by adapting
     Asset asset = resource.adaptTo(Asset.class);
 

Asset properties can be retrieved or set by adapting it to a ValueMap.

     eg:
     // to get Asset properties value map
     ValueMap map = asset.adaptTo(ValueMap.class);
 

Implementor's Note: Implementations are required to provide an adapter to a writable ValueMap.

See Also:
  • Method Details

    • getRendition

      Rendition getRendition(String name)
      Returns a named Rendition if available.
      Parameters:
      name - Name of the Rendition to get
      Returns:
      The Rendition object or null if Rendition with the given name cannot be found
      Throws:
      AssetException - If an error occurs trying to load the Rendition object
    • listRenditions

      Iterator<? extends Rendition> listRenditions()
      Returns an iterator for all Renditions of this asset.
      Returns:
      The Iterator of renditions or an empty iterator if no renditions has been created.
    • listRelated

      Iterator<? extends Asset> listRelated(String name)
      Get all related Asset with the given name.
      Parameters:
      name - Name of the related asset collection
      Returns:
      Iterator of related Assets or an empty iterator if relations cannot be found with the given name.
    • listRelations

      Iterator<? extends AssetRelation> listRelations(String name)
      Get asset relations for a given relation name.
      Parameters:
      name - Name of the relation
      Returns:
      Iterator of AssetRelation or an empty iterator if relations cannot be found with the given name.
      Since:
      1.3
    • getAssetMetadata

      AssetMetadata getAssetMetadata()
      Returns the metadata of this Asset.
      Returns:
      instance of AssetMetadata
      Since:
      1.8
    • addRelation

      AssetRelation addRelation(String name, String assetPath, Map<String,Object> map)
      Adds a new relation to this Asset with additional properties
      Parameters:
      name - of the relation to be created
      assetPath - Path of the Asset to set a relation for
      map - to be used to set additional relation properties.
      Returns:
      instance of AssetRelation
      Throws:
      AssetException - if Asset relation cannot be set.
      Since:
      1.3
    • setRelation

      @Deprecated void setRelation(String name, String assetPath)
      Deprecated.
      As of 1.3, please use addRelation(String, String)
      Sets a new relation to this Asset.
      Parameters:
      name - of the relation to be created
      assetPath - Path of the Asset to set a relation for
      Throws:
      AssetException - if Asset relation cannot be set.
    • addRelation

      AssetRelation addRelation(String name, String assetPath)
      adds a new relation to this Asset.
      Parameters:
      name - of the relation to be created
      assetPath - Path of the Asset to set a relation for
      Returns:
      instance of AssetRelation
      Throws:
      AssetException - if Asset relation cannot be set.
      Since:
      1.3
    • orderRelationBefore

      void orderRelationBefore(String name, String srcAssetPath, String destAssetPath)
      This method inserts the related asset at srcAssetPath into the related asset list at the position immediately before the related asset at destAssetPath. To insert the related asset into last position, destAssetPath can be null.
      Parameters:
      name - Name of the relation to be ordered
      srcAssetPath - asset path that needs to be moved in the order
      destAssetPath - path of the related asset before which the srcAssetPath will be placed.
      Throws:
      IllegalArgumentException - if srcAssetPath is null or srcAssetPath is not related to Asset. if srcAssetPath and destAssetPath represents the same Asset.
      Since:
      1.3
    • removeRelation

      void removeRelation(String name, String assetPath)
      Removes Asset relation.
      Parameters:
      name - of the relation
      assetPath - Path of the Asset to be removed from the relations
      Throws:
      AssetException - if relation cannot be deleted
    • removeRelation

      void removeRelation(String name)
      Removes all relations for the given name.
      Parameters:
      name - of the relation
      Throws:
      AssetException - if relation cannot be deleted
    • getIdentifier

      String getIdentifier()
      Get unique Asset identifier
      Returns:
      Asset identifier as String or null if Asset has no unique identifier
    • setRendition

      Rendition setRendition(String name, InputStream is, Map<String,Object> map)
      Create or update the Rendition. If a rendition with the given name already exists, it will be replaced. Actual creation of rendition is delegated to the RenditionHandler.
      Parameters:
      name - to be used for this rendition
      is - InputStream to create this rendition or null if stream is not required by the RenditionHandler
      map - to be used by the rendition handler. If the map contains RenditionHandler.PROPERTY_ID, implementation is required to delegate to the RenditionHandler registered with this id. Otherwise, a default rendition handler must be used. Implementations are free to define the semantics of what constitutes a default rendition handler.
      Returns:
      newly created or updated rendition
      Throws:
      AssetException - if new rendition cannot be set
      NullPointerException - if the given map is null
    • setRendition

      Rendition setRendition(String name, Binary binary, Map<String,Object> map)
      Create or update the Rendition. If a rendition with the given name already exists, it will be replaced. Not like the setRendition(String, InputStream, Map), this method does not delegate to any RenditionHandler.
      Parameters:
      name - to be used for this rendition
      binary - binary to create this rendition or null if binary is not required by the RenditionHandler
      map - to be used for passing through mimeType etc. properties for the rendition. Not like the setRendition(String, InputStream, Map), this method does not delegate to any RenditionHandler. so any renditionHandlerID passed through the map does not work here
      Returns:
      newly created or updated rendition
      Throws:
      AssetException - if new rendition cannot be set
      NullPointerException - if the given map is null
    • removeRendition

      void removeRendition(String name)
      Remove Rendition with the given name.
      Parameters:
      name - of the Rendition
      Throws:
      AssetException - if Rendition cannot be removed