Class ImageMagickMediaConversionStrategy

    • 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
    • Constructor Detail

      • ImageMagickMediaConversionStrategy

        public ImageMagickMediaConversionStrategy()
    • Method Detail

      • 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, the MediaConversionService is passed.
        input - the local input file
        target - the output file
        format - 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 given 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.
        Parameters:
        format - the targeted format
        input - original media
        Returns:
        the targeted file extensions never null.
        Throws:
        java.io.IOException - if a technical error occurs
        MediaConversionException - 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, the MediaConversionService is passed.
        input - the input file
        output - the output file
        format - 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, the MediaConversionService is passed.
        input - the absolute path to input file
        output - the absolute path to output file
        format - 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 given commandPart and return it's new value, if there are mediaAddOns set on the given ConversionMediaFormatModel.
        Parameters:
        mediaConversionService - reference to the MediaConversionService to use for File retrieval
        commandPart - the command part to manipulate
        format - the ConversionMediaFormatModel 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 local File for the given MediaModel or throws a IOException if no such file is accessible.
        Parameters:
        media - the MediaModel in question.
        Returns:
        a local (readable) File representation for the given MediaModel.
        Throws:
        java.io.IOException - if no such file is accessible.
      • setMimeMappingStrategy

        public void setMimeMappingStrategy​(MimeMappingStrategy mimeMappingStrategy)
      • setImageMagickService

        public void setImageMagickService​(ImageMagickService magickService)
      • setMediaService

        public void setMediaService​(MediaService mediaService)