Package de.hybris.platform.util
Class MediaUtil
- java.lang.Object
-
- de.hybris.platform.util.MediaUtil
-
public class MediaUtil extends java.lang.ObjectTools for medias
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMediaUtil.PublicMediaURLRendererstatic interfaceMediaUtil.SecureMediaURLRenderer
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDUMMY_FILE_NAMEstatic java.lang.StringFILE_SEPstatic java.lang.StringMEDIA_DATA_DIRSstatic java.lang.StringMEDIA_READ_DIRstatic java.lang.StringURL_HAS_DATAstatic java.lang.StringURL_IS_EMPTYIf the URL contains this string, the URL is empty.
-
Constructor Summary
Constructors Constructor Description MediaUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.StringaddLeadingFileSepIfNeeded(java.lang.String path)Adds the leading file separator to the path if it doesn't contain one already.static java.lang.StringaddTrailingFileSepIfNeeded(java.lang.String path)Adds the trailing file separator to the path if it doesn't contain one already.static java.lang.StringappendFileNameToDirName(java.lang.String dirname, java.lang.String filename)static java.lang.StringassemblePublicMediaURL(java.lang.String rawUrl)static java.lang.StringassembleSecureMediaURL(MediaSource media)static java.io.FilecomposeOrGetParent(java.io.File parent, java.lang.String child)Builds the file from parent file and child pathname which can be directory or file.static java.io.FileconcatDirectoryWithFolder(java.io.File dir, MediaFolder subFolder)Concatenates given directory with given folder.static longcopy(java.io.InputStream is, java.io.OutputStream os)Copy the data from the Inputstream to the Outputstream.static longcopy(java.io.InputStream is, java.io.OutputStream os, boolean closeOutputStream)Copy the data from the Inputstream to the Outputstream.static longcopy(java.io.InputStream is, java.util.Collection<java.io.OutputStream> os)Copy the data from the Inputstream to a Collection of Outputstreams.static longcopy(java.io.InputStream is, java.util.Collection<java.io.OutputStream> outStreams, boolean closeOutputStreams)Copy the data from the InputStream to a Collection of OutputStreams.static voidcopyMediaData(Media src, Media tgt)Deprecated, for removal: This API element is subject to removal in a future version.static MediaUtil.PublicMediaURLRenderergetCurrentPublicMediaURLRenderer()static MediaUtil.SecureMediaURLRenderergetCurrentSecureMediaURLRenderer()static java.lang.StringgetFileExtension(java.lang.String filename)Returns the file name extension (lowercase) or, if no '.' is found, the whole file name (without case change).static java.lang.StringgetLocalMediaWebRootUrl()Returns local media web URL root URL.static java.io.FilegetLocalStorageDataDir()static java.util.List<java.io.File>getLocalStorageReplicationDirs()Reads directories defined in media.replication.dirs.static java.io.FilegetMediaReadDir()Returns the media read directory.static java.lang.StringgetSystemDir()static java.io.FilegetTenantMediaReadDir()Same asgetMediaReadDir()but including the current tenant subdirectory.static booleanisCurrentRequestSSLModeEnabled()static booleanisFileNamePrettyURLCompatible(java.lang.String realFileName)static booleanisZipRelatedMime(java.lang.String mime)Deprecated, for removal: This API element is subject to removal in a future version.since ages - useMimeService.isZipRelatedMime(String)instead.static java.lang.StringnormalizeRealFileName(java.lang.String realFileName)static java.lang.StringremoveFileExtension(java.lang.String fileName)static java.lang.StringremoveLeadingFileSepIfNeeded(java.lang.String path)Removes leading separator from the path if exists.static java.lang.StringremoveTrailingFileSepIfNeeded(java.lang.String path)Removes trailing separator from the path if it exists.static voidsetCurrentPublicMediaURLRenderer(MediaUtil.PublicMediaURLRenderer renderer)static voidsetCurrentRequestSSLModeEnabled(boolean enabled)static voidsetCurrentSecureMediaURLRenderer(MediaUtil.SecureMediaURLRenderer renderer)static voidunsetCurrentPublicMediaURLRenderer()static voidunsetCurrentRequestSSLModeEnabled()static voidunsetCurrentSecureMediaURLRenderer()
-
-
-
Field Detail
-
URL_IS_EMPTY
public static final java.lang.String URL_IS_EMPTY
If the URL contains this string, the URL is empty. Use empty string or null. This string is put into URL, when the data is removed. BEWARE: Oracle converts empty strings to null.
-
URL_HAS_DATA
public static final java.lang.String URL_HAS_DATA
- See Also:
- Constant Field Values
-
MEDIA_DATA_DIRS
public static final java.lang.String MEDIA_DATA_DIRS
- See Also:
- Constant Field Values
-
MEDIA_READ_DIR
public static final java.lang.String MEDIA_READ_DIR
- See Also:
- Constant Field Values
-
DUMMY_FILE_NAME
public static final java.lang.String DUMMY_FILE_NAME
- See Also:
- Constant Field Values
-
FILE_SEP
public static final java.lang.String FILE_SEP
- See Also:
- Constant Field Values
-
-
Method Detail
-
isCurrentRequestSSLModeEnabled
public static boolean isCurrentRequestSSLModeEnabled()
-
setCurrentRequestSSLModeEnabled
public static void setCurrentRequestSSLModeEnabled(boolean enabled)
-
unsetCurrentRequestSSLModeEnabled
public static void unsetCurrentRequestSSLModeEnabled()
-
setCurrentSecureMediaURLRenderer
public static void setCurrentSecureMediaURLRenderer(MediaUtil.SecureMediaURLRenderer renderer)
-
unsetCurrentSecureMediaURLRenderer
public static void unsetCurrentSecureMediaURLRenderer()
-
getCurrentSecureMediaURLRenderer
public static MediaUtil.SecureMediaURLRenderer getCurrentSecureMediaURLRenderer()
-
setCurrentPublicMediaURLRenderer
public static void setCurrentPublicMediaURLRenderer(MediaUtil.PublicMediaURLRenderer renderer)
-
unsetCurrentPublicMediaURLRenderer
public static void unsetCurrentPublicMediaURLRenderer()
-
getCurrentPublicMediaURLRenderer
public static MediaUtil.PublicMediaURLRenderer getCurrentPublicMediaURLRenderer()
-
isZipRelatedMime
@Deprecated(since="ages", forRemoval=true) public static boolean isZipRelatedMime(java.lang.String mime)Deprecated, for removal: This API element is subject to removal in a future version.since ages - useMimeService.isZipRelatedMime(String)instead.Checks whether provided mime string is zip archive related.
-
assembleSecureMediaURL
@Nullable public static java.lang.String assembleSecureMediaURL(MediaSource media)
-
assemblePublicMediaURL
@Nullable public static java.lang.String assemblePublicMediaURL(java.lang.String rawUrl)
-
getMediaReadDir
public static final java.io.File getMediaReadDir()
Returns the media read directory. If not set in the configuration, a temporary directory will be returned.- Returns:
- media read directory
- See Also:
getTenantMediaReadDir()
-
getTenantMediaReadDir
public static final java.io.File getTenantMediaReadDir()
Same asgetMediaReadDir()but including the current tenant subdirectory.- Returns:
- media read directory including tenant subdirectory
- See Also:
getMediaReadDir()
-
getLocalStorageReplicationDirs
public static java.util.List<java.io.File> getLocalStorageReplicationDirs()
Reads directories defined in media.replication.dirs. This method is called from getDataDirs when FILE mode is set
-
getLocalStorageDataDir
public static java.io.File getLocalStorageDataDir()
-
composeOrGetParent
public static java.io.File composeOrGetParent(java.io.File parent, java.lang.String child)Builds the file from parent file and child pathname which can be directory or file. If child is blank or null simply parent is returned.
-
getSystemDir
public static java.lang.String getSystemDir()
-
copy
public static long copy(java.io.InputStream is, java.io.OutputStream os) throws java.io.IOExceptionCopy the data from the Inputstream to the Outputstream. The Outputstream will always be closed after. Not the Inputstream- Parameters:
is- the Inputstreamos- the Outputstream- Returns:
- how many bytes where copied
- Throws:
java.io.IOException- when an error in the inputstream occurs; an error in the outputstream will be catched and printed to the commandline
-
copy
public static long copy(java.io.InputStream is, java.io.OutputStream os, boolean closeOutputStream) throws java.io.IOExceptionCopy the data from the Inputstream to the Outputstream.- Parameters:
is- the Inputstreamos- the OutputstreamcloseOutputStream- set to false if the Outputstream should not be closed afterwards.- Returns:
- how many bytes where copied
- Throws:
java.io.IOException- when an error in the inputstream occurs; an error in the outputstream will be catched and printed to the commandline
-
copy
public static long copy(java.io.InputStream is, java.util.Collection<java.io.OutputStream> os) throws java.io.IOExceptionCopy the data from the Inputstream to a Collection of Outputstreams. The Outputstreams will always be closed after. Not the Inputstream- Parameters:
is- the Inputstreamos- a Collection of Outputstreams- Returns:
- how many bytes where copied
- Throws:
java.io.IOException- when an error in the inputstream occurs; an error in the outputstreams will be catched and printed to the commandline
-
copy
public static long copy(java.io.InputStream is, java.util.Collection<java.io.OutputStream> outStreams, boolean closeOutputStreams) throws java.io.IOExceptionCopy the data from the InputStream to a Collection of OutputStreams. The OutputStreams will only be closed after if closeOutputStream is set to true. Not the InputStream- Parameters:
is- the InputStreamoutStreams- a Collection of OutputStreamscloseOutputStreams- set to false if the OutputStream should not be closed afterwards.- Returns:
- how many bytes where copied
- Throws:
java.io.IOException- when an error in the input stream occurs; an error in the output streams will be caught and printed to the command line
-
getLocalMediaWebRootUrl
public static java.lang.String getLocalMediaWebRootUrl()
Returns local media web URL root URL. By default: /medias.
-
appendFileNameToDirName
public static java.lang.String appendFileNameToDirName(java.lang.String dirname, java.lang.String filename)
-
getFileExtension
public static final java.lang.String getFileExtension(java.lang.String filename)
Returns the file name extension (lowercase) or, if no '.' is found, the whole file name (without case change).- Parameters:
filename- the file name to get extension from
-
normalizeRealFileName
public static java.lang.String normalizeRealFileName(java.lang.String realFileName)
-
isFileNamePrettyURLCompatible
public static boolean isFileNamePrettyURLCompatible(java.lang.String realFileName)
-
concatDirectoryWithFolder
public static java.io.File concatDirectoryWithFolder(java.io.File dir, MediaFolder subFolder)Concatenates given directory with given folder. Extracts the relative path from folder and adds it to the directory.- Parameters:
dir- directorysubFolder- folder whose path will be added to directory- Returns:
- new concatenated directory
- Since:
- 3.1-u4
-
addTrailingFileSepIfNeeded
public static java.lang.String addTrailingFileSepIfNeeded(java.lang.String path)
Adds the trailing file separator to the path if it doesn't contain one already.- Parameters:
path- the path- Returns:
- modified path or empty string if path is null or empty
-
removeTrailingFileSepIfNeeded
public static java.lang.String removeTrailingFileSepIfNeeded(java.lang.String path)
Removes trailing separator from the path if it exists.- Parameters:
path- the path- Returns:
- modified path
-
removeLeadingFileSepIfNeeded
public static java.lang.String removeLeadingFileSepIfNeeded(java.lang.String path)
Removes leading separator from the path if exists.- Parameters:
path- the path- Returns:
- modified path
-
addLeadingFileSepIfNeeded
public static java.lang.String addLeadingFileSepIfNeeded(java.lang.String path)
Adds the leading file separator to the path if it doesn't contain one already.- Parameters:
path- the path- Returns:
- modified path or empty string if path is null or empty
-
copyMediaData
@Deprecated(since="ages", forRemoval=true) public static void copyMediaData(Media src, Media tgt)Deprecated, for removal: This API element is subject to removal in a future version.
-
removeFileExtension
public static java.lang.String removeFileExtension(java.lang.String fileName)
-
-