public class Asset
extends java.lang.Object
implements java.lang.AutoCloseable
Asset
object allows you to access an individual asset. This is only possible if the asset is accessible.AssetReference
Modifier and Type | Class and Description |
---|---|
static class |
Asset.VersionInformation
This class bundles version information for an asset.
|
Constructor and Description |
---|
Asset(CumulusSession session,
java.io.File fileOrFolder)
Creates a new
Asset object from the given file or folder object. |
Asset(CumulusSession session,
java.io.File fileOrFolder,
java.lang.String assetHandlingSet)
Creates a new
Asset object from the given file or folder object, using a specific asset handling set. |
Asset(CumulusSession session,
java.lang.String sXML)
Creates a new
Asset object from the given AssetReference in XML format. |
Asset(CumulusSession session,
java.lang.String sXML,
java.lang.String assetHandlingSet)
Creates a new
Asset object from the given AssetReference in XML format, using a specific asset handling set. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this asset and releases all occupied resources.
|
void |
closeCachedDataStreams()
Closes the cached data streams to release the occupied resources.
|
Asset |
convert(Asset destinationContainer,
java.lang.String parameters,
GUID guid)
Converts the asset content and creates a new asset in a container asset.
|
java.io.File |
convert(java.io.File dstFolder,
java.lang.String params,
GUID guid)
Converts the asset content and creates a new file.
|
void |
copyFrom(Asset srcAsset)
Overwrites this asset with the given asset.
|
Asset |
createSubAsset(Asset srcAsset)
Creates a sub-asset (for example a file in a folder) from the given asset.
|
Asset |
createSubAsset(java.lang.String sName,
java.lang.String sFileNameExtension,
java.lang.String sMacFileType,
java.lang.String sMacFileCreator,
java.util.Date creationDate,
java.util.Date modificationDate,
java.io.InputStream dataFork,
java.io.InputStream rsrcFork)
Create an asset (e.g.
|
Asset |
createSubContainerAsset(java.lang.String name,
java.util.Date creationDate,
java.util.Date modificationDate)
Create a container asset (e.g.
|
void |
deleteAsset()
Deletes the asset itself.
|
java.io.File |
getAsFile()
Returns the asset as a
File object if possible. |
java.lang.String |
getAsPathOrXMLAssetReference()
Get a string referencing this asset.
|
Asset |
getContainer()
Returns the asset's container asset.
|
java.util.Date |
getCreationDate()
Returns the asset's creation date.
|
CumulusSession |
getCumulusSession()
Returns the current
CumulusSession object. |
java.awt.Dimension |
getDimensions()
Returns the width and height of the asset in pixels.
|
java.lang.String |
getDownloadURL(int urlTimeoutInSeconds,
boolean forDownload)
Returns a URL that can be used to download the asset.
|
java.lang.String |
getFileFormatIdentifier()
Returns the file format identifier of the asset.
|
java.lang.String |
getFileNameExtension()
Returns the name extension of this asset in its container asset.
|
java.lang.String |
getFilePath()
Get the path for this asset.
|
Asset |
getHostAsset()
Returns the host asset for this contained asset.
|
java.lang.String |
getMacFileCreator()
Returns the Mac OS file creator code of this asset.
|
java.lang.String |
getMacFileType()
Returns the Mac OS file type of this asset.
|
java.util.Date |
getModificationDate()
Returns the asset's modification date.
|
java.lang.String |
getNameInContainer()
Returns the name of this asset in its container asset.
|
int |
getNumberOfPages()
Returns the number of pages for this asset.
|
java.lang.String |
getOriginalName()
Returns the original asset name.
|
Asset |
getSubAsset(java.lang.String name)
Returns a sub-asset by name.
|
AssetCollection |
getSubAssetsCollection()
Returns a
AssetCollection of all sub assets. |
Asset.VersionInformation |
getVersionInformation()
Get the version information for the selected version of this asset.
|
int[] |
getVersionNumbers()
Returns a list of version numbers for this asset.
|
boolean |
hasDataStream()
Returns whether the asset has a data stream.
|
boolean |
hasSubAssets()
Returns true if this asset has sub assets.
|
boolean |
isSameAsset(Asset anotherAsset)
Return whether this asset is the same as another asset object.
|
AssetReference |
newAssetReference(java.lang.String assetHandlingSet)
Create a new asset reference for this asset.
|
InputDataStream |
openInputDataStream()
Returns the asset's data fork for reading.
|
InputDataStream |
openInputRsrcStream()
Returns the asset's resource stream for reading.
|
OutputDataStream |
openOutputDataStream()
Returns the asset's data fork for writing.
|
OutputDataStream |
openOutputRsrcStream()
Returns the asset's resource stream for writing.
|
Asset |
redirect(java.lang.String parameters,
GUID guid)
Redirects the asset content to another existing asset.
|
void |
rename(java.lang.String newName)
Renames the name of the asset to the new name.
|
void |
rename(java.lang.String newName,
boolean addNumberIfExists)
Renames the name of the asset to the new name.
|
void |
setVersionInformation(java.util.Date date,
java.lang.String user,
java.lang.String comment) |
void |
showInContainer()
Show this asset in it's container.
|
boolean |
supportsVersioning()
Return whether this asset supports versioning, meaning that is allows to check it out and check a new version back in.
|
java.lang.String |
toString()
Returns the name of this asset in its container asset.
|
int |
useVersion(int versionNumber)
Uses a specific version of the asset and return the version that was previously used.
|
public Asset(CumulusSession session, java.lang.String sXML) throws UnresolvableAssetReferenceException
Asset
object from the given AssetReference
in XML format.session
- the CumulusSession
to which this object belongs.sXML
- an asset reference in XML format.UnresolvableAssetReferenceException
- in case of an unresolvable AssetReferenceAssetReference.getAsXML()
public Asset(CumulusSession session, java.lang.String sXML, java.lang.String assetHandlingSet) throws UnresolvableAssetReferenceException, InvalidArgumentException
Asset
object from the given AssetReference
in XML format, using a specific asset handling set.session
- the CumulusSession
to which this object belongs.sXML
- an asset reference in XML format.assetHandlingSet
- the asset handling set to use for creating this asset or an empty String
to use the default asset handling set.UnresolvableAssetReferenceException
- in case of an unresolvable AssetReferenceInvalidArgumentException
- in case of an invalid argumentAssetReference.getAsXML()
public Asset(CumulusSession session, java.io.File fileOrFolder) throws java.io.FileNotFoundException
Asset
object from the given file or folder object.session
- the CumulusSession
to which this object belongs.fileOrFolder
- a local file or a folder.java.io.FileNotFoundException
- if the file or folder does not exists.public Asset(CumulusSession session, java.io.File fileOrFolder, java.lang.String assetHandlingSet) throws java.io.FileNotFoundException, InvalidArgumentException
Asset
object from the given file or folder object, using a specific asset handling set.session
- the CumulusSession
to which this object belongs.fileOrFolder
- a local file or a folder.assetHandlingSet
- the asset handling set to use for creating this asset or an empty String
to use the default asset handling set.java.io.FileNotFoundException
- if the file or folder does not exists.InvalidArgumentException
- in case of an invalid argumentpublic CumulusSession getCumulusSession()
CumulusSession
object.CumulusSession
objectpublic AssetReference newAssetReference(java.lang.String assetHandlingSet) throws InvalidArgumentException
assetHandlingSet
- The name of the asset handling set to use.InvalidArgumentException
- in case of an non-existing asset handling setpublic java.lang.String getAsPathOrXMLAssetReference()
public void copyFrom(Asset srcAsset) throws CumulusException
AssetStorage
module, this will also copy all other properties of the asset, except
for the name.srcAsset
- the source asset access object to copy.CumulusException
- on errorspublic Asset convert(Asset destinationContainer, java.lang.String parameters, GUID guid) throws CumulusException
GUID.UID_AS_PIXEL_CONVERTER
GUID.UID_AS_ZIP_PROCESSOR
GUID.UID_AS_HELIOS_PROCESSOR
GUID.UID_AS_2PDF_PROCESSOR
//Convert BMP to JPEG using the Pixel Asset Converter Asset myAsset = myCollection.getRecords().getRecord("myImage.bmp").getAssetReference().getAsset(); Asset myFolder = new Asset(myAsset.getCumulusSession(), new File("myFolder")); Asset newAsset = myAsset.convert(myFolder, "Format=JPEG JPEGQuality=5", GUID.UID_AS_PIXEL_CONVERTER);
destinationContainer
- the destination container asset where to create the converted asset.parameters
- conversion parameters specific to the conversion module (see Conversion Parameters).guid
- the Class ID of the converter module used for the conversion.CumulusException
- if the asset cannot be converted.public Asset redirect(java.lang.String parameters, GUID guid) throws CumulusException
parameters
- parameters specific to the AssetStorage
module (see Redirection
Parameters).guid
- the Class ID of the module used for the redirection.CumulusException
- if the asset cannot be redirected.public void rename(java.lang.String newName) throws InvalidArgumentException, CumulusException
newName
- the new asset nameCumulusException
- if the asset cannot be renamed.InvalidArgumentException
- if an asset of that name already exists.public void rename(java.lang.String newName, boolean addNumberIfExists) throws InvalidArgumentException, CumulusException
newName
- the new asset nameaddNumberIfExists
- appends a number behind the asset name (before the extension) if the asset existsCumulusException
- if the asset cannot be renamed.InvalidArgumentException
- if an asset of that name already exists and the parameter addNumberIfExists
is false
.public void deleteAsset() throws PermissionDeniedException, CumulusException
PermissionDeniedException
- If the user does not have the necessary permission to delete the asset.CumulusException
- on other errors.public Asset createSubAsset(Asset srcAsset) throws PermissionDeniedException, CumulusException
getNameInContainer()
to get the new asset's name. The new asset will be an exact copy of the given source asset.srcAsset
- the source asset.PermissionDeniedException
- If the user does not have the necessary permission to create the asset.CumulusException
- on other errors.copyFrom(com.canto.cumulus.Asset)
public Asset createSubAsset(java.lang.String sName, java.lang.String sFileNameExtension, java.lang.String sMacFileType, java.lang.String sMacFileCreator, java.util.Date creationDate, java.util.Date modificationDate, java.io.InputStream dataFork, java.io.InputStream rsrcFork) throws PermissionDeniedException, CumulusException
sName
- The name of the asset to create. Pass null
to let the asset storage choose a name if supported.sFileNameExtension
- The file name extension for the new asset. Pass null
if you do not want to explicitly specify an extension.sMacFileType
- The Mac OS file type (4 character string) for the asset. Pass null
if you do not want to explicitly specify a Mac OS
file type.sMacFileCreator
- The Mac OS file creator code (4 character string) for the asset. Pass null
if you do not want to explicitly specify a
Mac OS file creator code.creationDate
- The desired creation date. Pass null
to use the current date and time.modificationDate
- The desired creation date. Pass null
to use the current date and time.dataFork
- The contents of the asset's data fork. If you specify null
then the asset is not filled with data.rsrcFork
- The contents of the asset's resource fork. If you specify null
then the asset will not get a resource fork.PermissionDeniedException
- If the user does not have the necessary permission to create the asset.CumulusException
- on other errors.public Asset createSubContainerAsset(java.lang.String name, java.util.Date creationDate, java.util.Date modificationDate) throws PermissionDeniedException, CumulusException
name
- The name of the container to create.creationDate
- The desired creation date. Pass null
to use the current date and time.modificationDate
- The desired creation date. Pass null
to use the current date and time.PermissionDeniedException
- If the user does not have the necessary permission to create the container asset.CumulusException
- on other errors.public boolean isSameAsset(Asset anotherAsset)
anotherAsset
- The other asset to compare.true
if the other asset is the same, false
otherwise.public java.lang.String getFilePath() throws CumulusException
CumulusException
- if the asset is not a file.public java.io.File getAsFile()
File
object if possible.File
object for the asset or null if this is not an asset resolvable to a single File
.public java.lang.String getNameInContainer()
public java.lang.String getOriginalName()
public java.lang.String getFileNameExtension()
public Asset getContainer() throws CumulusException
null
if this asset is already the top-level asset.CumulusException
- on errorpublic boolean supportsVersioning()
AssetReference.supportsVersioning()
.true
if this asset supports versioning.public int[] getVersionNumbers()
null
if the asset does not support versioning.public int useVersion(int versionNumber)
Asset
object is created, the used version number is
the latest version. All other methods of the Asset
object now work on the specified version instead of the latest version. This method has no
effect and returns 0
if the asset does not support versioning.versionNumber
- the version number to use. This must be one of the version numbers returned by getVersionNumbers()
. Pass a version
Number of 0<code> to use the latest version of the asset.
getVersionNumbers()
public Asset.VersionInformation getVersionInformation()
useVersion(int)
prior to this method. If you do not call useVersion(int)
this method returns the latest version's information.getVersionNumbers()
,
useVersion(int)
,
supportsVersioning()
public void setVersionInformation(java.util.Date date, java.lang.String user, java.lang.String comment)
date
- Modification date of the currently set versionuser
- Modifying user of the currently set versioncomment
- Comment text of the currently set versionpublic java.lang.String getMacFileType()
String
if the asset has no Mac OS file type associated.public java.lang.String getMacFileCreator()
String
if the asset has no Mac OS file creator associated.public java.util.Date getCreationDate()
public java.util.Date getModificationDate()
public boolean hasDataStream()
true
if the asset has a data stream; false
otherwise.public InputDataStream openInputDataStream()
public InputDataStream openInputRsrcStream()
public OutputDataStream openOutputDataStream()
public OutputDataStream openOutputRsrcStream()
public Asset getHostAsset() throws CumulusException
null
otherwise.CumulusException
- in case of an errorpublic void showInContainer()
public java.lang.String getDownloadURL(int urlTimeoutInSeconds, boolean forDownload)
urlTimeoutInSeconds
- The timeout of the URL. It's the time in which the download must be started.forDownload
- Specifies whether the URL is used to download the file or to show the file in browser.null
otherwise.CumulusException
- in case of an errorpublic int getNumberOfPages()
CumulusException
- in case of an errorpublic java.awt.Dimension getDimensions()
CumulusException
- in case of an errorpublic java.lang.String getFileFormatIdentifier()
CumulusException
- in case of an errorpublic void close()
Asset
object cannot be used anymore.close
in interface java.lang.AutoCloseable
public void closeCachedDataStreams()
public java.lang.String toString()
toString
in class java.lang.Object
getNameInContainer()
public Asset getSubAsset(java.lang.String name) throws CumulusException
name
- name of the sub asset to getCumulusException
- if the sub-asset cannot be found.public AssetCollection getSubAssetsCollection()
AssetCollection
of all sub assets.AssetCollection
of all sub assetshasSubAssets()
public boolean hasSubAssets()
public java.io.File convert(java.io.File dstFolder, java.lang.String params, GUID guid) throws CumulusException, java.io.FileNotFoundException
GUID.UID_AS_PIXEL_CONVERTER
GUID.UID_AS_ZIP_PROCESSOR
GUID.UID_AS_HELIOS_PROCESSOR
GUID.UID_AS_2PDF_PROCESSOR
//Convert BMP to JPEG using the Pixel Asset Converter Asset myAsset = myCollection.getRecords().getRecord("myImage.bmp").getAssetReference().getAsset(); Asset newAsset = myAsset.convert(new File("myFolder"), "Format=JPEG JPEGQuality=5", GUID.UID_AS_PIXEL_CONVERTER);
dstFolder
- the destination folder where to create the converted asset.params
- conversion parameters specific to the conversion module (see Conversion
Parameters).guid
- the Class ID of the converter module used for the conversion.CumulusException
- if the asset cannot be converted.java.io.FileNotFoundException
- if the destination folder does not exist.www.canto.com
Canto, the Canto logo, the Cumulus logo, and Cumulus are registered trademarks of Canto GmbH, registered in the U.S. and other countries.