com.day.cq.dam.api
Interface Asset

All Superinterfaces:
Adaptable

public interface Asset
extends Adaptable

The Asset interface describes the digital asset with its methods.


Method Summary
 Revision createRevision(String label, String comment)
          Create a new Revision of the asset.
 Resource getCurrentOriginal()
          Returns the Resource representing the asset's rendition currently marked as the asset's unmodified, original version.
 long getLastModified()
          Returns the date of last modification of the asset's main content node (jcr:lastModified property).
 Map<String,Object> getMetadata()
          Returns all available metadata as map.
 Object getMetadata(String name)
          Returns the generic metadata value of an asset by the given property name.
 String getMetadataValue(String name)
          Returns the metadata String value of an asset by the given property name.
 String getModifier()
          Returns the name of the modifier who modified the asset last
 String getName()
          Returns the name of the asset.
 Resource getOriginal()
          Returns the Resource of the original file.
 String getPath()
          Returns the repository path of the asset.
 Resource getRendition(RenditionPicker picker)
          Returns the file Resource of a rendition, based on a custom RenditionPicker implementation.
 Resource getRendition(String name)
          This method returns the Resource of an asset's rendition specified by its name.
 List<Resource> getRenditions()
          Lists all available renditions.
 boolean isSubAsset()
          Indicates if this asset is a Sub Asset.
 void setCurrentOriginal(String name)
          Defines which rendition is marked as the asset's original version.
 Resource setRendition(String name, InputStream is)
          Deprecated. since 5.3 use setRendition(String, java.io.InputStream, String)
 Resource setRendition(String name, InputStream is, String mimeType)
          Saves a new rendition and returns the newly saved file Resource.
 
Methods inherited from interface org.apache.sling.api.adapter.Adaptable
adaptTo
 

Method Detail

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

String getMetadataValue(String name)
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.

getMetadata

Object getMetadata(String name)
Returns the generic metadata 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).

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("dc:modified");
      ...
 

Parameters:
name - metadata property name
Returns:
the Object or null 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

Resource getRendition(String name)
This method returns the Resource of an asset's rendition 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

getOriginal

Resource getOriginal()
Returns the Resource of the original file. The original file 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 the Download or Image 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

getCurrentOriginal

Resource getCurrentOriginal()
Returns the Resource 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:
getOriginal()

isSubAsset

boolean isSubAsset()
Indicates if this asset is a Sub 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 a Sub Asset

getMetadata

Map<String,Object> getMetadata()
Returns all available metadata as map.

Returns:
metadata
See Also:
getMetadataValue(String)

setRendition

Resource setRendition(String name,
                      InputStream is)
Deprecated. since 5.3 use setRendition(String, java.io.InputStream, String)

Save a new rendition. The mimetype of the original rendition is taken.

Parameters:
name - rendition name
is - inputstream of rendition
Returns:
rendition as resource
See Also:
setRendition(String, java.io.InputStream, String)

setRendition

Resource setRendition(String name,
                      InputStream is,
                      String mimeType)
Saves a new rendition and returns the newly saved file Resource. The modification date of the asset will be set automatically.

Parameters:
name - rendition name
is - InputStream of rendition
mimeType - The mime type of the rendition
Returns:
rendition as resource
Since:
5.3
See Also:
getRendition(String), getRenditions()

setCurrentOriginal

void setCurrentOriginal(String name)
Defines which rendition is marked as the asset's original version.

Parameters:
name - name of rendition
See Also:
getCurrentOriginal()

createRevision

Revision createRevision(String label,
                        String comment)
                        throws Exception
Create a new Revision of the asset. The revision will be created as a standard JCR version of the underlying asset node.

Parameters:
label - version label
comment - version comment
Returns:
The created revision
Throws:
Exception - Thrown when an error during version creation occurred.

getRenditions

List<Resource> getRenditions()
Lists all available renditions.

Returns:
list of all available renditions

getRendition

Resource getRendition(RenditionPicker picker)
Returns the file Resource of a rendition, based on a custom RenditionPicker implementation. RenditionPicker implementations are free to choose which rendition is to be returned.

Parameters:
picker - The RenditionPicker 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


Copyright © 1993-2010 Day Management AG. All Rights Reserved.