Class MediaManager

java.lang.Object
de.hybris.platform.jalo.Manager
de.hybris.platform.jalo.media.MediaManager
All Implemented Interfaces:
ItemLifecycleListener, Serializable

public class MediaManager extends Manager
The manager for media items.
See Also:
  • Field Details

    • BEAN_NAME

      public static final String BEAN_NAME
      Identifier of this manager used at core-spring.xml spring configuration.
      See Also:
    • MEDIAFOLDER

      @Deprecated(since="ages", forRemoval=false) public static final String MEDIAFOLDER
      Deprecated.
      since ages - use CoreConstants.TC.MEDIAFOLDER instead
      Constant identifier for MediaFolder type.
    • MEDIACONTAINER

      @Deprecated(since="ages", forRemoval=false) public static final String MEDIACONTAINER
      Deprecated.
      since ages - use CoreConstants.TC.MEDIACONTAINER instead
      Constant identifier for MediaContainer type.
    • MEDIACONTEXT

      @Deprecated(since="ages", forRemoval=false) public static final String MEDIACONTEXT
      Deprecated.
      since ages - use CoreConstants.TC.MEDIACONTEXT instead
      Constant identifier for MediaContext type.
    • MEDIAFORMAT

      @Deprecated(since="ages", forRemoval=false) public static final String MEDIAFORMAT
      Deprecated.
      since ages - use CoreConstants.TC.MEDIAFORMAT instead
      Constant identifier for MediaFormat type.
    • MEDIAFORMATMAPPING

      @Deprecated(since="ages", forRemoval=false) public static final String MEDIAFORMATMAPPING
      Deprecated.
      since ages - use CoreConstants.TC.MEDIAFORMATMAPPING instead
      Constant identifier for MediaFormatMapping type.
    • MEDIAFORMATTER

      @Deprecated(since="ages", forRemoval=false) public static final String MEDIAFORMATTER
      Deprecated.
      since ages - use CommonsConstants.TC.MEDIAFORMATTER instead
      Constant identifier for MediaFormatter type.
    • ROOT_FOLDER_QUALIFIER

      public static final String ROOT_FOLDER_QUALIFIER
      Identifier of the root media folder created at system initialization.
      See Also:
    • PREFERRED_URL_STRATEGY_ID

      public static final String PREFERRED_URL_STRATEGY_ID
      See Also:
  • Constructor Details

    • MediaManager

      public MediaManager()
  • Method Details

    • setMimeService

      public void setMimeService(MimeService mimeService)
    • setMediaHeadersRegistry

      public void setMediaHeadersRegistry(MediaHeadersRegistry mediaHeadersRegistry)
    • setLocalMediaFileCache

      public void setLocalMediaFileCache(LocalMediaFileCacheService localMediaFileCache)
    • setMediaStorageConfigService

      public void setMediaStorageConfigService(MediaStorageConfigService mediaStorageConfig)
    • setMediaStorageRegistry

      public void setMediaStorageRegistry(MediaStorageRegistry mediaStorageRegistry)
    • setLocationHashService

      public void setLocationHashService(MediaLocationHashService locationHashService)
    • getMediaStorageFactory

      public MediaStorageRegistry getMediaStorageFactory()
    • getFileExtensionFromMime

      public String getFileExtensionFromMime(String mime)
      Gets the file extension from mime.
      See Also:
    • getBestMime

      public String getBestMime(String fileName, byte[] firstBytes, String overrideMime)
      Gets the best mime.
      See Also:
    • getBestMime

      public String getBestMime(String filePath)
      Gets the best mime for provided media file path.
      See Also:
    • hasForeignDataOwners

      public boolean hasForeignDataOwners(PK mediaPk, Long dataPk)
    • storeMedia

      public StoredMediaData storeMedia(MediaDataStoreCommand command)
      Store media.
      Returns:
      the stored media data
    • deleteMedia

      public void deleteMedia(String folderQualifier, String location)
      Delete media.
      Parameters:
      folderQualifier - the folder qualifier
      location - the location
    • deleteMediaDataUnlessReferenced

      public void deleteMediaDataUnlessReferenced(PK mediaPk, Long dataPk, String folderQualifier, String location)
      This method deletes media data unless it is referenced by another media object. If current transaction is running deletion will be delayed just after success commit. If there is no running transaction delete operation will be executed immediately.
      Parameters:
      mediaPk - PK of the given media object
      dataPk - Data PK of the given media object
      folderQualifier - Folder qualifier of the given media object
      location - Location of media data in the storage
    • getMediaAsStreamWithSize

      public MediaManager.InputStreamWithSize getMediaAsStreamWithSize(String folderQualifier, String location)
      Gets the media as stream with its size.
      Parameters:
      folderQualifier - the folder qualifier
      location - the location
      Returns:
      the MediaManager.InputStreamWithSize object containing a stream with its size
    • getMediaAsStream

      public InputStream getMediaAsStream(String folderQualifier, String location)
      Gets the media as stream.
      Parameters:
      folderQualifier - the folder qualifier
      location - the location
      Returns:
      the media as stream
    • getMediaAsStream

      public InputStream getMediaAsStream(MediaSource mediaSource)
      Gets media as stream. This method returns stream for backed binary data if media has it or tries to get stream directly from its URL if it does not have real data.
      Parameters:
      mediaSource - Wrapper interface for the media object.
      Returns:
      the media as stream
    • getMediaAsByteArray

      public byte[] getMediaAsByteArray(String folderQualifier, String location) throws IOException
      Throws:
      IOException
    • tryToGetMediaAsByteArrayFromUrl

      public byte[] tryToGetMediaAsByteArrayFromUrl(MediaSource media) throws IOException
      Tries to get media from URL then turns media to an array of bytes
      Parameters:
      media - media source
      Returns:
      byte[]
      Throws:
      IOException - IO Error
    • hasData

      public boolean hasData(MediaSource mediaSource)
    • getMediaHeadersRegistry

      public MediaHeadersRegistry getMediaHeadersRegistry()
    • isZipRelatedMime

      public boolean isZipRelatedMime(String mime)
    • verifyMediaHashForLocation

      @Deprecated(since="2011", forRemoval=true) public void verifyMediaHashForLocation(String folderQualifier, String location, String storedHash)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • verifyMediaHash

      public MediaLocationHashService.HashType verifyMediaHash(String folderQualifier, String location, String storedHash, long size, String mime)
    • isPathTargetSecuredFolder

      public boolean isPathTargetSecuredFolder(String folderQualifier, String location)
    • isFolderConfiguredAsSecured

      public boolean isFolderConfiguredAsSecured(String folderQualifier)
    • getMediaAsFile

      public File getMediaAsFile(String folderQualifier, String location)
      This method try to return media data as File. It may throw UnsupportedOperationException when underlying MediaStorageStrategy does not support it.
      Parameters:
      folderQualifier - the folder qualifier
      location - the location
      Returns:
      the media as file
    • getURLForMedia

      public String getURLForMedia(String folderQualifier, MediaSource mediaSource)
    • getDownloadURLForMedia

      public String getDownloadURLForMedia(String folderQualifier, MediaSource mediaSource)
    • createMediaSource

      protected MediaSource createMediaSource(AbstractMedia media)
    • initializeMediaStorage

      public void initializeMediaStorage(boolean freshInit)
      Executes any configured media storage initializer on initialization process.
      Parameters:
      freshInit - determines whether it is fresh init or update
    • isSecuredFolder

      public boolean isSecuredFolder(String folderQualifier)
    • getInstance

      public static MediaManager getInstance()
      Gets the instance of this manager.
      Returns:
      instance of this manager
    • checkBeforeItemRemoval

      protected void checkBeforeItemRemoval(SessionContext ctx, Item item) throws ConsistencyCheckException
      Superclass method overridden to avoid call to EJB layer.
      Overrides:
      checkBeforeItemRemoval in class Manager
      Parameters:
      ctx - the current session context
      item - the item which should be removed
      Throws:
      ConsistencyCheckException - thrown to abort removal due to consistency errors
      Since:
      2.10
    • notifyItemRemoval

      protected void notifyItemRemoval(SessionContext ctx, Item item)
      Superclass method overridden to avoid call to EJB layer.
      Overrides:
      notifyItemRemoval in class Manager
      Parameters:
      ctx - the currency session context
      item - the item which is going to be removed
      Since:
      2.10
    • getMediaTypeCode

      protected String getMediaTypeCode()
      Gets the code of the media type.
      Returns:
      code of media type
    • createMedia

      public Media createMedia(String code)
      Creates a new media item. By this time no URL is set and no data is available.
      Parameters:
      code - code of new media
    • createMedia

      public Media createMedia(PK pk, String code)
      Creates a new media item. By this time no URL is set and no data is available.
      Parameters:
      pk - the pk for the new item; it will be equipped with type code additionally (-)
      code - code of new media
    • createMedia

      public Media createMedia(String code, ComposedType type)
      Creates a new media item with a specific type. By this time no URL is set and no data is available.

      Please note that this does not set any attribute declared by this type! Use ComposedType.newInstance(Map) to achieve attribute checks.

      Parameters:
      code - the code of the new media
      type - the type of the new media
    • createMedia

      public Media createMedia(PK pkBase, String code, ComposedType type)
      Creates a new media item with a specific type. By this time no URL is set and no data is available.

      Please note that this does not set any attribute declared by this type! Use ComposedType.newInstance(Map) to achieve attribute checks.

      Parameters:
      pkBase - the pk for the new item; it will be equipped with type code additionally (-)
      code - the code of the new media
      type - the type of the new media
    • getAllMedias

      @Deprecated(since="ages", forRemoval=false) public Collection getAllMedias()
      Deprecated.
      since 'medias' is incorrect term. Please use getAllMedia() instead.
      Gets all media items.
    • getAllMedia

      @Deprecated(since="ages", forRemoval=false) public Collection getAllMedia()
      Deprecated.
      since ages - use plain FlexibleSearchService.getModelsByExample(Object) to get a de.hybris.platform.core.model.media.MediaModels instances. See more at loading by exemplary model.
      Gets all media items.
    • getMediasByCode

      @Deprecated(since="ages", forRemoval=false) public Collection getMediasByCode(String searchString)
      Deprecated.
      since 'medias' is incorrect term
      Finds all media which code matches the specified search pattern. Wildcards are '%' and '_' ( as in SQL LIKE statements ).
      Parameters:
      searchString - pattern used for searching
    • getMediaByCode

      public Collection getMediaByCode(String searchString)
      Finds all media which code matches the specified search pattern. Wildcards are '%' and '_' ( as in SQL LIKE statements ).
      Parameters:
      searchString - pattern used for searching
    • getMediasByMimeType

      @Deprecated(since="ages", forRemoval=false) public Collection getMediasByMimeType(String mimePattern)
      Deprecated.
      since 'medias' is incorrect term
      Finds all media whose mime type matches the given pattern.
      Parameters:
      mimePattern - a SQL pattern for the mime type
      Returns:
      a collection of Media objects
    • getMediaByMimeType

      public Collection getMediaByMimeType(String mimePattern)
      Finds all media whose mime type matches the given pattern.
      Parameters:
      mimePattern - a SQL pattern for the mime type
      Returns:
      a collection of Media objects
    • getMediaByURL

      @Deprecated(since="ages", forRemoval=false) public Collection getMediaByURL(String urlPattern)
      Deprecated.
      since ages
      Finds all media whose url matches the given pattern.
      Parameters:
      urlPattern - a SQL pattern for the url
      Returns:
      a collection of Media objects
    • getMediaByURLExact

      @Deprecated(since="ages", forRemoval=false) public Collection getMediaByURLExact(String url)
      Deprecated.
      since ages - use plain FlexibleSearchService.getModelsByExample(Object) to get a de.hybris.platform.core.model.media.MediaModels instances for a specified de.hybris.platform.core.model.media.MediaModel.CODE. See more at loading by exemplary model.
      Finds a media for a given url.
      Parameters:
      url - the url media will be needed
      Returns:
      all media matching given url
    • getMimeTypeByExtension

      public String getMimeTypeByExtension(String fileExtension)
      Returns the MimeType for the given fileextension. If the Extension is unknown the Binary-Mimetype will be returned.
      Parameters:
      fileExtension - Fileextension, no dot, allowed are Lower- and Uppercases.
      Returns:
      Mimetypestring
    • createMediaFolder

      public MediaFolder createMediaFolder(String qualifier, String path)
      Creates a new folder with given qualifier and path.
      Parameters:
      qualifier - qualifier for new folder
      path - path for new folder
      Returns:
      created folder
      Since:
      3.1-u4
    • createMediaFolder

      public MediaFolder createMediaFolder(Map<String,Object> attributeValues)
      Creates a new folder with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      Returns:
      created folder
      Since:
      3.1-u4
    • createMediaFolder

      public MediaFolder createMediaFolder(SessionContext ctx, Map<String,Object> attributeValues)
      Creates a new folder with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      ctx - session context
      Returns:
      created folder
      Since:
      3.1-u4
    • getMediaFolderByQualifier

      public Collection<MediaFolder> getMediaFolderByQualifier(String searchString)
      Finds all folders whose qualifier matches the specified search pattern. Wildcards are '%' and '_' ( as in SQL LIKE statements ).
      Parameters:
      searchString - pattern used for searching the folders
      Returns:
      list of found folders
      Since:
      3.1-u4
    • getAllMediaFolders

      @Deprecated(since="ages", forRemoval=false) public Collection<MediaFolder> getAllMediaFolders()
      Deprecated.
      Gets all MediaFolder's in system.
      Returns:
      all folders installed
      Since:
      3.1-u4
    • getRootMediaFolder

      @Deprecated(since="ages", forRemoval=false) public MediaFolder getRootMediaFolder()
      Deprecated.
      since ages - useMediaService.getRootFolder() instead
      Gets the root folder.
      Returns:
      root folder
      Throws:
      JaloSystemException - when root media folder does not exist
      Since:
      3.1-u4
    • getOrCreateRootMediaFolder

      public MediaFolder getOrCreateRootMediaFolder()
      Gets the or create root media folder.
      Returns:
      the or create root media folder
    • createMediaContainer

      public MediaContainer createMediaContainer(String qualifier)
      Creates a new container with given qualifier.
      Parameters:
      qualifier - qualifier for new container
      Returns:
      created container
    • createMediaContainer

      public MediaContainer createMediaContainer(Map<String,Object> attributeValues)
      Creates a new container with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      Returns:
      created container
    • createMediaContainer

      public MediaContainer createMediaContainer(SessionContext ctx, Map<String,Object> attributeValues)
      Creates a new container with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      ctx - session context
      Returns:
      created container
    • createMediaFormat

      public MediaFormat createMediaFormat(String qualifier)
      Creates a new format with given qualifier.
      Parameters:
      qualifier - qualifier for new format
      Returns:
      created format
    • createMediaFormat

      public MediaFormat createMediaFormat(Map<String,Object> attributeValues)
      Creates a new format with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      Returns:
      created format
    • createMediaFormat

      public MediaFormat createMediaFormat(SessionContext ctx, Map<String,Object> attributeValues)
      Creates a new format with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      ctx - session context
      Returns:
      created format
    • createMediaContext

      public MediaContext createMediaContext(String qualifier)
      Creates a new context with given qualifier.
      Parameters:
      qualifier - qualifier for new context
      Returns:
      created context
    • createMediaContext

      public MediaContext createMediaContext(Map<String,Object> attributeValues)
      Creates a new context with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      Returns:
      created context
    • createMediaContext

      public MediaContext createMediaContext(SessionContext ctx, Map<String,Object> attributeValues)
      Creates a new context with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      ctx - session context
      Returns:
      created context
    • createMediaFormatMapping

      public MediaFormatMapping createMediaFormatMapping(MediaFormat source, MediaFormat target)
      Creates a new mapping with given source and target format.
      Parameters:
      source - source format
      target - target format
      Returns:
      created mapping
    • createMediaFormatMapping

      public MediaFormatMapping createMediaFormatMapping(Map<String,Object> attributeValues)
      Creates a new mapping with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      Returns:
      created mapping
    • createMediaFormatMapping

      public MediaFormatMapping createMediaFormatMapping(SessionContext ctx, Map<String,Object> attributeValues)
      Creates a new mapping with given parameters.
      Parameters:
      attributeValues - parameters used for creation
      ctx - session context
      Returns:
      created mapping
    • createMedia

      public Media createMedia(String code, MediaFormat format)
      Creates a new media with given code and format.
      Parameters:
      code - code for new media
      format - format for new media
      Returns:
      created media
    • getAllMediaContexts

      @Deprecated(since="ages", forRemoval=false) public List<MediaContext> getAllMediaContexts()
      Deprecated.
      since ages - use plain FlexibleSearchService.getModelsByExample(Object) to get a MediaContexts instances. See more at loading by exemplary model.
      Gets all media contexts in system.
      Returns:
      list of all contexts in system
    • getMediaFormatByQualifier

      public MediaFormat getMediaFormatByQualifier(String qualifier)
      Gets first media format matching given qualifier.
      Parameters:
      qualifier - qualifier a format is needed for
      Returns:
      media format with given qualifier
    • writeReplace

      public Object writeReplace() throws ObjectStreamException
      Specified by:
      writeReplace in class Manager
      Throws:
      ObjectStreamException