Class Media

All Implemented Interfaces:
Serializable, Comparable
Direct Known Subclasses:
GeneratedBarcodeMedia, GeneratedCatalogUnawareMedia, GeneratedCatalogVersionSyncScheduleMedia, GeneratedConfigurationMedia, GeneratedDocument, GeneratedEmailAttachment, GeneratedFormatter, GeneratedImpExMedia, GeneratedJasperMedia, GeneratedJobMedia, GeneratedLDIFMedia, GeneratedLogFile, MediaTest.TestMedia

public class Media extends GeneratedMedia
The media item in the hybris platform.

These items should be used for managing data actually stored outside hybris platform (like images, archives, documents etc ). Media items can be linked with any other hybris platform item. This way the application programmer can access either the raw media data or their URL to display it at the right place.

See Also:
  • Field Details

  • Constructor Details

    • Media

      public Media()
  • Method Details

    • createItem

      protected Item createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes) throws JaloBusinessException
      Description copied from class: Item
      Has to be implemented for each concrete subtype of item. This method is responsible for creating a new item instance ( by calling managers, ejb homes, etc. ) during ComposedType.newInstance(Map).

      In case this method uses any of the attribute values during creation it is required to override Item.getNonInitialAttributes(SessionContext, ItemAttributeMap) too.
      Sn example:

      
       public static final String MY_ATTRIBUTE = "someAttribute"; ... protected Item createItem(SessionContext
       ctx, ComposedType type, Map allAttributes ) throws JaloBusinessException { MyManager man = ... return
       man.createMyItem( (String)allAttributes.get(MY_ATTRIBUTE) );
       // here MY_ATTRIBUTE is used for creation, so it must not be set again } protected Map getNonInitialAttributes(
       SessionContext ctx, Map allAttributes ) { // let superclass remove its own initial attributes Map ret =
       super.getNonInitialAttributes( ctx, allAttributes );
       // remove MY_ATTRIBUTE from all attributes since if has already been set ret.remove(MY_ATTRIBUTE); return ret; }
      
       
      Overrides:
      createItem in class GeneratedMedia
      Parameters:
      ctx - the current session context which this item is created within
      type - the actual item type ( since subtypes may not provide a own jalo class this may be different from the type which this method was implemented for )
      Returns:
      the new item instance
      Throws:
      JaloBusinessException - indicates an error during creation - any changes will be rollbacked
    • setFile

      public boolean setFile(File file) throws JaloBusinessException
      Uploads a file for this media. This includes uploading its actual data, setting the real filename to its filename.
      Parameters:
      file - the file to upload (must be readable!)
      Returns:
      true if the upload was successful
      Throws:
      JaloBusinessException
    • setFile

      public boolean setFile(File file, MediaFolder newFolder) throws JaloBusinessException
      Uploads a file for this media. This includes uploading its actual data, setting the real filename to its filename.
      Parameters:
      file - the file to upload (must be readable!)
      newFolder - the new folder for this media where the new file will be located at
      Returns:
      true if the upload was successful
      Throws:
      JaloBusinessException
      Since:
      3.1-u7
    • getURL

      public String getURL()
    • getURL

      public String getURL(SessionContext ctx)
      The URL for use in jsp pages in order to view this medias raw data file (image etc).

      Once setURL(String) was called this medias rely upon this URL has been correct.

      After setData(byte[]) was called an automatically generated URL will be returned which points to the uploaded file

    • getURL2

      @Deprecated(since="ages", forRemoval=false) public String getURL2(SessionContext ctx)
      Deprecated.
      since ages - usegetURL(SessionContext) instead
      JaloOnly methods which are only used to display the preview and the url in the hybris Management Console
      Returns:
      the URL of the media, same as getURL()
    • getURL2

      @Deprecated(since="ages", forRemoval=false) public String getURL2()
      Deprecated.
      since ages - usegetURL() instead
    • setURL2

      @Deprecated(since="ages", forRemoval=false) public void setURL2(SessionContext ctx, String url) throws JaloBusinessException
      Deprecated.
      since ages
      JaloOnly method which is only used to workaround a hmc problem. This method does absolutely the same as setURL ( url ).
      Throws:
      JaloBusinessException
    • setURL2

      @Deprecated(since="ages", forRemoval=false) public void setURL2(String url) throws JaloBusinessException
      Deprecated.
      since ages
      Throws:
      JaloBusinessException
    • getDownloadURL

      public String getDownloadURL(SessionContext ctx)
      The URL for use in jsp pages in order to download this medias raw data file (image etc).

      The value of GeneratedMedia.getInternalURL() URL()} will expanded by:

    • getDownloadURL

      public String getDownloadURL()
    • copyToTempFile

      protected File copyToTempFile(InputStream inputStream) throws IOException
      Throws:
      IOException
    • relocateData

      @Deprecated(since="ages", forRemoval=false) public boolean relocateData(MediaFolder folder)
      Deprecated.
      since ages
      Relocates data to another location. If data is also used by other media objects these objects metadata will be update accordingly.
      Parameters:
      folder - the folder to which move data file
      Returns:
      true, if successful
    • setData

      @Deprecated(since="ages", forRemoval=false) public void setData(DataInputStream stream)
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#setStreamForMedia(de.hybris.platform.core.model.media .MediaModel, InputStream) instead
      Sets given data to media by writing content of given stream to a new data file.
      Parameters:
      stream - stream whose content will be set as data to media
    • setData

      @Deprecated(since="ages", forRemoval=false) public final void setData(DataInputStream stream, String originalName, String mimeType)
      Deprecated.
      since ages
      Sets given data to media by writing content of given stream to a new data file.
      Parameters:
      stream - stream whose content will be set as data to media
      originalName - original name of the data
      mimeType - mime type of data
    • setData

      public final void setData(InputStream stream, String originalName, String mimeType)
      Sets given data to media by writing content of given stream to a new data file.
      Parameters:
      stream - stream whose content will be set as data to media
      originalName - original name of the data
      mimeType - mime type of data
    • setData

      @Deprecated(since="ages", forRemoval=false) public void setData(DataInputStream stream, String originalName, String mimeType, MediaFolder folder)
      Deprecated.
      since ages
      Sets given data to media by writing content of given stream to a new data file.
      Parameters:
      stream - stream whose content will be set as data to media
      originalName - original name of the data
      mimeType - mime type of data
      folder - folder where the data will be written to
      Since:
      3.1-u4
    • setData

      @Deprecated(since="ages", forRemoval=false) public void setData(InputStream stream)
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#setStreamForMedia(de.hybris.platform.core.model.media .MediaModel, InputStream) instead
      Sets given data to media by writing content of given stream to a new data file.
      Parameters:
      stream - stream whose content will be set as data to media
    • setData

      public void setData(InputStream stream, String originalName, String mimeType, MediaFolder folder)
      Sets given data to media by writing content of given stream to a new data file.
      Parameters:
      stream - stream whose content will be set as data to media
      originalName - original name of the data
      mimeType - mime type of data
      folder - folder where the data will be written to
      Since:
      3.1-u4
    • setURL

      public void setURL(String url) throws JaloBusinessException
      Throws:
      JaloBusinessException
    • setURL

      public void setURL(SessionContext ctx, String url) throws JaloBusinessException
      Sets a custom URL for this media.

      Any previously stored raw data file will be deleted.

      Throws:
      JaloBusinessException
    • hasData

      public boolean hasData()
      Checks whether a data file is assigned to this media. Will return false in case data is assigned by URL only.
    • isOnServer

      @Deprecated(since="ages", forRemoval=false) public boolean isOnServer()
      Deprecated.
      since ages - usehasData() instead
      Check if file of that media is uploaded.
    • setSize

      public void setSize(Long size)
      Description copied from class: GeneratedAbstractMedia
      Generated method - Setter of the AbstractMedia.size attribute.
      Overrides:
      setSize in class GeneratedAbstractMedia
      Parameters:
      size - the size - Size of referenced data file.
    • isRemovableAsPrimitive

      public boolean isRemovableAsPrimitive(SessionContext context)
      Checks whether the media can be removed or is locked by a job. If it is not removable and you try to remove it, a ConsistencyCheckException will be raised while call of remove.

      Change default null handling

      Overrides:
      isRemovableAsPrimitive in class GeneratedMedia
      Returns:
      is the media removable?
    • checkRemovable

      protected void checkRemovable(SessionContext ctx) throws ConsistencyCheckException
      Description copied from class: Item
      Checks whether or not this it may be removed or not. Called before the actual removal process.
      Overrides:
      checkRemovable in class Item
      Throws:
      ConsistencyCheckException - to indicate that the item cannot be removed
    • remove

      public void remove(SessionContext context) throws ConsistencyCheckException
      Description copied from class: Item
      Removes this item.

      This method is using the following attributes of the given SessionContext:

      CacheUsage   Language   StagingMethod
      n/a (this is a setter method)   no, language doesn't matter for removal   yes if called on a StageableItem, no otherwise


      Overrides:
      remove in class Item
      Parameters:
      context - A SessionContext object
      Throws:
      ConsistencyCheckException - if this item could not be removed for some reason
    • setDataByURL

      public void setDataByURL() throws IOException, JaloBusinessException
      Loads the data from the medias URL. Loads the file specified by getURL(), and puts it into the media by setDataFromStream(). If the media has no mime type, the mime type is tried to be guessed, first by the extension of the URL, and secondly by the content of the data.
      Throws:
      JaloSystemException - if the media has already data (hasData()).
      IOException
      JaloBusinessException
    • removeData

      public void removeData(boolean failOnError) throws JaloBusinessException
      Removes related data and clears all metadata informations. Keep in mind that data will be removed physically only when there is no other media sharing same binary data.
      Throws:
      JaloBusinessException - if exception occurs and failOnError flag is set
    • getForeignDataOwners

      public Collection<Media> getForeignDataOwners()
    • getForeignDataOwners

      public Collection<Media> getForeignDataOwners(SessionContext ctx)
      Gets all medias excluding this one referencing data file of this media.
      Returns:
      other medias referencing same data file
      Since:
      3.1-u6
    • hasForeignDataOwners

      public boolean hasForeignDataOwners()
      Tells if there are other medias referencing the data file of this media.
      Since:
      3.1-u8
    • getDataFromStream

      @Deprecated(since="ages", forRemoval=false) public DataInputStream getDataFromStream() throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#getStreamFromMedia(de.hybris.platform.core.model .media.MediaModel) instead
      Returns a stream object which makes this medias raw data file available. This can only succeed if once setData(byte[]) or setDataFromStream(DataInputStream) has been called. BEWARE: clients that call this method have to close the returned stream, or they will block further operations on this Media object !
      Returns:
      the media's data as stream
      Throws:
      JaloBusinessException - if no actual data was uploaded
    • getDataFromInputStream

      @Deprecated(since="ages", forRemoval=false) public InputStream getDataFromInputStream() throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#getStreamFromMedia(de.hybris.platform.core.model .media.MediaModel) instead
      Returns a stream object which makes this medias raw data file available. This can only succeed if once setData(byte[]) or setDataFromStream(DataInputStream) has been called. BEWARE: clients that call this method have to close the returned stream, or they will block further operations on this Media object !
      Returns:
      the media's data as stream
      Throws:
      JaloBusinessException - if no actual data was uploaded
    • getDataFromStreamSure

      @Deprecated(since="ages", forRemoval=false) public DataInputStream getDataFromStreamSure() throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#getStreamFromMedia(de.hybris.platform.core.model .media.MediaModel) instead.
      Gets a stream of related data as getDataFromStream() method but additionally for medias having data set by fromjar notation (reading directly from classpath file).
      Throws:
      JaloBusinessException
    • getDataFromInputStreamSure

      @Deprecated(since="ages", forRemoval=false) public InputStream getDataFromInputStreamSure() throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#getStreamFromMedia(de.hybris.platform.core.model .media.MediaModel) instead
      Gets a stream of related data as getDataFromStream() method but additionally for medias having data set by fromjar notation (reading directly from classpath file).
      Throws:
      JaloBusinessException
    • setDataFromStream

      @Deprecated(since="ages", forRemoval=false) public void setDataFromStream(DataInputStream stream) throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#setStreamForMedia(de.hybris.platform.core.model.media .MediaModel, InputStream) instead
      Sets given data to media by writing content of given stream to a new data file. Sets mime type and realfilename to null.
      Throws:
      JaloBusinessException
    • setDataFromStream

      @Deprecated(since="ages", forRemoval=false) public void setDataFromStream(InputStream stream) throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#setStreamForMedia(de.hybris.platform.core.model.media .MediaModel, InputStream) instead
      Sets given data to media by writing content of given stream to a new data file. Sets mime type and realfilename to null.
      Throws:
      JaloBusinessException
    • getData

      @Deprecated(since="ages", forRemoval=false) public byte[] getData() throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#getDataFromMedia(de.hybris.platform.core.model.media .MediaModel) instead.
      Returns the stored file as raw data array. This can only succeed if once setData(byte[]) or setDataFromStream(DataInputStream) has been called once before.
      Throws:
      JaloBusinessException - if no actual data was uploaded
    • setData

      @Deprecated(since="ages", forRemoval=false) public void setData(Media sourceMedia)
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#copyData(de.hybris.platform.core.model.media .MediaModel, de.hybris.platform.core.model.media.MediaModel) instead.
      Copies data from given media to this media. This method is optimized for reusing data files without actually copying them so it should be preferred to stream based methods like setData(InputStream)! 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.
      Parameters:
      sourceMedia - media which hold source data
      Throws:
      JaloInvalidParameterException - if given media is null or does not provide any data (either by file or URL)
      Since:
      3.1-u6
    • setData

      @Deprecated(since="ages", forRemoval=false) public void setData(byte[] data) throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#setDataForMedia(de.hybris.platform.core.model.media .MediaModel, byte[]) instead.
      Sets given data into uploaded files
      Throws:
      JaloBusinessException
    • getFiles

      @Deprecated(since="ages", forRemoval=false) public Collection getFiles() throws JaloSystemException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#getFiles(de.hybris.platform.core.model.media .MediaModel) instead.
      Gets file of given media (from all media replication directories) as collection of File's.
      Throws:
      JaloSystemException - if no file was found
    • getFile

      public File getFile() throws JaloSystemException
      Throws:
      JaloSystemException
    • getFileName

      public String getFileName()
      Gives name of uploaded file. It has name in following format: [DataPkString].[mime_extension]
    • getFileExtensionFromMime

      protected String getFileExtensionFromMime()
    • moveData

      @Deprecated(since="ages", forRemoval=false) public void moveData(Media destin) throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#moveData(de.hybris.platform.core.model.media .MediaModel, de.hybris.platform.core.model.media.MediaModel) instead.
      Moves the medias data to another media. After this method, this media has no data anymore.
      Parameters:
      destin - target media to move data to
      Throws:
      JaloBusinessException - if this media has no data
    • moveDataTo

      @Deprecated(since="ages", forRemoval=false) public void moveDataTo(Media destin) throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#moveData(de.hybris.platform.core.model.media .MediaModel, de.hybris.platform.core.model.media.MediaModel) instead.
      Moves the medias data to another media. After this method, this media has no data anymore.
      Parameters:
      destin - target media to move data to
      Throws:
      JaloSystemException - if source media has no data
      JaloBusinessException
    • moveMedia

      @Deprecated(since="ages", forRemoval=false) public boolean moveMedia(MediaFolder newFolder) throws JaloBusinessException
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#setFolderForMedia(de.hybris.platform.core.model.media .MediaModel, de.hybris.platform.core.model.media.MediaFolderModel) instead.
      Moves the data of media to given folder.
      Parameters:
      newFolder - folder where the data has to be moved to
      Returns:
      true if the data was moved, false otherwise (f.e. in case the old folder is the same as the new one)
      Throws:
      JaloBusinessException - in case an IOException is thrown while move
      Since:
      3.1-u4
    • moveMedia

      @Deprecated(since="ages", forRemoval=false) protected boolean moveMedia(MediaFolder newFolder, boolean forOverwriting) throws JaloBusinessException
      Moves the data of media to given folder.
      Parameters:
      newFolder - folder where the data has to be moved to
      forOverwriting - special case: if data is going to be overwritten anyway we can optimize moving data a bit
      Returns:
      true if the data was moved, false otherwise (f.e. in case the old folder is the same as the new one)
      Throws:
      JaloBusinessException - in case an IOException is thrown while move
      Since:
      3.1-u8
    • getFileNameForFileBasedSoftware

      public String getFileNameForFileBasedSoftware()
      Returns <dataPk>.<mime> if the media has data, else it returns the url part without server/port (and without the 'fromjar/' which is used when loading files from jars), e.g. <dir>/<realname>.<mime>. This method can be used e.g. when using Indesign and must provide a String which should be converted to an image.
      Returns:
      the file name for file based software
      Since:
      3.0
    • getZipEntryNames

      public List<String> getZipEntryNames() throws IOException, JaloBusinessException
      If the media is of type ZIP-archive, then it gets all entry names of the archive.
      Returns:
      name of all archive entries, if media has mime application/zip
      Throws:
      JaloBusinessException - media is not an zip-archive
      IOException - error while reading entry names from archive
    • getZipEntries

      @Deprecated(since="ages", forRemoval=false) public List<ZipEntry> getZipEntries() throws IOException, JaloBusinessException
      Deprecated.
      since ages - don't use any more - usegetZipEntryNames() instead
      If the media is of type ZIP-archive, then it gets all entries of the archive.
      Returns:
      all archive entries, if media has mime application/zip
      Throws:
      JaloBusinessException - media is not an zip-archive
      IOException - error while reading entries from archive
    • getInFormat

      @Deprecated(since="ages", forRemoval=false) public Media getInFormat(MediaFormat format)
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#getMediaByFormat(de.hybris.platform.core.model.media .MediaModel, de.hybris.platform.core.model.media.MediaFormatModel) instead.
      Returns the media in the specified format using the MediaContainer.getMedia(MediaFormat) method of related MediaContainer. Returns null if no MediaContainer is assigned ( GeneratedMedia.getMediaContainer() returns null) or the assigned MediaContainer does not provide a media in given format.
      Parameters:
      format - format the desired media has to have
      Returns:
      media in specified format or null if no corresponding media in specified format is available
      Since:
      3.0-u5
    • getForContext

      @Deprecated(since="ages", forRemoval=false) public Media getForContext(MediaContext context)
      Deprecated.
      since ages - use de.hybris.platform.servicelayer.media.MediaService#getMediaByContext(de.hybris.platform.core.model .media.MediaModel, de.hybris.platform.core.model.media.MediaContextModel) instead.
      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.
      Parameters:
      context - context which defines the target format
      Returns:
      media in specified target format
      Since:
      3.0-u5
    • toString

      public String toString()
      Description copied from class: Item
      Returns the String representation of this item. This is by default the representation of the primary key of this item.
      Overrides:
      toString in class Item
      Returns:
      the String representation of this item.
    • setDataPK

      public void setDataPK(Long dataPK)
      Description copied from class: GeneratedAbstractMedia
      Generated method - Setter of the AbstractMedia.dataPK attribute.
      Overrides:
      setDataPK in class GeneratedAbstractMedia
      Parameters:
      dataPK - the dataPK - PK of the referenced data file.
    • getFolder

      public MediaFolder getFolder(SessionContext ctx)
      Description copied from class: GeneratedMedia
      Generated method - Getter of the Media.folder attribute.
      Overrides:
      getFolder in class GeneratedMedia
      Returns:
      the folder - Sub folder where this media is stored.
    • getLocation

      public String getLocation(SessionContext ctx)
      Description copied from class: GeneratedAbstractMedia
      Generated method - Getter of the AbstractMedia.location attribute.
      Overrides:
      getLocation in class GeneratedAbstractMedia
      Returns:
      the location - Generated location (by one of Storage Strategies) to media within storage.
    • getDeniedPrincipals

      public Collection<Principal> getDeniedPrincipals()
    • setDeniedPrincipals

      public void setDeniedPrincipals(Collection<Principal> value)
    • getDeniedPrincipals

      public Collection<Principal> getDeniedPrincipals(SessionContext ctx)
    • setDeniedPrincipals

      public void setDeniedPrincipals(SessionContext ctx, Collection<Principal> value)
    • getPermittedPrincipals

      public Collection<Principal> getPermittedPrincipals()
    • getPermittedPrincipals

      public Collection<Principal> getPermittedPrincipals(SessionContext ctx)
    • setPermittedPrincipals

      public void setPermittedPrincipals(Collection<Principal> value)
    • setPermittedPrincipals

      public void setPermittedPrincipals(SessionContext ctx, Collection<Principal> value)