Interface MediaService
-
- All Known Implementing Classes:
DefaultMediaService
public interface MediaService
Provides business functionality for media handling including search methods for medias, folder, formats.- Since:
- 4.0
- Spring Bean ID:
- mediaService
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addVersionStreamForMedia(MediaModel media, java.lang.String versionId, java.io.InputStream data)
Adds the additional version of data as stream for given base media.void
addVersionStreamForMedia(MediaModel media, java.lang.String mimeType, java.lang.String versionId, java.io.InputStream data)
Adds the additional version of data as stream for given base mediavoid
copyData(MediaModel fromMedia, MediaModel toMedia)
Copies data from a media to another media by linking the data (both medias will point to same data file).void
duplicateData(MediaModel fromMedia, MediaModel toMedia)
Copies data from a media to another media by duplicating the data (both medias will point to different data file).byte[]
getDataFromMedia(MediaModel media)
Returns the stored file of given media as raw data array.java.io.DataInputStream
getDataStreamFromMedia(MediaModel media)
Deprecated.since ages - please usegetStreamFromMedia(MediaModel)
insteadjava.util.Collection<java.io.File>
getFiles(MediaModel mediaModel)
Deprecated.since ages - Operating on files is no more supported.MediaFolderModel
getFolder(java.lang.String qualifier)
Gets the folder identified unique by given qualifier.MediaFormatModel
getFormat(java.lang.String qualifier)
Gets the format identified unique by given qualifier.MediaModel
getMedia(CatalogVersionModel catalogVersion, java.lang.String code)
Gets the media identified unique by given code and catalog version.MediaModel
getMedia(java.lang.String code)
Gets the media identified unique by given code.MediaModel
getMediaByContext(MediaModel media, MediaContextModel context)
Gets related media for given media determined by target format of given context.MediaModel
getMediaByFormat(MediaContainerModel container, MediaFormatModel format)
Gets media in specified format related to given media container.MediaModel
getMediaByFormat(MediaModel media, MediaFormatModel format)
Gets media in specified format related to given media.java.util.Collection<MediaModel>
getMediaWithSameDataReference(MediaModel media)
Returns a collection of MediaModel objects that point to the same physical file.MediaFolderModel
getRootFolder()
Gets the root media folder.java.io.InputStream
getStreamForMediaVersion(MediaModel media, java.lang.String versionId)
Gets the stream for media version.java.io.InputStream
getStreamFromMedia(MediaModel media)
Returns the stored file of given media as stream.java.lang.String
getUrlForMedia(MediaModel media)
Returns URL for to given media.java.lang.String
getUrlForMediaVersion(MediaModel media, java.lang.String versionId)
Gets the URL for media version rendered by configured URL strategy.boolean
hasData(MediaModel media)
Returns information whether given media has binary data.void
moveData(MediaModel fromMedia, MediaModel toMedia)
Moves a media data to another media.void
moveMediaToFolder(MediaModel media, MediaFolderModel targetFolder)
Changes the folder of media to given new folder and move the related media data to this folder.void
removeDataFromMedia(MediaModel media)
Removes binary data from provided media.boolean
removeDataFromMediaQuietly(MediaModel media)
Removes binary data from provided media without throwing exception.void
removeVersionForMedia(MediaModel media, java.lang.String versionId)
Removes the version of data for media.void
setDataForMedia(MediaModel media, byte[] data)
Sets given raw data to media by writing content of given stream to a new data file.void
setDataStreamForMedia(MediaModel media, java.io.DataInputStream data)
Deprecated.since ages - please usesetStreamForMedia(MediaModel, InputStream)
insteadvoid
setFolderForMedia(MediaModel media, MediaFolderModel targetFolder)
Deprecated.void
setStreamForMedia(MediaModel media, java.io.InputStream data)
Sets given data to media by writing content of given stream to a new data file.void
setStreamForMedia(MediaModel media, java.io.InputStream data, java.lang.String originalName, java.lang.String mimeType)
Sets given data to media by writing content of given stream to a new data file.void
setStreamForMedia(MediaModel media, java.io.InputStream data, java.lang.String originalName, java.lang.String mimeType, MediaFolderModel folder)
Sets given data to media by writing content of given stream to a new data file.void
setUrlForMedia(MediaModel media, java.lang.String url)
Sets the external URL for the media.
-
-
-
Method Detail
-
hasData
boolean hasData(MediaModel media)
Returns information whether given media has binary data.- Parameters:
media
- media to examine- Returns:
- true if media has binary data, false otherwise
-
getDataStreamFromMedia
@Deprecated java.io.DataInputStream getDataStreamFromMedia(MediaModel media) throws NoDataAvailableException
Deprecated.since ages - please usegetStreamFromMedia(MediaModel)
insteadReturns the stored file of given media as stream. This can only succeed if once data was set before.- Parameters:
media
- media for which data is requested- Returns:
- stream to data of media
- Throws:
NoDataAvailableException
- if no data was set before
-
getStreamFromMedia
java.io.InputStream getStreamFromMedia(MediaModel media) throws NoDataAvailableException, java.lang.IllegalArgumentException
Returns the stored file of given media as stream. This can only succeed if once data was set before.- Parameters:
media
- media for which data is requested- Returns:
- stream to data of media
- Throws:
NoDataAvailableException
- if no data was set before or if underlying data is corruptedjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
getDataFromMedia
byte[] getDataFromMedia(MediaModel media) throws NoDataAvailableException
Returns the stored file of given media as raw data array. This can only succeed if once data was set before.- Parameters:
media
- media for which data is requested- Returns:
- raw data of media
- Throws:
NoDataAvailableException
- if no data was set before or if underlying data is corrupted
-
setDataForMedia
void setDataForMedia(MediaModel media, byte[] data) throws MediaIOException, java.lang.IllegalArgumentException
Sets given raw data to media by writing content of given stream to a new data file.- Parameters:
media
- media for which data will be setdata
- raw data to set- Throws:
MediaIOException
- if IO problems has occurredjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
setDataStreamForMedia
@Deprecated void setDataStreamForMedia(MediaModel media, java.io.DataInputStream data)
Deprecated.since ages - please usesetStreamForMedia(MediaModel, InputStream)
insteadSets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.- Parameters:
media
- media for which data will be setdata
- data to set- Throws:
MediaIOException
- if IO problems has occurred
-
setStreamForMedia
void setStreamForMedia(MediaModel media, java.io.InputStream data) throws MediaIOException, java.lang.IllegalArgumentException
Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.- Parameters:
media
- media for which data will be setdata
- data to set- Throws:
MediaIOException
- if IO problems has occurredjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
removeDataFromMediaQuietly
boolean removeDataFromMediaQuietly(MediaModel media)
Removes binary data from provided media without throwing exception.- Parameters:
media
-- Returns:
- true when removal operation has succeeded, false otherwise.
-
removeDataFromMedia
void removeDataFromMedia(MediaModel media)
Removes binary data from provided media. If data cannot be removed MediaRemovalException is thrown.- Parameters:
media
- media from which data will be removed- Throws:
MediaRemovalException
-
addVersionStreamForMedia
void addVersionStreamForMedia(MediaModel media, java.lang.String versionId, java.io.InputStream data)
Adds the additional version of data as stream for given base media. Mime type will be used from base media.- Parameters:
media
- the base mediaversionId
- the unique version id of data (like format name)data
- the data stream
-
addVersionStreamForMedia
void addVersionStreamForMedia(MediaModel media, java.lang.String mimeType, java.lang.String versionId, java.io.InputStream data)
Adds the additional version of data as stream for given base media- Parameters:
media
- the base mediamimeType
- the custom mime typeversionId
- the unique version id of data (like format name)data
- the data stream
-
removeVersionForMedia
void removeVersionForMedia(MediaModel media, java.lang.String versionId)
Removes the version of data for media.- Parameters:
media
- the base mediaversionId
- the unique version id of data (like format name)
-
getUrlForMediaVersion
java.lang.String getUrlForMediaVersion(MediaModel media, java.lang.String versionId)
Gets the URL for media version rendered by configured URL strategy.- Parameters:
media
- the base mediaversionId
- the unique version id of data (like format name)- Returns:
- the URL for media version
-
getStreamForMediaVersion
java.io.InputStream getStreamForMediaVersion(MediaModel media, java.lang.String versionId)
Gets the stream for media version.- Parameters:
media
- the base mediaversionId
- the unique version id of data (like format name)- Returns:
- the stream for media version
-
setStreamForMedia
void setStreamForMedia(MediaModel media, java.io.InputStream data, java.lang.String originalName, java.lang.String mimeType) throws MediaIOException, java.lang.IllegalArgumentException
Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.- Parameters:
media
- media for which data will be setdata
- data to setoriginalName
- The file name that will be set to the media modelmimeType
- MIME type of the media that will be set to the media model- Throws:
MediaIOException
- if IO problems has occurredjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
setStreamForMedia
void setStreamForMedia(MediaModel media, java.io.InputStream data, java.lang.String originalName, java.lang.String mimeType, MediaFolderModel folder) throws MediaIOException, java.lang.IllegalArgumentException
Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.- Parameters:
media
- media for which data will be setdata
- data to setoriginalName
- The file name that will be set to the media modelmimeType
- MIME type of the media that will be set to the media modelfolder
- The folder where media will be stored- Throws:
java.lang.IllegalArgumentException
- the illegal argument exception if any argument is nullMediaStoreException
- if any media store problems occursjava.lang.IllegalStateException
- if media model is newMediaIOException
-
setUrlForMedia
void setUrlForMedia(MediaModel media, java.lang.String url)
Sets the external URL for the media. This method also automatically determines mime from URL as well as tries to set size if URL points to the file in classpath and contains specia "fromjar" flag.- Parameters:
media
- media for which the url will be seturl
- the url
-
getUrlForMedia
java.lang.String getUrlForMedia(MediaModel media)
Returns URL for to given media. Depending on the state of the media the URL can be URL which points to the binary data in underlying Media Storage or direct standard URL to the media in the network.- Parameters:
media
- media for which the url will be obtained- Returns:
- url
-
setFolderForMedia
@Deprecated void setFolderForMedia(MediaModel media, MediaFolderModel targetFolder) throws MediaIOException, java.lang.IllegalArgumentException
Deprecated.Changes the folder of media to given new folder and move the related media data to this folder.- Parameters:
media
- media for which the folder will be changedtargetFolder
- folder where the data has to be moved to- Throws:
MediaIOException
- if IO problems has occurredjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
moveMediaToFolder
void moveMediaToFolder(MediaModel media, MediaFolderModel targetFolder) throws MediaIOException, java.lang.IllegalArgumentException
Changes the folder of media to given new folder and move the related media data to this folder. If old media data is referenced by another media object it will be preserved in old location.This method calls
ModelService.save(Object)
method.- Parameters:
media
- media for which the folder will be changedtargetFolder
- folder where the data has to be moved to- Throws:
MediaIOException
- if IO problems has occurredjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
moveData
void moveData(MediaModel fromMedia, MediaModel toMedia) throws MediaIOException, java.lang.IllegalArgumentException
Moves a media data to another media. After this method, this media has no data anymore. Other medias linking same data will be still consistent.This method calls
ModelService.save(Object)
method.- Parameters:
fromMedia
- source media to move data fromtoMedia
- target media to move data to- Throws:
MediaIOException
- in case of unexpected errors while move operationjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
copyData
void copyData(MediaModel fromMedia, MediaModel toMedia) throws MediaIOException, java.lang.IllegalArgumentException
Copies data from a media to another media by linking the data (both medias will point to same data file). This method is optimized for reusing data files without actually copying them. See alsoduplicateData(MediaModel, MediaModel)
which copies by duplicating the data file. In case the source media does not hold own data but points to a URL this media simply takes the URL - no real data is copied.This method calls
ModelService.save(Object)
method.- Parameters:
fromMedia
- source media to copy data fromtoMedia
- target media to copy data to- Throws:
MediaIOException
- in case of unexpected errors while move operationjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
duplicateData
void duplicateData(MediaModel fromMedia, MediaModel toMedia) throws MediaIOException, java.lang.IllegalArgumentException
Copies data from a media to another media by duplicating the data (both medias will point to different data file). See alsocopyData(MediaModel, MediaModel)
which only creates a link. In case the source media does not hold own data but points to a URL this media simply takes the URL - no real data is copied.This method calls
ModelService.save(Object)
method.- Parameters:
fromMedia
- source media to copy data fromtoMedia
- target media to copy data to- Throws:
MediaIOException
- in case of unexpected errors while move operationjava.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
getMediaByContext
MediaModel getMediaByContext(MediaModel media, MediaContextModel context) throws ModelNotFoundException, java.lang.IllegalArgumentException
Gets related media for given media determined by target format of given context. Determines the format of the specified media and uses the specified MediaContext to determine the target format. Than it simply returns the specified media in this target format using the assigned container.- Parameters:
media
- media for which the related media in specific format is neededcontext
- context which defines the target format- Returns:
- media in format specified by context
- Throws:
ModelNotFoundException
- if no container is assigned (MediaModel.getMediaContainer()
returnsnull
) or the assignedMediaContainerModel
does not provide a media in given format.java.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
getMediaByFormat
MediaModel getMediaByFormat(MediaModel media, MediaFormatModel format) throws ModelNotFoundException, java.lang.IllegalArgumentException
Gets media in specified format related to given media.- Parameters:
media
- media for which the related media in specific format is neededformat
- format the desired media has to have- Returns:
- media in specified format or
null
if no corresponding media in specified format is available - Throws:
ModelNotFoundException
- if no container is assigned (MediaModel.getMediaContainer()
returnsnull
) or the assignedMediaContainerModel
does not provide a media in given format.java.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
getMediaByFormat
MediaModel getMediaByFormat(MediaContainerModel container, MediaFormatModel format) throws ModelNotFoundException, java.lang.IllegalArgumentException
Gets media in specified format related to given media container.- Parameters:
container
- container for which the related media in specific format is neededformat
- format the desired media has to have- Returns:
- MediaModel in specified format or
null
if no corresponding media in specified format is available - Throws:
ModelNotFoundException
- if container isnull
or the assignedMediaContainerModel
does not provide a media in given format.java.lang.IllegalArgumentException
- the illegal argument exception if any argument is null
-
getMedia
MediaModel getMedia(CatalogVersionModel catalogVersion, java.lang.String code) throws UnknownIdentifierException, AmbiguousIdentifierException
Gets the media identified unique by given code and catalog version.- Parameters:
catalogVersion
- version used for searchingcode
- code used for searching- Returns:
- media matching given code and version
- Throws:
UnknownIdentifierException
- in case no media can be foundAmbiguousIdentifierException
- in case more than one media was found (code and version are not unique)java.lang.IllegalArgumentException
- if any of the givenqualifier
orcatalogVersion
are null
-
getMedia
MediaModel getMedia(java.lang.String code) throws UnknownIdentifierException, AmbiguousIdentifierException
Gets the media identified unique by given code.- Parameters:
code
- code used for searching- Returns:
- media matching given code
- Throws:
UnknownIdentifierException
- in case no media can be foundAmbiguousIdentifierException
- in case more than one media was found (code is not unique)java.lang.IllegalArgumentException
- if givenqualifier
is null
-
getFiles
@Deprecated java.util.Collection<java.io.File> getFiles(MediaModel mediaModel) throws java.lang.IllegalArgumentException, NoDataAvailableException
Deprecated.since ages - Operating on files is no more supported. Use InputStream related methods.Gets file of given media (from all media replication directories) as collection ofFile
's.- Parameters:
mediaModel
- mediaModel used for searching- Returns:
- Collection of files based on the given mediaModel
- Throws:
java.lang.IllegalArgumentException
- the illegal argument exception if any argument is nullNoDataAvailableException
- if no file was found
-
getFolder
MediaFolderModel getFolder(java.lang.String qualifier) throws UnknownIdentifierException, AmbiguousIdentifierException
Gets the folder identified unique by given qualifier.- Parameters:
qualifier
- qualifier used for searching the folder- Returns:
- folder matching given qualifier
- Throws:
UnknownIdentifierException
- in case no folder can be foundAmbiguousIdentifierException
- in case more than one folder is foundjava.lang.IllegalArgumentException
- if givenqualifier
is null
-
getFormat
MediaFormatModel getFormat(java.lang.String qualifier) throws UnknownIdentifierException, AmbiguousIdentifierException
Gets the format identified unique by given qualifier.- Parameters:
qualifier
- qualifier used for searching the format- Returns:
- format matching given qualifier
- Throws:
UnknownIdentifierException
- in case no format can be foundAmbiguousIdentifierException
- in case more than one format is foundjava.lang.IllegalArgumentException
- if givenqualifier
is null
-
getRootFolder
MediaFolderModel getRootFolder() throws ModelNotFoundException
Gets the root media folder. This folder is created at createEssentialData of core extension and should be always existent. If not existent aModelNotFoundException
is thrown. The root folder is the default folder for a media.- Returns:
- root folder
- Throws:
ModelNotFoundException
- in case no root folder is available
-
getMediaWithSameDataReference
java.util.Collection<MediaModel> getMediaWithSameDataReference(MediaModel media)
Returns a collection of MediaModel objects that point to the same physical file.- Parameters:
media
- media used for search- Returns:
- collection of medias referencing the same file
-
-