Interface Asset
- All Superinterfaces:
Adaptable
Asset
interface describes the digital asset
with its methods.-
Method Summary
Modifier and TypeMethodDescriptionaddRendition
(String name, InputStream is, String mimeType) Adds/replaces aRendition
.addRendition
(String name, InputStream is, Map<String, Object> map) Adds/replaces aRendition
.addRendition
(String name, Binary binary, String mimeType) Adds/replaces aRendition
with given binary for supporting oak direct binary.Adds/replaces aRendition
with given binary for supporting oak direct binary.addSubAsset
(String name, String mimeType, InputStream stream) Adds/replaces a sub-asset to this asset.createRevision
(String label, String comment) Create a newRevision
of the asset.createRevision
(String label, String comment, User versionCreator) Create a newRevision
of the asset.Deprecated.Will be removed without replacement.getID()
This method returns the ID associated with an Asset Returns the non-null String value of Asset's ID May return an empty (non-null) stringThis method returns a suitableRendition
for rendering image rendition derivatives (thumbnails, previews, ptiff).long
Returns the date of last modification of the asset's main content node (jcr:lastModified property).Returns all available metadata as map.getMetadata
(String name) Returns the generic metadata value of an asset by the given property name.getMetadataValue
(String name) Returns the metadata String value of an asset by the given property name.This method is different from getMetadataValue(java.lang.String) as it doesn't fallback to parse xmp in asset if property not found in JCR.Returns the mime type of the asset's original binary.Returns the name of the modifier who modified the asset lastgetName()
Returns the name of the asset.Returns the asset's original as aRendition
.getPath()
Returns the repository path of the asset.getRendition
(RenditionPicker picker) Returns theRendition
, based on a customRenditionPicker
implementation.getRendition
(String name) This method returns theRendition
specified by its name.Returns a list of allRendition
s of this asset.getRevisions
(Calendar cal) Returns the revisions available for the current asset.Returns all sub-assets that exist for this asset.void
This method initializesDamConstants.DAM_ASSET_STATE
property toDamConstants.DAM_ASSET_STATE_UNPROCESSED
on the current asset.boolean
Indicates whether batch mode is enabled or not.boolean
Indicates if this asset is aSub Asset
.Returns an iterator for allRendition
s of this asset.void
removeRendition
(String name) Removes the rendition identified byname
Restores a revision of this asset as identified by the givenrevisionId
.void
setBatchMode
(boolean mode) Mark this asset as being part of a batch-mode process.void
setCurrentOriginal
(String name) Deprecated.Will be removed without replacement.setRendition
(String name, InputStream is, String mimeType) Deprecated.UseaddRendition(String, java.io.InputStream, String)
instead.setRendition
(String name, Binary binary, String mimeType) Adds/replaces aRendition
with given binary for supporting oak direct binary.
-
Method Details
-
getPath
String getPath()Returns the repository path of the asset.- Returns:
- path of the asset.
-
getName
String getName()Returns the name of the asset.- Returns:
- page name
-
getMetadataValue
Returns the metadata String value of an asset by the given property name. Note: Falls back to parse xmp in asset if property not found in JCR. Use of getMetadataValueFromJcr(java.lang.String) is recommended over this methodRetrieving a metadata value works as follows:
... Asset asset = resource.adaptTo(Asset.class); String assetTitle = asset.getMetadataValue("dc:title"); ...
- Parameters:
name
- metadata property name- Returns:
- the value or an empty string if the metadata property does not exist.
-
getMetadata
Returns the generic metadata value of an asset by the given property name. Falls back to parse xmp in asset if property not found in JCR.As asset metadata values are JCR repository based, a value may be of any type supported by the repository. As such for example a Calendar type property may be retrieved:
... Asset asset = resource.adaptTo(Asset.class); Calendar modified = (Calendar) asset.getMetadata(DamConstants.PN_MODIFIED); ...
- Parameters:
name
- metadata property name- Returns:
- the
Object
ornull
if the property does not exist.
-
getLastModified
long getLastModified()Returns the date of last modification of the asset's main content node (jcr:lastModified property).- Returns:
- lastmodified date as long
-
getRendition
This method returns theRendition
specified by its name. Available renditions are configured as part of the DAM Asset Update Workflow (see: http://dev.day.com/docs/en/cq/current/dam/customizing_and_extendingcq5dam.html#Customizing%20Renditions).Renditions are stored under the asset's main content node in the "renditions" folder, e.g. /content/dam/geometrixx/banners/banner-mono.png/jcr:content/renditions. The node name of a rendition in this folder is the name to be used as the method argument. For example the rendition path /content/dam/geometrixx/banners/banner-mono.png/jcr:content/renditions/cq5dam.thumbnail.140.100.png results in the rendition name "cq5dam.thumbnail.140.100.png". Sample:
... Asset asset = resource.adaptTo(Asset.class); Resource rendition = asset.getRendition("cq5dam.thumbnail.140.100.png"); ...
- Parameters:
name
- rendition name- Returns:
- the rendition or
null
- See Also:
-
getImagePreviewRendition
Rendition getImagePreviewRendition()This method returns a suitableRendition
for rendering image rendition derivatives (thumbnails, previews, ptiff). If a suitable rendition can't be found, the method will return the original rendition as a fallback.- Returns:
- Preview rendition, original rendition, or
null
if the original rendition doesn't exist.
-
getOriginal
Rendition getOriginal()Returns the asset's original as aRendition
. The original represents the binary file that was initially uploaded as the asset. It is the unmodified version of the asset. The original also represents a rendition of the asset, as such its storage path is in the asset's rendition folder, e.g. /content/dam/geometrixx/banners/banner-mono.png/jcr:content/renditions/original. The original, as any rendition, is persisted as a node of type nt:file in the repository. Subsequently access to the original's file data works through accessing its jcr:content subnode via resource API, or using theDownload
orImage
class. The Download and Image convenience classes automatically retrieve the rendition with the name original from the given asset resource.Using the resource API:
... Asset asset = resource.adaptTo(Asset.class); Resource original = asset.getOriginal(); InputStream stream = original.adaptTo(InputStream.class); ...
Using the asset as a download via the
Download
class:... Asset asset = resource.adaptTo(Asset.class); Download download = new Download(resource); String title = download.getTitle(); String mimeType = download.getMimeType(); javax.jcr.Property p = download.getData(); javax.jcr.Binary b = p.getBinary(); long size = b.getSize(); InputStream stream = b.getStream(); ...
Using the asset's original as an image via the
Image
class:... Asset asset = resource.adaptTo(Asset.class); Image image = new Image(resource); Layer layer = image.getLayer(true, true, true); ...
- Returns:
- file resource of the original file, or
null
if the original resource doesn't exist.
-
getCurrentOriginal
Deprecated.Will be removed without replacement. The concept of current originals will henceforth be managed through versioning the asset upon modifying the original. UsegetOriginal()
instead.Returns theRendition
representing the asset's rendition currently marked as the asset's unmodified, original version. A rendition is marked as the original of an asset via the existence of the property currentOriginal on the asset's content node. The property contains the path of the rendition to be considered the original. E.g. /content/dam/geometrixx/banners/banner-mono.png/jcr:content/currentOriginal with value /content/dam/geometrixx/banners/banner-mono.png/jcr:content/renditions/myOriginal.- Returns:
- current original rendition
- See Also:
-
isSubAsset
boolean isSubAsset()Indicates if this asset is aSub Asset
. Sub assets are assets stored under another asset, as a result of splitting up the asset in fragments during its import, e.g. the single pages of a multi-page PDF file.- Returns:
true
if it is aSub Asset
-
getMetadata
Returns all available metadata as map.- Returns:
- metadata
- See Also:
-
setRendition
Deprecated.UseaddRendition(String, java.io.InputStream, String)
instead.Saves a new rendition and returns the newly saved fileResource
. The modification date of the asset will be set automatically.- Parameters:
name
- rendition nameis
- InputStream of renditionmimeType
- The mime type of the rendition- Returns:
- rendition as resource
- Since:
- 5.3
- See Also:
-
setCurrentOriginal
Deprecated.Will be removed without replacement.Defines which rendition is marked as the asset'soriginal
version.- Parameters:
name
- name of rendition- See Also:
-
createRevision
Create a newRevision
of the asset. The revision will be created as a standard JCR version of the underlying asset node. Owner of the session through whichAsset
was created is added asinvalid reference
DamConstants.PN_VERSION_CREATOR
- Parameters:
label
- version label. Note that the version label must be unique across all versions.comment
- version comment- Returns:
- The created revision
- Throws:
Exception
- Thrown when an error during version creation occurred.
-
createRevision
Create a newRevision
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 ainvalid reference
DamConstants.PN_VERSION_CREATOR
- Parameters:
label
- version label. Note that the version label must be unique across all versions.comment
- version commentversionCreator
- version creator. If null, this API is equivalent tocreateRevision(java.lang.String,java.lang.String)
- Returns:
- The created revision
- Throws:
Exception
- Thrown when an error during version creation occurred.
-
getRenditions
Returns a list of allRendition
s of this asset.- Returns:
- The renditions.
-
listRenditions
Returns an iterator for allRendition
s of this asset.- Returns:
- The renditions.
- Since:
- 5.4
-
getRendition
Returns theRendition
, based on a customRenditionPicker
implementation.RenditionPicker
implementations are free to choose which rendition is to be returned.- Parameters:
picker
- TheRenditionPicker
implementation to use for selecting an asset's rendition.- Returns:
- the desired rendition or
null
if not existing.
-
getModifier
String getModifier()Returns the name of the modifier who modified the asset last- Returns:
- modifier userId
-
restore
Restores a revision of this asset as identified by the givenrevisionId
. If the revision ID does not pertain to the current asset or does not exist,null
is returned, otherwise the restored asset.- Parameters:
revisionId
- The id of the revision to restore.- Returns:
- The restored asset or
null
if the revision does not exist or doesn't pertain to the asset. - Throws:
Exception
- If an error is encountered during restoring the asset.- Since:
- CQ 5.4.0
-
getRevisions
Returns the revisions available for the current asset. The revisions can be filtered by date. Ifcal
is given, only revisions older or equal to the specified date are returned.- Parameters:
cal
- The calendar object to filter the revisions by.- Returns:
- The collection of revisions for this asset, or an empty collection if none were found.
- Throws:
Exception
- If an error occurred upon retrieving the revisions.- Since:
- CQ 5.4.0
-
getMimeType
String getMimeType()Returns the mime type of the asset's original binary. If a current original is marked, its mime type will be returned, otherwise the mime type of the asset's original rendition (./jcr:content/renditions/original). If no original could be found, or no mime type is set,null
is returned.- Returns:
- The mime type of the asset's original binary.
- Since:
- CQ 5.4.0
-
addRendition
Adds/replaces aRendition
. The modification date of the asset will be set automatically. If a rendition with the givenname
already exists, it will be replaced.- Parameters:
name
- rendition nameis
- InputStream of renditionmimeType
- The mime type of the rendition- Returns:
- rendition as resource
- Since:
- CQ 5.4.0
- See Also:
-
addRendition
Adds/replaces aRendition
. The modification date of the asset will be set automatically. If a rendition with the givenname
already exists, it will be replaced. Actual creation of rendition is delegated to theRenditionHandler
.- Parameters:
name
- rendition nameis
- InputStream to create this rendition or null if stream is not availablemap
- to be used by the rendition handler, it must containRenditionHandler.PROPERTY_ID
and optionally more properties as defined/required by the respectiveRenditionHandler
- Returns:
- rendition as resource
- Since:
- CQ 5.6.0
- See Also:
-
addRendition
Adds/replaces aRendition
with given binary for supporting oak direct binary. The modification date of the asset will be set automatically. If a rendition with the givenname
already exists, it will be replaced.- Parameters:
name
- rendition namebinary
- binary of renditionmimeType
- The mime type of the rendition- Returns:
- rendition as resource
- Since:
- CQ 6.5.0
-
addRendition
Adds/replaces aRendition
with given binary for supporting oak direct binary. The modification date of the asset will be set automatically. If a rendition with the givenname
already exists, it will be replaced. It will not delegate the actual creation of rendition to theRenditionHandler
likeaddRendition(String, InputStream, Map)
- Parameters:
name
- rendition namebinary
- binary to create this rendition or null if binary is not availablemap
- it contain properties for the renditions- Returns:
- rendition as resource
- Since:
- CQ 6.5.0
-
setRendition
Adds/replaces aRendition
with given binary for supporting oak direct binary. The modification date of the asset will be set automatically. If a rendition with the givenname
already exists, it will be replaced. The difference with addRendition is this method will not touch the asset state for original rendition- Parameters:
name
- rendition namebinary
- binary of renditionmimeType
- The mime type of the rendition- Returns:
- rendition as resource, return null if for any reason failed to create replace rendition
- Since:
- CQ 6.6.0
-
addSubAsset
Adds/replaces a sub-asset to this asset. If a sub-asset already exists, it will be replaced.- Parameters:
name
- The name of the sub-asset.mimeType
- The mime type of the sub-asset's original binary.stream
- The input stream of the sub-asset's original binary.- Returns:
- The newly added sub-asset.
- Since:
- CQ 5.4.0
-
getSubAssets
Collection<Asset> getSubAssets()Returns all sub-assets that exist for this asset.- Returns:
- The asset's collection of sub-assets.
- Since:
- CQ 5.4.0
-
removeRendition
Removes the rendition identified byname
- Parameters:
name
- The name of the rendition.- Since:
- CQ 5.4.0
-
setBatchMode
void setBatchMode(boolean mode) Mark this asset as being part of a batch-mode process. Settingmode
totrue
causes all changes made to the asset (e.g. viaaddRendition(String, java.io.InputStream, String)
not to be saved. It is then the responsibility of the caller to call a session save. This mode is particularly useful for batch changes to many assets at once with only one save call at the end so as to speed up operations. The only method exempt from batch mode iscreateRevision(String, String)
(will always cause save).- Parameters:
mode
- Set totrue
to enable batch mode for this asset.
-
isBatchMode
boolean isBatchMode()Indicates whether batch mode is enabled or not. If batch mode is enabled, any changes to the asset must be saved externally through a session save.- Returns:
- Whether batch mode is enabled or not. Default is
false
.
-
getMetadataValueFromJcr
This method is different from getMetadataValue(java.lang.String) as it doesn't fallback to parse xmp in asset if property not found in JCR. Returns the metadata String value of an asset by the given property name. Available property names are defined by the asset editor configuration used for a particular asset (see http://dev.day.com/docs/en/cq/current/dam/customizing_and_extendingcq5dam.html).Retrieving a metadata value works as follows:
... Asset asset = resource.adaptTo(Asset.class); String assetTitle = asset.getMetadataValue("dc:title"); ...
- Parameters:
name
- metadata property name- Returns:
- the value or an empty string if the metadata property does not exist.
-
getID
String getID()This method returns the ID associated with an Asset Returns the non-null String value of Asset's ID May return an empty (non-null) string- Returns:
- the ID of an asset.
-
initAssetState
This method initializesDamConstants.DAM_ASSET_STATE
property toDamConstants.DAM_ASSET_STATE_UNPROCESSED
on the current asset.- Throws:
RepositoryException
- Thrown in case of error in initialization.
-