org.broadleafcommerce.common.file.service
Class FileSystemFileServiceProvider

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

@Service(value="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 Summary
protected  String baseDirectory
           
protected  String fileSystemBaseDirectory
           
protected  int maxGeneratedDirectoryDepth
           
 
Constructor Summary
FileSystemFileServiceProvider()
           
 
Method Summary
 void addOrUpdateResources(FileWorkArea area, List<File> files, boolean removeResourcesFromWorkArea)
          Takes in a work area and application type and moves all of the files to the configured FileProvider.
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.
protected  String getBaseDirectory()
          Returns a base directory (unique for each tenant in a multi-tenant installation.
 File getResource(String name)
          Returns a File representing the passed in name.
 File getResource(String name, FileApplicationType applicationType)
          Returns a File representing the passed in name and application type.
protected  String getSiteDirectory(String baseDirectory)
          Creates a unique directory on the file system for each site.
 boolean removeResource(String name)
          Removes the resource from the file service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileSystemBaseDirectory

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

maxGeneratedDirectoryDepth

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

baseDirectory

protected String baseDirectory
Constructor Detail

FileSystemFileServiceProvider

public FileSystemFileServiceProvider()
Method Detail

getResource

public File getResource(String name)
Description copied from interface: FileServiceProvider
Returns a File representing the passed in name.

Specified by:
getResource in interface FileServiceProvider
Parameters:
name - - fully qualified path to the resource
Returns:

getResource

public File getResource(String name,
                        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:
name - - fully qualified path to the resource
applicationType - - applicationType
Returns:

addOrUpdateResources

public void addOrUpdateResources(FileWorkArea area,
                                 List<File> files,
                                 boolean removeResourcesFromWorkArea)
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

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()
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:
The - starting directory for local files which must end with a '/';


Copyright © 2013. All Rights Reserved.