Class DefaultMediaService

  • All Implemented Interfaces:
    MediaService, java.io.Serializable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean

    public class DefaultMediaService
    extends AbstractBusinessService
    implements MediaService
    Default implementation of media service.
    Since:
    4.0
    See Also:
    Serialized Form
    • Constructor Detail

      • DefaultMediaService

        public DefaultMediaService()
    • Method Detail

      • copyData

        public void copyData​(MediaModel fromMedia,
                             MediaModel toMedia)
        Description copied from interface: MediaService
        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 also MediaService.duplicateData(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.

        Specified by:
        copyData in interface MediaService
        Parameters:
        fromMedia - source media to copy data from
        toMedia - target media to copy data to
      • duplicateData

        public void duplicateData​(MediaModel fromMedia,
                                  MediaModel toMedia)
        Description copied from interface: MediaService
        Copies data from a media to another media by duplicating the data (both medias will point to different data file). See also MediaService.copyData(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.

        Specified by:
        duplicateData in interface MediaService
        Parameters:
        fromMedia - source media to copy data from
        toMedia - target media to copy data to
      • moveData

        public void moveData​(MediaModel fromMedia,
                             MediaModel toMedia)
        Description copied from interface: MediaService
        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.

        Specified by:
        moveData in interface MediaService
        Parameters:
        fromMedia - source media to move data from
        toMedia - target media to move data to
      • getMediaByContext

        public MediaModel getMediaByContext​(MediaModel media,
                                            MediaContextModel context)
        Description copied from interface: MediaService
        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.
        Specified by:
        getMediaByContext in interface MediaService
        Parameters:
        media - media for which the related media in specific format is needed
        context - context which defines the target format
        Returns:
        media in format specified by context
      • getMediaByFormat

        public MediaModel getMediaByFormat​(MediaModel media,
                                           MediaFormatModel format)
        Description copied from interface: MediaService
        Gets media in specified format related to given media.
        Specified by:
        getMediaByFormat in interface MediaService
        Parameters:
        media - media for which the related media in specific format is needed
        format - format the desired media has to have
        Returns:
        media in specified format or null if no corresponding media in specified format is available
      • getMediaByFormat

        public MediaModel getMediaByFormat​(MediaContainerModel container,
                                           MediaFormatModel format)
        Description copied from interface: MediaService
        Gets media in specified format related to given media container.
        Specified by:
        getMediaByFormat in interface MediaService
        Parameters:
        container - container for which the related media in specific format is needed
        format - format the desired media has to have
        Returns:
        MediaModel in specified format or null if no corresponding media in specified format is available
      • getDataFromMedia

        public byte[] getDataFromMedia​(MediaModel media)
                                throws NoDataAvailableException
        Description copied from interface: MediaService
        Returns the stored file of given media as raw data array. This can only succeed if once data was set before.
        Specified by:
        getDataFromMedia in interface MediaService
        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
      • getDataStreamFromMedia

        @Deprecated
        public java.io.DataInputStream getDataStreamFromMedia​(MediaModel media)
                                                       throws NoDataAvailableException
        Deprecated.
        since ages
        Description copied from interface: MediaService
        Returns the stored file of given media as stream. This can only succeed if once data was set before.
        Specified by:
        getDataStreamFromMedia in interface MediaService
        Parameters:
        media - media for which data is requested
        Returns:
        stream to data of media
        Throws:
        NoDataAvailableException - if no data was set before
      • getStreamFromMedia

        public java.io.InputStream getStreamFromMedia​(MediaModel media)
                                               throws NoDataAvailableException
        Description copied from interface: MediaService
        Returns the stored file of given media as stream. This can only succeed if once data was set before.
        Specified by:
        getStreamFromMedia in interface MediaService
        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 corrupted
      • getFiles

        public java.util.Collection<java.io.File> getFiles​(MediaModel media)
                                                    throws NoDataAvailableException
        Description copied from interface: MediaService
        Gets file of given media (from all media replication directories) as collection of File's.
        Specified by:
        getFiles in interface MediaService
        Parameters:
        media - mediaModel used for searching
        Returns:
        Collection of files based on the given mediaModel
        Throws:
        NoDataAvailableException - if no file was found
      • getFolder

        public MediaFolderModel getFolder​(java.lang.String qualifier)
        Description copied from interface: MediaService
        Gets the folder identified unique by given qualifier.
        Specified by:
        getFolder in interface MediaService
        Parameters:
        qualifier - qualifier used for searching the folder
        Returns:
        folder matching given qualifier
      • getFormat

        public MediaFormatModel getFormat​(java.lang.String qualifier)
        Description copied from interface: MediaService
        Gets the format identified unique by given qualifier.
        Specified by:
        getFormat in interface MediaService
        Parameters:
        qualifier - qualifier used for searching the format
        Returns:
        format matching given qualifier
      • setFolderForMedia

        public void setFolderForMedia​(MediaModel media,
                                      MediaFolderModel targetFolder)
        Description copied from interface: MediaService
        Changes the folder of media to given new folder and move the related media data to this folder.
        Specified by:
        setFolderForMedia in interface MediaService
        Parameters:
        media - media for which the folder will be changed
        targetFolder - folder where the data has to be moved to
      • moveMediaToFolder

        public void moveMediaToFolder​(MediaModel media,
                                      MediaFolderModel targetFolder)
                               throws MediaIOException,
                                      java.lang.IllegalArgumentException
        Description copied from interface: MediaService
        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.

        Specified by:
        moveMediaToFolder in interface MediaService
        Parameters:
        media - media for which the folder will be changed
        targetFolder - folder where the data has to be moved to
        Throws:
        MediaIOException - if IO problems has occurred
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • setDataStreamForMedia

        @Deprecated
        public void setDataStreamForMedia​(MediaModel media,
                                          java.io.DataInputStream data)
        Deprecated.
        since ages
        Description copied from interface: MediaService
        Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.
        Specified by:
        setDataStreamForMedia in interface MediaService
        Parameters:
        media - media for which data will be set
        data - data to set
      • setStreamForMedia

        public void setStreamForMedia​(MediaModel media,
                                      java.io.InputStream data)
        Description copied from interface: MediaService
        Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.
        Specified by:
        setStreamForMedia in interface MediaService
        Parameters:
        media - media for which data will be set
        data - data to set
      • removeDataFromMediaQuietly

        public boolean removeDataFromMediaQuietly​(MediaModel media)
        Description copied from interface: MediaService
        Removes binary data from provided media without throwing exception.
        Specified by:
        removeDataFromMediaQuietly in interface MediaService
        Returns:
        true when removal operation has succeeded, false otherwise.
      • removeDataFromMedia

        public void removeDataFromMedia​(MediaModel media)
        Description copied from interface: MediaService
        Removes binary data from provided media. If data cannot be removed MediaRemovalException is thrown.
        Specified by:
        removeDataFromMedia in interface MediaService
        Parameters:
        media - media from which data will be removed
      • hasData

        public boolean hasData​(MediaModel media)
        Description copied from interface: MediaService
        Returns information whether given media has binary data.
        Specified by:
        hasData in interface MediaService
        Parameters:
        media - media to examine
        Returns:
        true if media has binary data, false otherwise
      • addVersionStreamForMedia

        public void addVersionStreamForMedia​(MediaModel media,
                                             java.lang.String versionId,
                                             java.io.InputStream data)
        Description copied from interface: MediaService
        Adds the additional version of data as stream for given base media. Mime type will be used from base media.
        Specified by:
        addVersionStreamForMedia in interface MediaService
        Parameters:
        media - the base media
        versionId - the unique version id of data (like format name)
        data - the data stream
      • addVersionStreamForMedia

        public void addVersionStreamForMedia​(MediaModel media,
                                             java.lang.String versionId,
                                             java.lang.String mimeType,
                                             java.io.InputStream data)
        Description copied from interface: MediaService
        Adds the additional version of data as stream for given base media
        Specified by:
        addVersionStreamForMedia in interface MediaService
        Parameters:
        media - the base media
        versionId - the custom mime type
        mimeType - the unique version id of data (like format name)
        data - the data stream
      • removeVersionForMedia

        public void removeVersionForMedia​(MediaModel media,
                                          java.lang.String versionId)
        Description copied from interface: MediaService
        Removes the version of data for media.
        Specified by:
        removeVersionForMedia in interface MediaService
        Parameters:
        media - the base media
        versionId - the unique version id of data (like format name)
      • getUrlForMediaVersion

        public java.lang.String getUrlForMediaVersion​(MediaModel media,
                                                      java.lang.String versionId)
        Description copied from interface: MediaService
        Gets the URL for media version rendered by configured URL strategy.
        Specified by:
        getUrlForMediaVersion in interface MediaService
        Parameters:
        media - the base media
        versionId - the unique version id of data (like format name)
        Returns:
        the URL for media version
      • getStreamForMediaVersion

        public java.io.InputStream getStreamForMediaVersion​(MediaModel media,
                                                            java.lang.String versionId)
        Description copied from interface: MediaService
        Gets the stream for media version.
        Specified by:
        getStreamForMediaVersion in interface MediaService
        Parameters:
        media - the base media
        versionId - the unique version id of data (like format name)
        Returns:
        the stream for media version
      • setStreamForMedia

        public 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. The stream will be closed afterwards.
        Specified by:
        setStreamForMedia in interface MediaService
        Parameters:
        media - media for which data will be set
        data - data to set
        originalName - The file name
        mimeType - MIME type of the media
      • setStreamForMedia

        public 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. The stream will be closed afterwards.
        Specified by:
        setStreamForMedia in interface MediaService
        Parameters:
        media - media for which data will be set
        data - data to set
        originalName - The file name
        mimeType - MIME type of the media
        folder - The folder where media will be stored
      • setUrlForMedia

        public void setUrlForMedia​(MediaModel media,
                                   java.lang.String url)
        Description copied from interface: MediaService
        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.
        Specified by:
        setUrlForMedia in interface MediaService
        Parameters:
        media - media for which the url will be set
        url - the url
      • getUrlForMedia

        public java.lang.String getUrlForMedia​(MediaModel media)
        Description copied from interface: MediaService
        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.
        Specified by:
        getUrlForMedia in interface MediaService
        Parameters:
        media - media for which the url will be obtained
        Returns:
        url
      • setDataForMedia

        public void setDataForMedia​(MediaModel media,
                                    byte[] data)
        Description copied from interface: MediaService
        Sets given raw data to media by writing content of given stream to a new data file.
        Specified by:
        setDataForMedia in interface MediaService
        Parameters:
        media - media for which data will be set
        data - raw data to set
      • getRootFolder

        public MediaFolderModel getRootFolder()
        Description copied from interface: MediaService
        Gets the root media folder. This folder is created at createEssentialData of core extension and should be always existent. If not existent a ModelNotFoundException is thrown. The root folder is the default folder for a media.
        Specified by:
        getRootFolder in interface MediaService
        Returns:
        root folder
      • getMedia

        public MediaModel getMedia​(CatalogVersionModel catalogVersion,
                                   java.lang.String code)
        Description copied from interface: MediaService
        Gets the media identified unique by given code and catalog version.
        Specified by:
        getMedia in interface MediaService
        Parameters:
        catalogVersion - version used for searching
        code - code used for searching
        Returns:
        media matching given code and version
      • getMedia

        public MediaModel getMedia​(java.lang.String code)
        Description copied from interface: MediaService
        Gets the media identified unique by given code.
        Specified by:
        getMedia in interface MediaService
        Parameters:
        code - code used for searching
        Returns:
        media matching given code
      • getMediaWithSameDataReference

        public java.util.Collection<MediaModel> getMediaWithSameDataReference​(MediaModel media)
        Description copied from interface: MediaService
        Returns a collection of MediaModel objects that point to the same physical file.
        Specified by:
        getMediaWithSameDataReference in interface MediaService
        Parameters:
        media - media used for search
        Returns:
        collection of medias referencing the same file
      • setMediaDao

        public void setMediaDao​(MediaDao mediaDao)
      • setMimeService

        public void setMimeService​(MimeService mimeService)
      • setFlexibleSearchService

        public void setFlexibleSearchService​(FlexibleSearchService flexibleSearchService)