Class DoNothingImageOperationService

java.lang.Object
com.broadleafcommerce.asset.service.image.DoNothingImageOperationService
All Implemented Interfaces:
ImageOperationService

public class DoNothingImageOperationService extends Object implements ImageOperationService
A backup ImageOperationService implementation that does nothing.

Since some clients may not want to perform image operations, the presence of this service avoids introducing a hard requirement on the default implementation, ImageMagickImageOperationService, which introduces a requirement on the ImageMagick commandline utility.

Author:
Samarth Dhruva (samarthd)
  • Constructor Details

    • DoNothingImageOperationService

      public DoNothingImageOperationService()
  • Method Details

    • applyEffectsAndStoreModifiedFile

      public File applyEffectsAndStoreModifiedFile(File file, String targetUrl, org.springframework.util.MultiValueMap<String,String> imageEffectsTags)
      Description copied from interface: ImageOperationService
      Apply the effects to the file and store the new file to the targetUrl
      Specified by:
      applyEffectsAndStoreModifiedFile in interface ImageOperationService
      Parameters:
      file - the image file to apply effects
      targetUrl - the target url to save file
      imageEffectsTags - the image effects
      Returns:
      the new saved file
    • applyEffectsAndStoreModifiedResource

      public ResourceWithMetadata applyEffectsAndStoreModifiedResource(ResourceWithMetadata imageResource, String targetUrl, org.springframework.util.MultiValueMap<String,String> imageEffectsTags)
      Description copied from interface: ImageOperationService
      Apply the effects to the imageResource and store the new resource to the targetUrl
      Specified by:
      applyEffectsAndStoreModifiedResource in interface ImageOperationService
      Parameters:
      imageResource - the image resource to apply effects
      targetUrl - the target url to save file
      imageEffectsTags - the image effects
      Returns:
      the new saved resource
    • applyEffects

      public InputStream applyEffects(File file, org.springframework.util.MultiValueMap<String,String> imageEffectsTags)
      Description copied from interface: ImageOperationService
      Apply the effects to the file and save it to the temp file. Note: The temp file will be deleted on close. StandardOpenOption.DELETE_ON_CLOSE
      Specified by:
      applyEffects in interface ImageOperationService
      Parameters:
      file - the image file to apply effects
      imageEffectsTags - the image effects
      Returns:
      the InputStream to the new temp file.
    • applyEffects

      public InputStream applyEffects(ResourceWithMetadata imageResource, org.springframework.util.MultiValueMap<String,String> imageEffectsTags)
      Description copied from interface: ImageOperationService
      Apply the effects to the imageResource and save it to the temp file. Note: The temp file will be deleted on close. StandardOpenOption.DELETE_ON_CLOSE
      Specified by:
      applyEffects in interface ImageOperationService
      Parameters:
      imageResource - the image resource to apply effects
      imageEffectsTags - the image effects
      Returns:
      the InputStream to the new temp file.
    • isValidImageEffectTags

      public boolean isValidImageEffectTags(org.springframework.util.MultiValueMap<String,String> imageEffectsTags)
      Description copied from interface: ImageOperationService
      Check that the imageEffectsTags is valid
      Specified by:
      isValidImageEffectTags in interface ImageOperationService
      Parameters:
      imageEffectsTags - the image effects
      Returns:
      false if imageEffectsTags contains the effect names which is not configured by broadleaf.image.availableEffects property or NamedOperation and true otherwise
    • optimizeImage

      public InputStream optimizeImage(org.springframework.web.multipart.MultipartFile toOptimize)
      Description copied from interface: ImageOperationService
      Optimizes a GIF, PNG, or JPEG in an attempt to reduce its size.

      If toOptimize is a GIF, PNG, or JPEG, it will be copied to a temporary file, optimized, and its stream will be returned. When this stream is closed, the temporary file will be deleted, as documented by StandardOpenOption.DELETE_ON_CLOSE.

      The given file itself is not modified, as the optimization is applied to a copy.

      If toOptimize was not a GIF, PNG, or JPEG, the returned value will just be its unmodified stream. The temp file will be deleted on close. StandardOpenOption.DELETE_ON_CLOSE

      Specified by:
      optimizeImage in interface ImageOperationService
      Parameters:
      toOptimize - the file to be optimized
      Returns:
      the InputStream of the optimized file, or of the unmodified file if not a GIF, PNG, or JPEG
    • optimizeImageBatch

      public Map<String,File> optimizeImageBatch(Map<String,File> imagesToOptimize)
      Description copied from interface: ImageOperationService
      This method will batch-optimize any GIF, PNG, and JPEG image files in the input map in an attempt to reduce their sizes.

      This operation will write over the given files themselves.

      Specified by:
      optimizeImageBatch in interface ImageOperationService
      Parameters:
      imagesToOptimize - a map of normalized URLs to files that should be optimized. The content type of the files will be determined purely by examining the URLs (key), and this will be used to determine whether the file is eligible for optimization.
      Returns:
      a map of the given URLs to the corresponding optimized files. Only files that were successfully optimized will be present in this result. While the resulting map will be a new instance, the instances of any keys/values will be the same as those that were supplied.
    • setNamedOperations

      public void setNamedOperations(List<NamedOperation> namedOperations)
      Description copied from interface: ImageOperationService
      Set the List of NamedOperation
      Specified by:
      setNamedOperations in interface ImageOperationService
      Parameters:
      namedOperations - the List of NamedOperation to set