Package com.adobe.granite.asset.api
Interface Asset
-
@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 viaAssetManager
or by adapting a assetResource
to anAsset
.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:
AssetManager
,ValueMap
-
-
Field Summary
-
Fields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description AssetRelation
addRelation(java.lang.String name, java.lang.String assetPath)
adds a new relation to this Asset.AssetRelation
addRelation(java.lang.String name, java.lang.String assetPath, java.util.Map<java.lang.String,java.lang.Object> map)
Adds a new relation to this Asset with additional propertiesAssetMetadata
getAssetMetadata()
Returns the metadata of this Asset.java.lang.String
getIdentifier()
Get unique Asset identifierRendition
getRendition(java.lang.String name)
Returns a namedRendition
if available.java.util.Iterator<? extends Asset>
listRelated(java.lang.String name)
Get all related Asset with the given name.java.util.Iterator<? extends AssetRelation>
listRelations(java.lang.String name)
Get asset relations for a given relation name.java.util.Iterator<? extends Rendition>
listRenditions()
Returns an iterator for allRendition
s of this asset.void
orderRelationBefore(java.lang.String name, java.lang.String srcAssetPath, java.lang.String destAssetPath)
This method inserts the related asset atsrcAssetPath
into the related asset list at the position immediately before the related asset atdestAssetPath
.void
removeRelation(java.lang.String name)
Removes all relations for the given name.void
removeRelation(java.lang.String name, java.lang.String assetPath)
Removes Asset relation.void
removeRendition(java.lang.String name)
RemoveRendition
with the given name.void
setRelation(java.lang.String name, java.lang.String assetPath)
Deprecated.As of 1.3, please useaddRelation(String, String)
Rendition
setRendition(java.lang.String name, java.io.InputStream is, java.util.Map<java.lang.String,java.lang.Object> map)
Create or update theRendition
.Rendition
setRendition(java.lang.String name, Binary binary, java.util.Map<java.lang.String,java.lang.Object> map)
Create or update theRendition
.-
Methods inherited from interface org.apache.sling.api.resource.Resource
getChild, getChildren, getName, getParent, getPath, getResourceMetadata, getResourceResolver, getResourceSuperType, getResourceType, getValueMap, hasChildren, isResourceType, listChildren
-
-
-
-
Method Detail
-
getRendition
Rendition getRendition(java.lang.String name)
Returns a namedRendition
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
java.util.Iterator<? extends Rendition> listRenditions()
Returns an iterator for allRendition
s of this asset.- Returns:
- The Iterator of renditions or an empty iterator if no renditions has been created.
-
listRelated
java.util.Iterator<? extends Asset> listRelated(java.lang.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
java.util.Iterator<? extends AssetRelation> listRelations(java.lang.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(java.lang.String name, java.lang.String assetPath, java.util.Map<java.lang.String,java.lang.Object> map)
Adds a new relation to this Asset with additional properties- Parameters:
name
- of the relation to be createdassetPath
- Path of the Asset to set a relation formap
- 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(java.lang.String name, java.lang.String assetPath)
Deprecated.As of 1.3, please useaddRelation(String, String)
Sets a new relation to this Asset.- Parameters:
name
- of the relation to be createdassetPath
- Path of the Asset to set a relation for- Throws:
AssetException
- if Asset relation cannot be set.
-
addRelation
AssetRelation addRelation(java.lang.String name, java.lang.String assetPath)
adds a new relation to this Asset.- Parameters:
name
- of the relation to be createdassetPath
- 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(java.lang.String name, java.lang.String srcAssetPath, java.lang.String destAssetPath)
This method inserts the related asset atsrcAssetPath
into the related asset list at the position immediately before the related asset atdestAssetPath
. To insert the related asset into last position,destAssetPath
can be null.- Parameters:
name
- Name of the relation to be orderedsrcAssetPath
- asset path that needs to be moved in the orderdestAssetPath
- path of the related asset before which thesrcAssetPath
will be placed.- Throws:
java.lang.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(java.lang.String name, java.lang.String assetPath)
Removes Asset relation.- Parameters:
name
- of the relationassetPath
- Path of the Asset to be removed from the relations- Throws:
AssetException
- if relation cannot be deleted
-
removeRelation
void removeRelation(java.lang.String name)
Removes all relations for the given name.- Parameters:
name
- of the relation- Throws:
AssetException
- if relation cannot be deleted
-
getIdentifier
java.lang.String getIdentifier()
Get unique Asset identifier- Returns:
- Asset identifier as String or null if Asset has no unique identifier
-
setRendition
Rendition setRendition(java.lang.String name, java.io.InputStream is, java.util.Map<java.lang.String,java.lang.Object> map)
Create or update theRendition
. If a rendition with the givenname
already exists, it will be replaced. Actual creation of rendition is delegated to theRenditionHandler
.- Parameters:
name
- to be used for this renditionis
- InputStream to create this rendition or null if stream is not required by the RenditionHandlermap
- to be used by the rendition handler. If the map containsRenditionHandler.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 setjava.lang.NullPointerException
- if the given map is null
-
setRendition
Rendition setRendition(java.lang.String name, Binary binary, java.util.Map<java.lang.String,java.lang.Object> map)
Create or update theRendition
. If a rendition with the givenname
already exists, it will be replaced. Not like thesetRendition(String, InputStream, Map)
, this method does not delegate to anyRenditionHandler
.- Parameters:
name
- to be used for this renditionbinary
- binary to create this rendition or null if binary is not required by the RenditionHandlermap
- to be used for passing through mimeType etc. properties for the rendition. Not like thesetRendition(String, InputStream, Map)
, this method does not delegate to anyRenditionHandler
. so any renditionHandlerID passed through the map does not work here- Returns:
- newly created or updated rendition
- Throws:
AssetException
- if new rendition cannot be setjava.lang.NullPointerException
- if the given map is null
-
removeRendition
void removeRendition(java.lang.String name)
RemoveRendition
with the given name.- Parameters:
name
- of the Rendition- Throws:
AssetException
- if Rendition cannot be removed
-
-