Class FileSystemFileServiceProvider

java.lang.Object
org.broadleafcommerce.common.file.service.FileSystemFileServiceProvider
All Implemented Interfaces:
FileServiceProvider

@Service("blDefaultFileServiceProvider") public class FileSystemFileServiceProvider extends Object implements FileServiceProvider
Default implementation of FileServiceProvider that uses the local file system to store files created by Broadleaf components.

This Provider can only be used in production systems that run on a single server or those that have a shared filesystem mounted to the application servers.

Author:
bpolster
  • Field Details

    • fileSystemBaseDirectory

      @Value("${asset.server.file.system.path}") protected String fileSystemBaseDirectory
    • maxGeneratedDirectoryDepth

      @Value("${asset.server.max.generated.file.system.directories}") protected int maxGeneratedDirectoryDepth
    • extensionManager

      protected BroadleafFileServiceExtensionManager extensionManager
    • baseDirectory

      protected String baseDirectory
  • Constructor Details

    • FileSystemFileServiceProvider

      public FileSystemFileServiceProvider()
  • Method Details

    • getResource

      public File getResource(String url)
      Description copied from interface: FileServiceProvider
      Returns a File representing the passed in url. All separators in the given url should be in URL-separator form meaning '/' rather than '\' (like on Windows).
      Specified by:
      getResource in interface FileServiceProvider
      Parameters:
      url - - fully qualified path to the resource
      Returns:
    • getResource

      public File getResource(String url, FileApplicationType applicationType)
      Description copied from interface: FileServiceProvider
      Returns a File representing the passed in name and application type. Providers may choose to cache certain FileApplicationType(s) locally rather than retrieve them from a remote source.
      Specified by:
      getResource in interface FileServiceProvider
      Parameters:
      url - - the URL-representation of the resource. This means that paths should always have / separators rather than system-specific values
      applicationType - applicationType
      Returns:
      a File to the
    • addOrUpdateResources

      @Deprecated public void addOrUpdateResources(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea)
      Deprecated.
      Description copied from interface: FileServiceProvider
      Takes in a work area and application type and moves all of the files to the configured FileProvider.
      Specified by:
      addOrUpdateResources in interface FileServiceProvider
      files - the files that should be copied
    • addOrUpdateResourcesForPaths

      public List<String> addOrUpdateResourcesForPaths(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea)
      Description copied from interface: FileServiceProvider
      Adds all of the given files and returns the resource names of all of them suitable for invoking FileServiceProvider.getResource(String) and/or FileServiceProvider.removeResource(String)
      Specified by:
      addOrUpdateResourcesForPaths in interface FileServiceProvider
      Returns:
      the resource names for each file that was uploaded. The resource names that are returned should be for each file in file
    • removeResource

      public boolean removeResource(String name)
      Description copied from interface: FileServiceProvider
      Removes the resource from the file service.
      Specified by:
      removeResource in interface FileServiceProvider
      Parameters:
      name - - fully qualified path to the resource
      Returns:
      true if the resource was removed
    • buildResourceName

      protected String buildResourceName(String url)
      Stores the file on the file-system by performing an MD5 hash of the the passed in fileName

      To ensure that files can be stored and accessed in an efficient manner, the system creates directories based on the characters in the hash.

      For example, if the URL is /product/myproductimage.jpg, then the MD5 would be 35ec52a8dbd8cf3e2c650495001fe55f resulting in the following file on the filesystem {assetFileSystemPath}/35/ec/myproductimage.jpg.

      The hash for the filename will include a beginning slash before performing the MD5. This is done largely for backward compatibility with similar functionality in BLC 3.0.0.

      This algorithm has the following benefits: - Efficient file-system storage with - Balanced tree of files that supports 10 million files

      If support for more files is needed, implementors should consider one of the following approaches: 1. Overriding the maxGeneratedFileSystemDirectories property from its default of 2 to 3 2. Overriding this method to introduce an alternate approach

      Parameters:
      url - The URL used to represent an asset for which a name on the fileSystem is desired.
      Returns:
    • getBaseDirectory

      protected String getBaseDirectory(boolean skipSite)
      Returns a base directory (unique for each tenant in a multi-tenant installation. Creates the directory if it does not already exist.
    • getSiteDirectory

      protected String getSiteDirectory(String baseDirectory)
      Creates a unique directory on the file system for each site. Each site may be in one of 255 base directories. This model efficiently supports up to 65,000 sites served from a single file system based on most OS systems ability to quickly access files as long as there are not more than 255 directories.
      Parameters:
      baseDirectory - The starting directory for local files which must end with a '/';