Package com.adobe.granite.asset.api
Interface Asset
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:
-
Field Summary
Fields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING -
Method Summary
Modifier and TypeMethodDescriptionaddRelation(String name, String assetPath) adds a new relation to this Asset.Adds a new relation to this Asset with additional propertiesReturns the metadata of this Asset.Get unique Asset identifiergetRendition(String name) Returns a namedRenditionif available.listRelated(String name) Get all related Asset with the given name.Iterator<? extends AssetRelation> listRelations(String name) Get asset relations for a given relation name.Returns an iterator for allRenditions of this asset.voidorderRelationBefore(String name, String srcAssetPath, String destAssetPath) This method inserts the related asset atsrcAssetPathinto the related asset list at the position immediately before the related asset atdestAssetPath.voidremoveRelation(String name) Removes all relations for the given name.voidremoveRelation(String name, String assetPath) Removes Asset relation.voidremoveRendition(String name) RemoveRenditionwith the given name.voidsetRelation(String name, String assetPath) Deprecated.setRendition(String name, InputStream is, Map<String, Object> map) Create or update theRendition.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 Details
-
getRendition
Returns a namedRenditionif 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
Returns an iterator for allRenditions of this asset.- Returns:
- The Iterator of renditions or an empty iterator if no renditions has been created.
-
listRelated
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
Get asset relations for a given relation name.- Parameters:
name- Name of the relation- Returns:
- Iterator of
AssetRelationor 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
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.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
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
This method inserts the related asset atsrcAssetPathinto the related asset list at the position immediately before the related asset atdestAssetPath. To insert the related asset into last position,destAssetPathcan 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 thesrcAssetPathwill 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
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
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
Create or update theRendition. If a rendition with the givennamealready 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 setNullPointerException- if the given map is null
-
setRendition
Create or update theRendition. If a rendition with the givennamealready 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 setNullPointerException- if the given map is null
-
removeRendition
RemoveRenditionwith the given name.- Parameters:
name- of the Rendition- Throws:
AssetException- if Rendition cannot be removed
-
addRelation(String, String)