Class StaticAssetServiceImpl
- All Implemented Interfaces:
StaticAssetService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Stringprotected booleanprotected ImageArtifactProcessorprotected char[]protected Stringprotected booleanprotected StaticAssetDaoprotected StaticAssetMultiTenantExtensionManagerprotected StaticAssetPathServiceprotected StaticAssetStorageServiceprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddStaticAsset(StaticAsset staticAsset) Add an asset outside of Broadleaf Admin.protected StringbuildAssetURL(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 StaticAssetcreateNonImageAsset(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.voiddeleteStaticAsset(StaticAsset staticAsset) Delete an asset outside of Broadleaf Admin.findStaticAssetByFullUrl(String fullUrl) protected StringgenerateFileName(int size) Generates a filename as a set of Hex digits.protected StringgetCountUrl(String fullUrl, int count, boolean legacyFormat) Gets the count URL based on the original fullUrl.protected StringgetFileExtension(String fileName) protected voidgetMimeType(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 setbooleanvoidsetAllowedFileExtensions(String allowedFileExtensions) voidsetDisabledFileExtensions(String disabledFileExtensions) voidsetShouldAcceptNonImageAsset(boolean accept) updateStaticAsset(StaticAsset staticAsset) Update an asset outside of Broadleaf Admin.voidvalidateFileExtension(org.springframework.web.multipart.MultipartFile file) protected booleanvalidateFileName(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:
findStaticAssetByIdin interfaceStaticAssetService
-
readAllStaticAssets
- Specified by:
readAllStaticAssetsin interfaceStaticAssetService
-
findTotalStaticAssetCount
- Specified by:
findTotalStaticAssetCountin 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: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
StaticAssetServiceImplhas a environment properties that determine this behaviorasset.use.filesystem.storageThe 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:
createStaticAssetFromFilein 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:StaticAssetServiceSimilar 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:
createStaticAssetin 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:
findStaticAssetByFullUrlin interfaceStaticAssetService
-
addStaticAsset
Description copied from interface:StaticAssetServiceAdd an asset outside of Broadleaf Admin.- Specified by:
addStaticAssetin interfaceStaticAssetService- Returns:
-
updateStaticAsset
@Transactional("blTransactionManager") public StaticAsset updateStaticAsset(StaticAsset staticAsset) Description copied from interface:StaticAssetServiceUpdate an asset outside of Broadleaf Admin.- Specified by:
updateStaticAssetin interfaceStaticAssetService- Returns:
-
deleteStaticAsset
Description copied from interface:StaticAssetServiceDelete an asset outside of Broadleaf Admin.- Specified by:
deleteStaticAssetin interfaceStaticAssetService
-
getStaticAssetUrlPrefix
- Specified by:
getStaticAssetUrlPrefixin interfaceStaticAssetService- See Also:
-
getPrefixedStaticAssetUrl
Description copied from interface:StaticAssetServiceReturn a prefixed version of the given asset url, assuming a static asset url prefix is set- Specified by:
getPrefixedStaticAssetUrlin interfaceStaticAssetService- Returns:
-
getStaticAssetEnvironmentUrlPrefix
- Specified by:
getStaticAssetEnvironmentUrlPrefixin interfaceStaticAssetService- See Also:
-
getStaticAssetEnvironmentSecureUrlPrefix
- Specified by:
getStaticAssetEnvironmentSecureUrlPrefixin interfaceStaticAssetService- See Also:
-
convertAssetPath
- Specified by:
convertAssetPathin interfaceStaticAssetService- See Also:
-
getShouldAcceptNonImageAsset
public boolean getShouldAcceptNonImageAsset() -
setShouldAcceptNonImageAsset
public void setShouldAcceptNonImageAsset(boolean accept) -
getDisabledFileExtensions
-
setDisabledFileExtensions
-
getAllowedFileExtensions
-
setAllowedFileExtensions
-