Class StaticAssetServiceImpl
- All Implemented Interfaces:
StaticAssetService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected String
protected boolean
protected ImageArtifactProcessor
protected char[]
protected String
protected boolean
protected StaticAssetDao
protected StaticAssetMultiTenantExtensionManager
protected StaticAssetPathService
protected StaticAssetStorageService
protected boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddStaticAsset
(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-ab12convertAssetPath
(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-imagescreateStaticAsset
(InputStream inputStream, String fileName, long fileSize, Map<String, String> properties) Similar toStaticAssetService.createStaticAssetFromFile(MultipartFile, Map)
except not dependent upon an uploaded file from a controllercreateStaticAssetFromFile
(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.findStaticAssetByFullUrl
(String fullUrl) 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) getPrefixedStaticAssetUrl
(String assetUrl) Return a prefixed version of the given asset url, assuming a static asset url prefix is setboolean
void
setAllowedFileExtensions
(String allowedFileExtensions) void
setDisabledFileExtensions
(String disabledFileExtensions) void
setShouldAcceptNonImageAsset
(boolean accept) updateStaticAsset
(StaticAsset staticAsset) Update an asset outside of Broadleaf Admin.void
validateFileExtension
(org.springframework.web.multipart.MultipartFile file) protected boolean
validateFileName
(String fileName)
-
Field Details
-
imageArtifactProcessor
-
storeAssetsOnFileSystem
@Value("${asset.use.filesystem.storage}") protected boolean storeAssetsOnFileSystem -
staticAssetDao
-
staticAssetStorageService
-
staticAssetPathService
-
staticAssetExtensionManager
-
shouldAcceptNonImageAsset
@Value("${should.accept.non.image.asset:true}") protected boolean shouldAcceptNonImageAsset -
disabledFileExtensions
-
allowedFileExtensions
-
notAllowedCharsInFileName
@Value("${static.asset.invalid.chars.in.filename}") protected char[] notAllowedCharsInFileName -
exceptionOnInvalidChar
@Value("${static.asset.exception.on.invalid.char.in.filename:false}") protected boolean exceptionOnInvalidChar -
replacementString
-
-
Constructor Details
-
StaticAssetServiceImpl
public StaticAssetServiceImpl()
-
-
Method Details
-
findStaticAssetById
- Specified by:
findStaticAssetById
in interfaceStaticAssetService
-
readAllStaticAssets
- Specified by:
readAllStaticAssets
in interfaceStaticAssetService
-
findTotalStaticAssetCount
- Specified by:
findTotalStaticAssetCount
in interfaceStaticAssetService
-
getFileExtension
-
generateFileName
Generates a filename as a set of Hex digits.- Parameters:
size
-- Returns:
-
buildAssetURL
Will assemble the url from the passed in properties as /{entityType}/{fileName} /product/7001-ab12If the properties above are not set, it will generate the fileName randomly.
- Parameters:
assetProperties
-originalFilename
-- Returns:
-
validateFileExtension
public void validateFileExtension(org.springframework.web.multipart.MultipartFile file) throws IOException - Throws:
IOException
-
createStaticAssetFromFile
@Transactional("blTransactionManager") public StaticAsset createStaticAssetFromFile(org.springframework.web.multipart.MultipartFile file, Map<String, String> properties) Description copied from interface:StaticAssetService
Used 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 behaviorasset.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)
- Specified by:
createStaticAssetFromFile
in interfaceStaticAssetService
- Parameters:
file
- - the file being uploadedproperties
- - additional meta-data properties- Returns:
- See Also:
-
validateFileName
-
createStaticAsset
@Transactional("blTransactionManager") public StaticAsset createStaticAsset(InputStream inputStream, String fileName, long fileSize, Map<String, String> properties) Description copied from interface:StaticAssetService
Similar to
StaticAssetService.createStaticAssetFromFile(MultipartFile, Map)
except not dependent upon an uploaded file from a controllerTo actually create the physical file that this asset represents see
StaticAssetStorageService.createStaticAssetStorage(InputStream, StaticAsset)
- Specified by:
createStaticAsset
in interfaceStaticAssetService
- Parameters:
inputStream
- 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 properties- Returns:
-
createNonImageAsset
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- Parameters:
inputStream
-fileName
-properties
-- Returns:
-
getCountUrl
Gets the count URL based on the original fullUrl. If requested in legacy format this will return URLs like:/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
-
getMimeType
-
findStaticAssetByFullUrl
- Specified by:
findStaticAssetByFullUrl
in interfaceStaticAssetService
-
addStaticAsset
Description copied from interface:StaticAssetService
Add an asset outside of Broadleaf Admin.- Specified by:
addStaticAsset
in interfaceStaticAssetService
- Returns:
-
updateStaticAsset
@Transactional("blTransactionManager") public StaticAsset updateStaticAsset(StaticAsset staticAsset) Description copied from interface:StaticAssetService
Update an asset outside of Broadleaf Admin.- Specified by:
updateStaticAsset
in interfaceStaticAssetService
- Returns:
-
deleteStaticAsset
Description copied from interface:StaticAssetService
Delete an asset outside of Broadleaf Admin.- Specified by:
deleteStaticAsset
in interfaceStaticAssetService
-
getStaticAssetUrlPrefix
- Specified by:
getStaticAssetUrlPrefix
in interfaceStaticAssetService
- See Also:
-
getPrefixedStaticAssetUrl
Description copied from interface:StaticAssetService
Return a prefixed version of the given asset url, assuming a static asset url prefix is set- Specified by:
getPrefixedStaticAssetUrl
in interfaceStaticAssetService
- Returns:
-
getStaticAssetEnvironmentUrlPrefix
- Specified by:
getStaticAssetEnvironmentUrlPrefix
in interfaceStaticAssetService
- See Also:
-
getStaticAssetEnvironmentSecureUrlPrefix
- Specified by:
getStaticAssetEnvironmentSecureUrlPrefix
in interfaceStaticAssetService
- See Also:
-
convertAssetPath
- Specified by:
convertAssetPath
in interfaceStaticAssetService
- See Also:
-
getShouldAcceptNonImageAsset
public boolean getShouldAcceptNonImageAsset() -
setShouldAcceptNonImageAsset
public void setShouldAcceptNonImageAsset(boolean accept) -
getDisabledFileExtensions
-
setDisabledFileExtensions
-
getAllowedFileExtensions
-
setAllowedFileExtensions
-