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
Modifier and TypeMethodDescriptionvoidaddVersionStreamForMedia(MediaModel media, String versionId, InputStream data) Adds the additional version of data as stream for given base media.voidaddVersionStreamForMedia(MediaModel media, String mimeType, String versionId, InputStream data) Adds the additional version of data as stream for given base mediavoidcopyData(MediaModel fromMedia, MediaModel toMedia) Copies data from a media to another media by linking the data (both medias will point to same data file).voidduplicateData(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.getDataStreamFromMedia(MediaModel media) Deprecated, for removal: This API element is subject to removal in a future version.getFiles(MediaModel mediaModel) Deprecated, for removal: This API element is subject to removal in a future version.since ages - Operating on files is no more supported.Gets the folder identified unique by given qualifier.Gets the format identified unique by given qualifier.getMedia(CatalogVersionModel catalogVersion, String code) Gets the media identified unique by given code and catalog version.Gets the media identified unique by given code.getMediaByContext(MediaModel media, MediaContextModel context) Gets related media for given media determined by target format of given context.getMediaByFormat(MediaContainerModel container, MediaFormatModel format) Gets media in specified format related to given media container.getMediaByFormat(MediaModel media, MediaFormatModel format) Gets media in specified format related to given media.Returns a collection of MediaModel objects that point to the same physical file.Gets the root media folder.getStreamForMediaVersion(MediaModel media, String versionId) Gets the stream for media version.getStreamFromMedia(MediaModel media) Returns the stored file of given media as stream.getUrlForMedia(MediaModel media) Returns URL for to given media.getUrlForMediaVersion(MediaModel media, String versionId) Gets the URL for media version rendered by configured URL strategy.booleanhasData(MediaModel media) Returns information whether given media has binary data.voidmoveData(MediaModel fromMedia, MediaModel toMedia) Moves a media data to another media.voidmoveMediaToFolder(MediaModel media, MediaFolderModel targetFolder) Changes the folder of media to given new folder and move the related media data to this folder.voidremoveDataFromMedia(MediaModel media) Removes binary data from provided media.booleanRemoves binary data from provided media without throwing exception.voidremoveVersionForMedia(MediaModel media, String versionId) Removes the version of data for media.voidsetDataForMedia(MediaModel media, byte[] data) Sets given raw data to media by writing content of given stream to a new data file.voidsetDataStreamForMedia(MediaModel media, DataInputStream data) Deprecated, for removal: This API element is subject to removal in a future version.since ages - please usesetStreamForMedia(MediaModel, InputStream)insteadvoidsetFolderForMedia(MediaModel media, MediaFolderModel targetFolder) Deprecated, for removal: This API element is subject to removal in a future version.voidsetStreamForMedia(MediaModel media, InputStream data) Sets given data to media by writing content of given stream to a new data file.voidsetStreamForMedia(MediaModel media, InputStream data, String originalName, String mimeType) Sets given data to media by writing content of given stream to a new data file.voidsetStreamForMedia(MediaModel media, InputStream data, String originalName, String mimeType, MediaFolderModel folder) Sets given data to media by writing content of given stream to a new data file.voidsetUrlForMedia(MediaModel media, String url) Sets the external URL for the media.
-
Method Details
-
hasData
Returns information whether given media has binary data.- Parameters:
media- media to examine- Returns:
- true if media has binary data, false otherwise
-
getDataStreamFromMedia
@Deprecated(since="ages", forRemoval=true) DataInputStream getDataStreamFromMedia(MediaModel media) throws NoDataAvailableException Deprecated, for removal: This API element is subject to removal in a future version.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
InputStream getStreamFromMedia(MediaModel media) throws NoDataAvailableException, 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 corruptedIllegalArgumentException- the illegal argument exception if any argument is null
-
getDataFromMedia
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, 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 occurredIllegalArgumentException- the illegal argument exception if any argument is null
-
setDataStreamForMedia
@Deprecated(since="ages", forRemoval=true) void setDataStreamForMedia(MediaModel media, DataInputStream data) Deprecated, for removal: This API element is subject to removal in a future version.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, InputStream data) throws MediaIOException, 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 occurredIllegalArgumentException- the illegal argument exception if any argument is null
-
removeDataFromMediaQuietly
Removes binary data from provided media without throwing exception.- Parameters:
media-- Returns:
- true when removal operation has succeeded, false otherwise.
-
removeDataFromMedia
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
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, String mimeType, String versionId, 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
Removes the version of data for media.- Parameters:
media- the base mediaversionId- the unique version id of data (like format name)
-
getUrlForMediaVersion
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
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, InputStream data, String originalName, String mimeType) throws MediaIOException, 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 occurredIllegalArgumentException- the illegal argument exception if any argument is null
-
setStreamForMedia
void setStreamForMedia(MediaModel media, InputStream data, String originalName, String mimeType, MediaFolderModel folder) throws MediaIOException, 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:
IllegalArgumentException- the illegal argument exception if any argument is nullMediaStoreException- if any media store problems occursIllegalStateException- if media model is newMediaIOException
-
setUrlForMedia
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
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(since="ages", forRemoval=true) void setFolderForMedia(MediaModel media, MediaFolderModel targetFolder) throws MediaIOException, IllegalArgumentException Deprecated, for removal: This API element is subject to removal in a future version.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 occurredIllegalArgumentException- the illegal argument exception if any argument is null
-
moveMediaToFolder
void moveMediaToFolder(MediaModel media, MediaFolderModel targetFolder) throws MediaIOException, 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 occurredIllegalArgumentException- the illegal argument exception if any argument is null
-
moveData
void moveData(MediaModel fromMedia, MediaModel toMedia) throws MediaIOException, 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 operationIllegalArgumentException- the illegal argument exception if any argument is null
-
copyData
void copyData(MediaModel fromMedia, MediaModel toMedia) throws MediaIOException, 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 operationIllegalArgumentException- the illegal argument exception if any argument is null
-
duplicateData
void duplicateData(MediaModel fromMedia, MediaModel toMedia) throws MediaIOException, 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 operationIllegalArgumentException- the illegal argument exception if any argument is null
-
getMediaByContext
MediaModel getMediaByContext(MediaModel media, MediaContextModel context) throws ModelNotFoundException, 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 assignedMediaContainerModeldoes not provide a media in given format.IllegalArgumentException- the illegal argument exception if any argument is null
-
getMediaByFormat
MediaModel getMediaByFormat(MediaModel media, MediaFormatModel format) throws ModelNotFoundException, 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
nullif no corresponding media in specified format is available - Throws:
ModelNotFoundException- if no container is assigned (MediaModel.getMediaContainer()returnsnull) or the assignedMediaContainerModeldoes not provide a media in given format.IllegalArgumentException- the illegal argument exception if any argument is null
-
getMediaByFormat
MediaModel getMediaByFormat(MediaContainerModel container, MediaFormatModel format) throws ModelNotFoundException, 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
nullif no corresponding media in specified format is available - Throws:
ModelNotFoundException- if container isnullor the assignedMediaContainerModeldoes not provide a media in given format.IllegalArgumentException- the illegal argument exception if any argument is null
-
getMedia
MediaModel getMedia(CatalogVersionModel catalogVersion, 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)IllegalArgumentException- if any of the givenqualifierorcatalogVersionare null
-
getMedia
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)IllegalArgumentException- if givenqualifieris null
-
getFiles
@Deprecated(since="ages", forRemoval=true) Collection<File> getFiles(MediaModel mediaModel) throws IllegalArgumentException, NoDataAvailableException Deprecated, for removal: This API element is subject to removal in a future version.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:
IllegalArgumentException- the illegal argument exception if any argument is nullNoDataAvailableException- if no file was found
-
getFolder
MediaFolderModel getFolder(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 foundIllegalArgumentException- if givenqualifieris null
-
getFormat
MediaFormatModel getFormat(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 foundIllegalArgumentException- if givenqualifieris null
-
getRootFolder
Gets the root media folder. This folder is created at createEssentialData of core extension and should be always existent. If not existent aModelNotFoundExceptionis thrown. The root folder is the default folder for a media.- Returns:
- root folder
- Throws:
ModelNotFoundException- in case no root folder is available
-
getMediaWithSameDataReference
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
-
getStreamFromMedia(MediaModel)instead