@Service(value="blStaticAssetService") public class StaticAssetServiceImpl extends Object implements StaticAssetService
| Modifier and Type | Field and Description |
|---|---|
protected String |
disabledFileExtensions |
protected boolean |
exceptionOnInvalidChar |
protected ImageArtifactProcessor |
imageArtifactProcessor |
protected char[] |
notAllowedCharsInFileName |
protected String |
replacementString |
protected boolean |
shouldAcceptNonImageAsset |
protected StaticAssetDao |
staticAssetDao |
protected StaticAssetMultiTenantExtensionManager |
staticAssetExtensionManager |
protected StaticAssetPathService |
staticAssetPathService |
protected StaticAssetStorageService |
staticAssetStorageService |
protected boolean |
storeAssetsOnFileSystem |
| Constructor and Description |
|---|
StaticAssetServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
StaticAsset |
addStaticAsset(StaticAsset staticAsset)
Add an asset outside of Broadleaf Admin.
|
protected String |
buildAssetURL(Map<String,String> assetProperties,
String originalFilename)
Will assemble the url from the passed in properties as
/{entityType}/{fileName}
/product/7001-ab12
|
String |
convertAssetPath(String assetPath,
String contextPath,
boolean secureRequest) |
protected StaticAsset |
createNonImageAsset(InputStream inputStream,
String fileName,
Map<String,String> properties)
Hook-point for implementors to add custom business logic for handling files that are non-images
|
StaticAsset |
createStaticAsset(InputStream inputStream,
String fileName,
long fileSize,
Map<String,String> properties)
Similar to
StaticAssetService.createStaticAssetFromFile(MultipartFile, Map) except not dependent upon an uploaded file from a
controller |
StaticAsset |
createStaticAssetFromFile(org.springframework.web.multipart.MultipartFile file,
Map<String,String> properties)
Used when uploading a file to Broadleaf.
|
void |
deleteStaticAsset(StaticAsset staticAsset)
Delete an asset outside of Broadleaf Admin.
|
StaticAsset |
findStaticAssetByFullUrl(String fullUrl) |
StaticAsset |
findStaticAssetById(Long id) |
Long |
findTotalStaticAssetCount() |
protected String |
generateFileName(int size)
Generates a filename as a set of Hex digits.
|
protected String |
getCountUrl(String fullUrl,
int count,
boolean legacyFormat)
Gets the count URL based on the original fullUrl.
|
protected String |
getFileExtension(String fileName) |
protected void |
getMimeType(InputStream inputStream,
String fileName,
StaticAsset newAsset) |
String |
getPrefixedStaticAssetUrl(String assetUrl)
Return a prefixed version of the given asset url, assuming a static asset url prefix is set
|
boolean |
getShouldAcceptNonImageAsset() |
String |
getStaticAssetEnvironmentSecureUrlPrefix() |
String |
getStaticAssetEnvironmentUrlPrefix() |
String |
getStaticAssetUrlPrefix() |
List<StaticAsset> |
readAllStaticAssets() |
void |
setShouldAcceptNonImageAsset(boolean accept) |
StaticAsset |
updateStaticAsset(StaticAsset staticAsset)
Update an asset outside of Broadleaf Admin.
|
void |
validateFileExtension(org.springframework.web.multipart.MultipartFile file) |
protected boolean |
validateFileName(String fileName) |
protected ImageArtifactProcessor imageArtifactProcessor
@Value(value="${asset.use.filesystem.storage}")
protected boolean storeAssetsOnFileSystem
protected StaticAssetDao staticAssetDao
protected StaticAssetStorageService staticAssetStorageService
protected StaticAssetPathService staticAssetPathService
protected StaticAssetMultiTenantExtensionManager staticAssetExtensionManager
@Value(value="${should.accept.non.image.asset:true}")
protected boolean shouldAcceptNonImageAsset
@Value(value="${disabled.file.extensions}")
protected String disabledFileExtensions
@Value(value="${static.asset.invalid.chars.in.filename}")
protected char[] notAllowedCharsInFileName
@Value(value="${static.asset.exception.on.invalid.char.in.filename:false}")
protected boolean exceptionOnInvalidChar
@Value(value="${static.asset.invalid.chars.replacement}")
protected String replacementString
public StaticAsset findStaticAssetById(Long id)
findStaticAssetById in interface StaticAssetServicepublic List<StaticAsset> readAllStaticAssets()
readAllStaticAssets in interface StaticAssetServicepublic Long findTotalStaticAssetCount()
findTotalStaticAssetCount in interface StaticAssetServiceprotected String generateFileName(int size)
size - protected String buildAssetURL(Map<String,String> assetProperties, String originalFilename)
If the properties above are not set, it will generate the fileName randomly.
url - asset - assetProperties - public void validateFileExtension(org.springframework.web.multipart.MultipartFile file)
throws IOException
IOException@Transactional(value="blTransactionManager") public StaticAsset createStaticAssetFromFile(org.springframework.web.multipart.MultipartFile file, Map<String,String> properties)
StaticAssetServiceUsed when uploading a file to Broadleaf. This method will create the corresponding asset.
Depending on the the implementation, the actual asset may be saved to the DB or to
the file system. The default implementation StaticAssetServiceImpl has a
environment properties that determine this behavior asset.use.filesystem.storage
The properties Map allows for implementors to update other Asset properties at the same time they are uploading a file. The default implementation uses this for an optional URL to be specified.
To actually create the physical file that this asset represents see
StaticAssetStorageService.createStaticAssetStorageFromFile(MultipartFile, StaticAsset)
createStaticAssetFromFile in interface StaticAssetServicefile - - the file being uploadedproperties - - additional meta-data propertiesStaticAssetServiceImplprotected boolean validateFileName(String fileName)
@Transactional(value="blTransactionManager") public StaticAsset createStaticAsset(InputStream inputStream, String fileName, long fileSize, Map<String,String> properties)
StaticAssetService
Similar to StaticAssetService.createStaticAssetFromFile(MultipartFile, Map) except not dependent upon an uploaded file from a
controller
To actually create the physical file that this asset represents see
StaticAssetStorageService.createStaticAssetStorage(InputStream, StaticAsset)
createStaticAsset in interface StaticAssetServiceinputStream - the input stream of a file to create the asset fromfileName - the name of the filefileSize - the size of the file, in bytesproperties - additional metadata propertiesprotected StaticAsset createNonImageAsset(InputStream inputStream, String fileName, Map<String,String> properties)
inputStream - fileName - properties - protected String getCountUrl(String fullUrl, int count, boolean legacyFormat)
/path/to/image.jpg-1 /path/to/image.jpg-2
Whereas if this is in non-legacy format (legacy == false):
/path/to/image-1.jpg /path/to/image-2.jpg
Used to deal with duplicate URLs of uploaded assets
protected void getMimeType(InputStream inputStream, String fileName, StaticAsset newAsset)
public StaticAsset findStaticAssetByFullUrl(String fullUrl)
findStaticAssetByFullUrl in interface StaticAssetService@Transactional(value="blTransactionManager") public StaticAsset addStaticAsset(StaticAsset staticAsset)
StaticAssetServiceaddStaticAsset in interface StaticAssetService@Transactional(value="blTransactionManager") public StaticAsset updateStaticAsset(StaticAsset staticAsset)
StaticAssetServiceupdateStaticAsset in interface StaticAssetService@Transactional(value="blTransactionManager") public void deleteStaticAsset(StaticAsset staticAsset)
StaticAssetServicedeleteStaticAsset in interface StaticAssetServicepublic String getStaticAssetUrlPrefix()
getStaticAssetUrlPrefix in interface StaticAssetServiceStaticAssetPathService.getStaticAssetUrlPrefix()public String getPrefixedStaticAssetUrl(String assetUrl)
StaticAssetServicegetPrefixedStaticAssetUrl in interface StaticAssetServicepublic String getStaticAssetEnvironmentUrlPrefix()
getStaticAssetEnvironmentUrlPrefix in interface StaticAssetServiceStaticAssetPathService.getStaticAssetEnvironmentUrlPrefix()public String getStaticAssetEnvironmentSecureUrlPrefix()
getStaticAssetEnvironmentSecureUrlPrefix in interface StaticAssetServiceStaticAssetPathService.getStaticAssetEnvironmentSecureUrlPrefix()public String convertAssetPath(String assetPath, String contextPath, boolean secureRequest)
convertAssetPath in interface StaticAssetServiceStaticAssetPathService.convertAssetPath(String, String, boolean)public boolean getShouldAcceptNonImageAsset()
public void setShouldAcceptNonImageAsset(boolean accept)
Copyright © 2022. All rights reserved.