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}"
(where X denotes the position within the media add on list (starting with 1!)) will e replaced by the
absolute path names of these medias.| Modifier and Type | Field and 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).
|
EMBEDDED_CONFIG_DIR, IMAGEMAGICK_CONFIGURATION_DIRECTORY| Constructor and Description |
|---|
ImageMagickMediaConversionStrategy() |
| Modifier and Type | Method and 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.
|
protected void |
convert(MediaConversionService mediaConversionService,
java.io.File input,
java.io.File target,
ConversionMediaFormatModel format)
Does the actual conversion based.
|
MediaModel |
convert(MediaConversionService mediaConversionService,
MediaModel input,
ConversionMediaFormatModel format)
Converts the given
parent media to the given format. |
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 given
commandPart and return it's new value, if there are mediaAddOns set
on the given ConversionMediaFormatModel. |
java.io.File |
retrieveFile(MediaModel media)
Locates a local
File for the given MediaModel or throws a IOException 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.
|
getConfigurationDirectory, getConfigurationService, getTmpDir, setConfigurationDirectory, setConfigurationService, setTmpDirpublic static final java.lang.String CONVERSION_INPUT_TOKEN
public static final java.lang.String CONVERSION_OUTPUT_TOKEN
public static final java.lang.String CONVERSION_ADDON_TOKEN
X' will be replaced by the addOn's media index in the list of addOn medias.public MediaModel convert(MediaConversionService mediaConversionService, MediaModel input, ConversionMediaFormatModel format) throws MediaConversionException
parent media to the given format.convert in interface MediaConversionStrategymediaConversionService - to avoid cyclic IoC errors, the MediaConversionService is passed.input - the media to convertformat - the format to convert toMediaConversionException - if the conversion could not be processed due to a technical reasonMediaConversionStrategy.convert(MediaConversionService, MediaModel, ConversionMediaFormatModel)protected void convert(MediaConversionService mediaConversionService, java.io.File input, java.io.File target, ConversionMediaFormatModel format) throws java.io.IOException
mediaConversionService - to avoid cyclic IoC errors, the MediaConversionService is passed.input - the local input filetarget - the output fileformat - the conversion format specificationjava.io.IOException - on any conversion errorprotected java.lang.String targetFileExtension(ConversionMediaFormatModel format, MediaModel input) throws java.io.IOException, MediaConversionException
ConversionMediaFormatModel 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.format - the targeted formatinput - original medianull.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.protected java.util.List<java.lang.String> buildCommand(MediaConversionService mediaConversionService, java.io.File input, java.io.File output, ConversionMediaFormatModel format) throws java.io.IOException
mediaConversionService - to avoid cyclic IoC errors, the MediaConversionService is passed.input - the input fileoutput - the output fileformat - the conversion specification.java.io.IOException - if a technical error occursDefaultImageMagickService.convert(List)protected java.util.List<java.lang.String> buildCommand(MediaConversionService mediaConversionService, java.lang.String input, java.lang.String output, ConversionMediaFormatModel format) throws java.io.IOException
mediaConversionService - to avoid cyclic IoC errors, the MediaConversionService is passed.input - the absolute path to input fileoutput - the absolute path to output fileformat - the conversion specification.java.io.IOException - if a technical error occursDefaultImageMagickService.convert(List)protected java.lang.String replaceAddOns(MediaConversionService mediaConversionService, java.lang.String commandPart, ConversionMediaFormatModel format) throws java.io.IOException
commandPart and return it's new value, if there are mediaAddOns set
on the given ConversionMediaFormatModel.mediaConversionService - reference to the MediaConversionService to use for File retrievalcommandPart - the command part to manipulateformat - the ConversionMediaFormatModel specifying the mediaAddOnsjava.io.IOException - if a mediaAddOn cannot be accessedpublic java.io.File retrieveFile(MediaModel media) throws java.io.IOException
File for the given MediaModel or throws a IOException if no such file is
accessible.media - the MediaModel in question.MediaModel.java.io.IOException - if no such file is accessible.public MimeMappingStrategy getMimeMappingStrategy()
public void setMimeMappingStrategy(MimeMappingStrategy mimeMappingStrategy)
public ConvertedMediaCreationStrategy getConvertedMediaCreationStrategy()
public void setConvertedMediaCreationStrategy(ConvertedMediaCreationStrategy service)
public ImageMagickService getImageMagickService()
public void setImageMagickService(ImageMagickService magickService)
public MediaService getMediaService()
public void setMediaService(MediaService mediaService)
Copyright © 2018 SAP SE. All Rights Reserved.