Class ImageMagickMediaConversionStrategy
- java.lang.Object
-
- de.hybris.platform.mediaconversion.imagemagick.BasicImageMagickStrategy
-
- de.hybris.platform.mediaconversion.imagemagick.ImageMagickMediaConversionStrategy
-
- All Implemented Interfaces:
MediaConversionStrategy
public class ImageMagickMediaConversionStrategy extends BasicImageMagickStrategy implements MediaConversionStrategy
MediaConversionStrategy
backed by ImageMagick to do various image conversions.This
MediaConversionStrategy
takes the conversion string (ConversionMediaFormatModel.getConversion()
) and turns it to a image magick convert command line. The convert executable and input file (the original media's data) will be prepended to the command. The output file (which is a temporary file), will be appended to the command array. Input file and output file will not be included in the command array if you specify a{input}
or{output}
token in your conversion string. In the latter case these tokens will be replaced with the absolute file names of the input or output respectively.Additionally if there are
ConversionMediaFormatModel.getMediaAddOns()
present, occurrences of the "{addOn#X}" (whereX
denotes the position within the media add on list (starting with 1!)) will e replaced by the absolute path names of these medias.- See Also:
- ImageMagick, ImageMagick Command-line Processing
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONVERSION_ADDON_TOKEN
Token to be replaced with add on file names within the conversion command (if present).static java.lang.String
CONVERSION_INPUT_TOKEN
Token to be replaced with the conversions input file name within the conversion command (if present).static java.lang.String
CONVERSION_OUTPUT_TOKEN
Token to be replaced with the conversions output file name within the conversion command (if present).-
Fields inherited from class de.hybris.platform.mediaconversion.imagemagick.BasicImageMagickStrategy
EMBEDDED_CONFIG_DIR, IMAGEMAGICK_CONFIGURATION_DIRECTORY
-
-
Constructor Summary
Constructors Constructor Description ImageMagickMediaConversionStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<java.lang.String>
buildCommand(MediaConversionService mediaConversionService, java.io.File input, java.io.File output, ConversionMediaFormatModel format)
Build the imagemagick command to execute from the given input.protected java.util.List<java.lang.String>
buildCommand(MediaConversionService mediaConversionService, java.lang.String input, java.lang.String output, ConversionMediaFormatModel format)
Build the imagemagick command to execute from the given input.MediaModel
convert(MediaConversionService mediaConversionService, MediaModel input, ConversionMediaFormatModel format)
Converts the givenparent
media to the givenformat
.protected void
convert(MediaConversionService mediaConversionService, java.io.File input, java.io.File target, ConversionMediaFormatModel format)
Does the actual conversion based.ConvertedMediaCreationStrategy
getConvertedMediaCreationStrategy()
ImageMagickService
getImageMagickService()
MediaService
getMediaService()
MimeMappingStrategy
getMimeMappingStrategy()
protected java.lang.String
replaceAddOns(MediaConversionService mediaConversionService, java.lang.String commandPart, ConversionMediaFormatModel format)
Replaces all "{addOn#X}" occurrences in the givencommandPart
and return it's new value, if there are mediaAddOns set on the givenConversionMediaFormatModel
.java.io.File
retrieveFile(MediaModel media)
Locates a localFile
for the givenMediaModel
or throws aIOException
if no such file is accessible.void
setConvertedMediaCreationStrategy(ConvertedMediaCreationStrategy service)
void
setImageMagickService(ImageMagickService magickService)
void
setMediaService(MediaService mediaService)
void
setMimeMappingStrategy(MimeMappingStrategy mimeMappingStrategy)
protected java.lang.String
targetFileExtension(ConversionMediaFormatModel format, MediaModel input)
Returns the file extension for the targeted format.-
Methods inherited from class de.hybris.platform.mediaconversion.imagemagick.BasicImageMagickStrategy
getConfigurationDirectory, getConfigurationService, getTmpDir, setConfigurationDirectory, setConfigurationService, setTmpDir
-
-
-
-
Field Detail
-
CONVERSION_INPUT_TOKEN
public static final java.lang.String CONVERSION_INPUT_TOKEN
Token to be replaced with the conversions input file name within the conversion command (if present).- See Also:
- Constant Field Values
-
CONVERSION_OUTPUT_TOKEN
public static final java.lang.String CONVERSION_OUTPUT_TOKEN
Token to be replaced with the conversions output file name within the conversion command (if present).- See Also:
- Constant Field Values
-
CONVERSION_ADDON_TOKEN
public static final java.lang.String CONVERSION_ADDON_TOKEN
Token to be replaced with add on file names within the conversion command (if present). Note that the 'X
' will be replaced by the addOn's media index in the list of addOn medias.- See Also:
- Constant Field Values
-
-
Method Detail
-
convert
public MediaModel convert(MediaConversionService mediaConversionService, MediaModel input, ConversionMediaFormatModel format) throws MediaConversionException
Converts the givenparent
media to the givenformat
.- Specified by:
convert
in interfaceMediaConversionStrategy
- Parameters:
mediaConversionService
- to avoid cyclic IoC errors, theMediaConversionService
is passed.input
- the media to convertformat
- the format to convert to- Returns:
- a fresh created media in the given format
- Throws:
MediaConversionException
- if the conversion could not be processed due to a technical reason- See Also:
MediaConversionStrategy.convert(MediaConversionService, MediaModel, ConversionMediaFormatModel)
-
convert
protected void convert(MediaConversionService mediaConversionService, java.io.File input, java.io.File target, ConversionMediaFormatModel format) throws java.io.IOException
Does the actual conversion based.- Parameters:
mediaConversionService
- to avoid cyclic IoC errors, theMediaConversionService
is passed.input
- the local input filetarget
- the output fileformat
- the conversion format specification- Throws:
java.io.IOException
- on any conversion error
-
targetFileExtension
protected java.lang.String targetFileExtension(ConversionMediaFormatModel format, MediaModel input) throws java.io.IOException, MediaConversionException
Returns the file extension for the targeted format. If no mime type is set on the givenConversionMediaFormatModel
the file extension of the input mime type is used. If this does not lead to success, the file extension of the input medias URL is extracted. As a last fallback, the default file extension is returned.- Parameters:
format
- the targeted formatinput
- original media- Returns:
- the targeted file extensions never
null
. - Throws:
java.io.IOException
- if a technical error occursMediaConversionException
- if no file extension could be found for the mime type specified on the target format or (if no explicit mime type is given) if the file extension could not be extracted from the input's URL.
-
buildCommand
protected java.util.List<java.lang.String> buildCommand(MediaConversionService mediaConversionService, java.io.File input, java.io.File output, ConversionMediaFormatModel format) throws java.io.IOException
Build the imagemagick command to execute from the given input.- Parameters:
mediaConversionService
- to avoid cyclic IoC errors, theMediaConversionService
is passed.input
- the input fileoutput
- the output fileformat
- the conversion specification.- Returns:
- the command to execute (excluding the 'convert' executable).
- Throws:
java.io.IOException
- if a technical error occurs- See Also:
DefaultImageMagickService.convert(List)
-
buildCommand
protected java.util.List<java.lang.String> buildCommand(MediaConversionService mediaConversionService, java.lang.String input, java.lang.String output, ConversionMediaFormatModel format) throws java.io.IOException
Build the imagemagick command to execute from the given input.- Parameters:
mediaConversionService
- to avoid cyclic IoC errors, theMediaConversionService
is passed.input
- the absolute path to input fileoutput
- the absolute path to output fileformat
- the conversion specification.- Returns:
- the command to execute (excluding the 'convert' executable).
- Throws:
java.io.IOException
- if a technical error occurs- See Also:
DefaultImageMagickService.convert(List)
-
replaceAddOns
protected java.lang.String replaceAddOns(MediaConversionService mediaConversionService, java.lang.String commandPart, ConversionMediaFormatModel format) throws java.io.IOException
Replaces all "{addOn#X}" occurrences in the givencommandPart
and return it's new value, if there are mediaAddOns set on the givenConversionMediaFormatModel
.- Parameters:
mediaConversionService
- reference to theMediaConversionService
to use forFile
retrievalcommandPart
- the command part to manipulateformat
- theConversionMediaFormatModel
specifying the mediaAddOns- Returns:
- the manipulated command part
- Throws:
java.io.IOException
- if a mediaAddOn cannot be accessed
-
retrieveFile
public java.io.File retrieveFile(MediaModel media) throws java.io.IOException
Locates a localFile
for the givenMediaModel
or throws aIOException
if no such file is accessible.- Parameters:
media
- theMediaModel
in question.- Returns:
- a local (readable) File representation for the given
MediaModel
. - Throws:
java.io.IOException
- if no such file is accessible.
-
getMimeMappingStrategy
public MimeMappingStrategy getMimeMappingStrategy()
-
setMimeMappingStrategy
public void setMimeMappingStrategy(MimeMappingStrategy mimeMappingStrategy)
-
getConvertedMediaCreationStrategy
public ConvertedMediaCreationStrategy getConvertedMediaCreationStrategy()
-
setConvertedMediaCreationStrategy
public void setConvertedMediaCreationStrategy(ConvertedMediaCreationStrategy service)
-
getImageMagickService
public ImageMagickService getImageMagickService()
-
setImageMagickService
public void setImageMagickService(ImageMagickService magickService)
-
getMediaService
public MediaService getMediaService()
-
setMediaService
public void setMediaService(MediaService mediaService)
-
-