@Service(value="blFileService") public class BroadleafFileServiceImpl extends Object implements BroadleafFileService
FileServiceProvider
implementations.
This service can be used by any component that needs to write files to an area shared by multiple application servers.
For example usage, see SiteMapGenerator
. The Broadleaf CMS module also uses this component to load, store, and
manipulate images for the file-system.
Generally, the process to create a new asset in the shared file system is ...
1. Call initializeWorkArea() to get a temporary directory
2. Create files, directories, etc. using the FileWorkArea.filePathLocation
as the root directory.
3. Once your file processing is complete, call #addOrUpdateResources(FileWorkArea, FileApplicationType)
to
4. Call #closeWorkArea()
to clear out the temporary filesModifier and Type | Field and Description |
---|---|
protected FileServiceProvider |
defaultFileServiceProvider |
protected BroadleafFileServiceExtensionManager |
extensionManager |
protected String |
fileServiceClasspathDirectory |
protected List<FileServiceProvider> |
fileServiceProviders |
protected int |
maxGeneratedDirectoryDepth |
protected String |
tempFileSystemBaseDirectory |
Constructor and Description |
---|
BroadleafFileServiceImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addOrUpdateResource(FileWorkArea workArea,
File file,
boolean removeFilesFromWorkArea)
Takes in a temporary work area and a single File and copies that files to
the configured FileProvider's permanent storage.
|
String |
addOrUpdateResourceForPath(FileWorkArea workArea,
File file,
boolean removeFilesFromWorkArea)
Takes in a temporary work area and a single File and copies that files to
the configured FileProvider's permanent storage.
|
void |
addOrUpdateResources(FileWorkArea workArea,
boolean removeFilesFromWorkArea)
Takes in a temporary work area and copies all of the files to the configured FileProvider's permanent storage.
|
void |
addOrUpdateResources(FileWorkArea workArea,
List<File> files,
boolean removeFilesFromWorkArea)
Takes in a temporary work area and a list of Files and copies them to
the configured FileProvider's permanent storage.
|
List<String> |
addOrUpdateResourcesForPaths(FileWorkArea workArea,
boolean removeFilesFromWorkArea)
Takes in a temporary work area and copies all of the files to the configured FileProvider's permanent storage.
|
List<String> |
addOrUpdateResourcesForPaths(FileWorkArea workArea,
List<File> files,
boolean removeFilesFromWorkArea)
Takes in a temporary work area and a list of Files and copies them to
the configured FileProvider's permanent storage.
|
protected void |
buildFileList(File file,
Collection<File> fileList)
Adds the file to the passed in Collection.
|
protected String |
buildThreadIdString() |
protected void |
checkFiles(FileWorkArea workArea,
List<File> fileList) |
boolean |
checkForResourceOnClassPath(String name)
Returns true if the resource is available on the classpath.
|
void |
closeWorkArea(FileWorkArea fwArea)
Closes the passed in work area.
|
protected String |
getBaseDirectory(boolean skipSite)
Returns the baseDirectory for writing and reading files as the property assetFileSystemPath if it
exists or java.tmp.io if that property has not been set.
|
InputStream |
getClasspathResource(String name)
Allows assets to be included in the Java classpath.
|
FileServiceProvider |
getDefaultFileServiceProvider() |
List<FileServiceProvider> |
getFileServiceProviders() |
File |
getLocalResource(String resourceName)
Checks for a resource in the temporary directory of the file-system.
|
protected File |
getLocalResource(String resourceName,
boolean skipSite) |
int |
getMaxGeneratedDirectoryDepth() |
File |
getResource(String name)
Returns a File representing the passed in name.
|
File |
getResource(String name,
Long localTimeout)
Returns a File representing the resource.
|
File |
getSharedLocalResource(String resourceName)
Checks for a resource in the temporary directory of the file-system.
|
protected String |
getTempDirectory(String baseDirectory)
Returns a directory that is unique for this work area.
|
String |
getTempFileSystemBaseDirectory() |
FileWorkArea |
initializeWorkArea()
Create a file work area that can be used for further operations.
|
protected org.springframework.core.io.ClassPathResource |
lookupResourceOnClassPath(String name) |
protected void |
removeLocalCacheFiles(String resourceName,
String baseDirectory) |
boolean |
removeResource(String resourceName)
Removes the resource matching the passed in file name from the FileProvider
|
protected FileServiceProvider |
selectFileServiceProvider()
Returns the FileServiceProvider that can handle the passed in application type.
|
void |
setDefaultFileServiceProvider(FileServiceProvider defaultFileServiceProvider) |
void |
setFileServiceProviders(List<FileServiceProvider> fileServiceProviders) |
void |
setMaxGeneratedDirectoryDepth(int maxGeneratedDirectoryDepth) |
void |
setTempFileSystemBaseDirectory(String tempFileSystemBaseDirectory) |
protected List<FileServiceProvider> fileServiceProviders
protected FileServiceProvider defaultFileServiceProvider
@Value(value="${file.service.temp.file.base.directory}") protected String tempFileSystemBaseDirectory
@Value(value="${asset.server.max.generated.file.system.directories}") protected int maxGeneratedDirectoryDepth
@Value(value="${asset.server.file.classpath.directory}") protected String fileServiceClasspathDirectory
protected BroadleafFileServiceExtensionManager extensionManager
public FileWorkArea initializeWorkArea()
initializeWorkArea
in interface BroadleafFileService
public void closeWorkArea(FileWorkArea fwArea)
closeWorkArea
in interface BroadleafFileService
Work
- Areapublic File getResource(String name)
BroadleafFileService
getResource
in interface BroadleafFileService
name
- - fully qualified path to the resourcepublic File getLocalResource(String resourceName)
BroadleafFileService
getLocalResource
in interface BroadleafFileService
public File getSharedLocalResource(String resourceName)
BroadleafFileService
getSharedLocalResource
in interface BroadleafFileService
public File getResource(String name, Long localTimeout)
BroadleafFileService
BroadleafFileService.getResource(String)
.
If the timeout parameter is null then if the resource exists locally, it will be returned.getResource
in interface BroadleafFileService
name
- - fully qualified path to the resourcelocalTimeout
- - timeframe that the temporary file is considered validpublic boolean checkForResourceOnClassPath(String name)
BroadleafFileService
checkForResourceOnClassPath
in interface BroadleafFileService
protected org.springframework.core.io.ClassPathResource lookupResourceOnClassPath(String name)
public InputStream getClasspathResource(String name)
BroadleafFileService
getClasspathResource
in interface BroadleafFileService
name
- - fully qualified path to the resourcepublic boolean removeResource(String resourceName)
removeResource
in interface BroadleafFileService
resourceName
- - fully qualified path to the resourcepublic void addOrUpdateResource(FileWorkArea workArea, File file, boolean removeFilesFromWorkArea)
Takes in a temporary work area and a single File and copies that files to the configured FileProvider's permanent storage.
Passing in removeFilesFromWorkArea to true allows for more efficient file processing when using a local file system as it performs a move operation instead of a copy.
addOrUpdateResource
in interface BroadleafFileService
public String addOrUpdateResourceForPath(FileWorkArea workArea, File file, boolean removeFilesFromWorkArea)
Takes in a temporary work area and a single File and copies that files to the configured FileProvider's permanent storage.
Passing in removeFilesFromWorkArea to true allows for more efficient file processing when using a local file system as it performs a move operation instead of a copy.
addOrUpdateResourceForPath
in interface BroadleafFileService
workArea
- the work area from the given filefile
- the file to uploadremoveFilesFromWorkArea
- whether or not the given file should be removed from workArea when it
has been copiedpublic void addOrUpdateResources(FileWorkArea workArea, boolean removeFilesFromWorkArea)
Takes in a temporary work area and copies all of the files to the configured FileProvider's permanent storage.
Passing in removeFilesFromWorkArea to true allows for more efficient file processing when using a local file system as it performs a move operation instead of a copy.
addOrUpdateResources
in interface BroadleafFileService
public List<String> addOrUpdateResourcesForPaths(FileWorkArea workArea, boolean removeFilesFromWorkArea)
BroadleafFileService
Takes in a temporary work area and copies all of the files to the configured FileProvider's permanent storage.
Passing in removeFilesFromWorkArea to true allows for more efficient file processing when using a local file system as it performs a move operation instead of a copy.
addOrUpdateResourcesForPaths
in interface BroadleafFileService
public void addOrUpdateResources(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea)
BroadleafFileService
Takes in a temporary work area and a list of Files and copies them to the configured FileProvider's permanent storage.
Passing in removeFilesFromWorkArea to true allows for more efficient file processing when using a local file system as it performs a move operation instead of a copy.
addOrUpdateResources
in interface BroadleafFileService
public List<String> addOrUpdateResourcesForPaths(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea)
BroadleafFileService
Takes in a temporary work area and a list of Files and copies them to the configured FileProvider's permanent storage.
Passing in removeFilesFromWorkArea to true allows for more efficient file processing when using a local file system as it performs a move operation instead of a copy.
addOrUpdateResourcesForPaths
in interface BroadleafFileService
workArea
- the work area for the given filesfiles
- the files to copy to the provider's permanent storageremoveFilesFromWorkArea
- whether or not the given files hsould be removed from the given workArea
after they are uploadedprotected void removeLocalCacheFiles(String resourceName, String baseDirectory)
protected FileServiceProvider selectFileServiceProvider()
applicationType
- protected void checkFiles(FileWorkArea workArea, List<File> fileList)
protected String getBaseDirectory(boolean skipSite)
protected String getTempDirectory(String baseDirectory)
protected String buildThreadIdString()
protected void buildFileList(File file, Collection<File> fileList)
file
- fileList
- public String getTempFileSystemBaseDirectory()
public void setTempFileSystemBaseDirectory(String tempFileSystemBaseDirectory)
public List<FileServiceProvider> getFileServiceProviders()
public void setFileServiceProviders(List<FileServiceProvider> fileServiceProviders)
public int getMaxGeneratedDirectoryDepth()
public void setMaxGeneratedDirectoryDepth(int maxGeneratedDirectoryDepth)
public FileServiceProvider getDefaultFileServiceProvider()
public void setDefaultFileServiceProvider(FileServiceProvider defaultFileServiceProvider)
Copyright © 2022. All rights reserved.