Class Media

    • Field Detail

      • THUMBNAIL

        @Deprecated
        public static final java.lang.String THUMBNAIL
        Deprecated.
        since ages
        Sample qualifier which can be used to get a product-media-link.
        This constant is a qualifier which can be used by LinkManager methods. Use LinkManager.getLink( Media.THUMBNAIL, prod, ... ) to get the thumbnail to a product.
        See Also:
        Constant Field Values
      • PICTURE

        @Deprecated
        public static final java.lang.String PICTURE
        Deprecated.
        since ages
        Sample qualifier which can be used to get a product-media-link.
        This constant is a qualifier which can be used by LinkManager methods. Use LinkManager.getLink( Media.PICTURE, prod, ... ) to get the picture to a product.
        See Also:
        Constant Field Values
      • URL2

        public static final java.lang.String URL2
        Constant identifier for url2 attribute of Media type.
        See Also:
        Constant Field Values
      • HASDATA

        public static final java.lang.String HASDATA
        Constant identifier for hasdata attribute of Media type.
        See Also:
        Constant Field Values
      • ISONSERVER

        public static final java.lang.String ISONSERVER
        Constant identifier for isonserver attribute of Media type.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Media

        public Media()
    • Method Detail

      • 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​(java.io.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​(java.io.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 java.lang.String getURL()
      • getURL

        public java.lang.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
        public java.lang.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
        public java.lang.String getURL2()
        Deprecated.
        since ages - usegetURL() instead
      • setURL2

        @Deprecated
        public void setURL2​(SessionContext ctx,
                            java.lang.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
      • getDownloadURL

        public java.lang.String getDownloadURL()
      • copyToTempFile

        protected java.io.File copyToTempFile​(java.io.InputStream inputStream)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • relocateData

        @Deprecated
        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
        public void setData​(java.io.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
        public final void setData​(java.io.DataInputStream stream,
                                  java.lang.String originalName,
                                  java.lang.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​(java.io.InputStream stream,
                                  java.lang.String originalName,
                                  java.lang.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
        public void setData​(java.io.DataInputStream stream,
                            java.lang.String originalName,
                            java.lang.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
        public void setData​(java.io.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​(java.io.InputStream stream,
                            java.lang.String originalName,
                            java.lang.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
      • 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
        public boolean isOnServer()
        Deprecated.
        since ages - usehasData() instead
        Check if file of that media is uploaded.
      • setSize

        public void setSize​(java.lang.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?
      • 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 java.io.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()).
        java.io.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 java.util.Collection<Media> getForeignDataOwners()
      • getForeignDataOwners

        public java.util.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
        public java.io.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
        public java.io.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
        public java.io.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
        public java.io.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
        public void setDataFromStream​(java.io.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
        public void setDataFromStream​(java.io.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
        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
        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
        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
        public java.util.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
      • getFileName

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

        protected java.lang.String getFileExtensionFromMime()
      • moveData

        @Deprecated
        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
        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
        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
      • getFileNameForFileBasedSoftware

        public java.lang.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 java.util.List<java.lang.String> getZipEntryNames()
                                                          throws java.io.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
        java.io.IOException - error while reading entry names from archive
      • getZipEntries

        @Deprecated
        public java.util.List<java.util.zip.ZipEntry> getZipEntries()
                                                             throws java.io.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
        java.io.IOException - error while reading entries from archive
      • getInFormat

        @Deprecated
        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
        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 java.lang.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​(java.lang.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.
      • getLocation

        public java.lang.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 java.util.Collection<Principal> getDeniedPrincipals()
      • setDeniedPrincipals

        public void setDeniedPrincipals​(java.util.Collection<Principal> value)
      • setDeniedPrincipals

        public void setDeniedPrincipals​(SessionContext ctx,
                                        java.util.Collection<Principal> value)
      • getPermittedPrincipals

        public java.util.Collection<Principal> getPermittedPrincipals()
      • setPermittedPrincipals

        public void setPermittedPrincipals​(java.util.Collection<Principal> value)
      • setPermittedPrincipals

        public void setPermittedPrincipals​(SessionContext ctx,
                                           java.util.Collection<Principal> value)