Interface AssetManager


  • public interface AssetManager
    The AssetManager provides utility methods for assets.

    The asset manager can be retrieved as follows:

       ...
       AssetManager manager = resourceResolver.adaptTo(AssetManager.class);
       ...
     
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String assignAssetID​(Asset asset)
      Ask Asset ID Provider (associated with Asset Manager) to assign ID (if needed) to an asset and establish its parentage (dam:parentAssetID)
      Asset createAsset​(java.lang.String path, java.io.InputStream is, java.lang.String mimeType, boolean doSave)
      Creates a new Asset at the given path.
      Asset createAssetForBinary​(java.lang.String binaryPath, boolean doSave)
      This method creates the complete asset structure in /content/dam.
      Asset createOrUpdateAsset​(java.lang.String path, javax.jcr.Binary binary, java.lang.String mimeType, boolean doSave)
      Creates a new Asset at the given path.
      Revision createRevision​(Asset asset, java.lang.String label, java.lang.String comment)
      Create a new Revision of the asset.
      Revision createRevision​(Asset asset, java.lang.String label, java.lang.String comment, User versionCreator)
      Create a new Revision of the asset.
      Asset getAssetForBinary​(java.lang.String binaryPath)
      Returns the Resource of the Asset corresponding to the binary given with the path parameter.
      java.util.Collection<Revision> getRevisions​(java.lang.String path, java.util.Calendar cal)
      Lists all available Revisions.
      boolean removeAssetForBinary​(java.lang.String binaryPath)
      Removes the Node of the Asset corresponding to the binary given with the path parameter.
      Asset restore​(java.lang.String revisionId)
      Restores an Asset.
    • Method Detail

      • restore

        Asset restore​(java.lang.String revisionId)
               throws java.lang.Exception
        Restores an Asset.
        Parameters:
        revisionId - revision id
        Returns:
        the restored Asset
        Throws:
        java.lang.Exception - Upon encountering an error while restoring an asset.
      • getRevisions

        java.util.Collection<Revision> getRevisions​(java.lang.String path,
                                                    java.util.Calendar cal)
                                             throws java.lang.Exception
        Lists all available Revisions.
        Parameters:
        path - path of asset
        cal - starting date to search revisions or null in order to fetch all
        Returns:
        all available Revisions
        Throws:
        java.lang.Exception - Upon encountering an error while getting the revisions for an asset.
      • createAssetForBinary

        Asset createAssetForBinary​(java.lang.String binaryPath,
                                   boolean doSave)
        This method creates the complete asset structure in /content/dam. The following structure is created: <xmp> + file.jpg (dam:Asset) + jcr:content )(dam:AssetContent) + renditions (sling:OrderedFolder) + metadata (nt:unstructured)

        </xmp>

        The given binaryPath is translated into the final asset location (see DamUtil.binaryToAssetPath(String)).

        Parameters:
        binaryPath - The path of the asset's binary in /var/dam.
        doSave - Whether the repository changes are saved or not.
        Returns:
        The newly created asset or null if the binaryPath cannot be handled
      • getAssetForBinary

        Asset getAssetForBinary​(java.lang.String binaryPath)
        Returns the Resource of the Asset corresponding to the binary given with the path parameter.
           DamUtil.getAssetNode("/var/dam/myfolder/test.jpg", session)    =  Resource("/content/dam/myfolder/test.jpg")
         
        Parameters:
        binaryPath - The path of the binary.
        Returns:
        The resource representing the binary's asset, or null if it couldn't be found.
      • removeAssetForBinary

        boolean removeAssetForBinary​(java.lang.String binaryPath)
        Removes the Node of the Asset corresponding to the binary given with the path parameter.
           DamUtil.removeAssetNode("/var/dam/myfolder/test.jpg", session) =i> Delete Node("/content/dam/myfolder/test.jpg")
         
        Parameters:
        binaryPath - The path of the binary.
        Returns:
        true if the asset was successfully removed.
      • createAsset

        Asset createAsset​(java.lang.String path,
                          java.io.InputStream is,
                          java.lang.String mimeType,
                          boolean doSave)
        Creates a new Asset at the given path. If an asset already exists at the given path, its original rendition is updated instead of creating a new asset. If inputStream is null new Asset is created without original rendition. If an asset already exists at given path and inputstream is null, original rendition is not updated.
        Parameters:
        path - The path of the asset to be created.
        is - The input stream of the new asset's original binary.
        mimeType - The mime type of the new asset's original binary.
        doSave - Whether the repository changes are saved or not.
        Returns:
        The newly created asset or null if something exists at the given path already or there was an unexpected error
      • createOrUpdateAsset

        Asset createOrUpdateAsset​(java.lang.String path,
                                  javax.jcr.Binary binary,
                                  java.lang.String mimeType,
                                  boolean doSave)
        Creates a new Asset at the given path. If an asset already exists at the given path, its original rendition is updated instead of creating a new asset. If binary is null new Asset is created without original rendition. If an asset already exists at given path, original rendition is not updated.
        Parameters:
        path - The path of the asset to be created.
        binary - The binary for new asset's original
        mimeType - The mime type of the new asset's original binary.
        doSave - Whether the repository changes are saved or not.
        Returns:
        The newly created asset or null if something exists at the given path already or there was an unexpected error
      • createRevision

        Revision createRevision​(Asset asset,
                                java.lang.String label,
                                java.lang.String comment)
                         throws java.lang.Exception
        Create a new Revision of the asset. The revision will be created as a standard JCR version of the underlying asset node. Owner of the session through which Asset was created is added as DamConstants.PN_VERSION_CREATOR of the asset.
        Parameters:
        asset - The asset to version
        label - version label
        comment - version comment
        Returns:
        The created revision
        Throws:
        java.lang.Exception - Thrown when an error during version creation occurred.
      • createRevision

        Revision createRevision​(Asset asset,
                                java.lang.String label,
                                java.lang.String comment,
                                User versionCreator)
                         throws java.lang.Exception
        Create a new Revision of the asset. The revision will be created as a standard JCR version of the underlying asset node. This API allows specifying principal of an AEM User to be added a DamConstants.PN_VERSION_CREATOR of the asset being versioned.
        Parameters:
        asset - The asset to version
        label - version label
        comment - version comment
        versionCreator - version creator. If null, this API is equivalent to createRevision(com.day.cq.dam.api.Asset,java.lang.String,java.lang.String)
        Returns:
        The created revision
        Throws:
        java.lang.Exception - Thrown when an error during version creation occurred.
      • assignAssetID

        java.lang.String assignAssetID​(Asset asset)
                                throws javax.jcr.PathNotFoundException,
                                       javax.jcr.RepositoryException
        Ask Asset ID Provider (associated with Asset Manager) to assign ID (if needed) to an asset and establish its parentage (dam:parentAssetID)
        Parameters:
        asset - The asset to update
        Returns:
        The ID assigned to the asset
        Throws:
        javax.jcr.RepositoryException - thrown if an error occurs while accessing the asset
        javax.jcr.PathNotFoundException - thrown if no item exists in the path