Class StaticAssetStorageServiceImpl
java.lang.Object
org.broadleafcommerce.cms.file.service.StaticAssetStorageServiceImpl
- All Implemented Interfaces:
StaticAssetStorageService
@Service("blStaticAssetStorageService")
public class StaticAssetStorageServiceImpl
extends Object
implements StaticAssetStorageService
- Author:
- Jeff Fischer, Brian Polster
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ArtifactServiceprotected BroadleafFileServiceprotected Stringprotected ConcurrentFileOutputStreamprotected static final Stringstatic final longprotected static final intprotected org.springframework.boot.autoconfigure.web.servlet.MultipartPropertiesprotected org.springframework.core.env.Environmentprotected StaticAssetServiceExtensionManagerprotected NamedOperationManagerprotected Stringprotected StaticAssetServiceprotected StaticAssetStorageDaoprotected StreamingTransactionCapableUtil -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildModel(String returnFilePath, String mimeType) protected StringconstructCacheFileName(StaticAsset staticAsset, Map<String, String> parameterMap) Builds a file system path for the passed in static asset and paramaterMap.create()createBlob(InputStream uploadedFileInputStream, long fileSize) Creates a blob from an input stream with a given filesize.createBlob(org.springframework.web.multipart.MultipartFile uploadedFile) protected voidcreateLocalFileFromClassPathResource(StaticAsset staticAsset, File baseLocalFile) protected voidcreateLocalFileFromInputStream(InputStream is, File baseLocalFile) voidcreateStaticAssetStorage(InputStream fileInputStream, StaticAsset staticAsset) Similar toStaticAssetStorageService.createStaticAssetStorageFromFile(MultipartFile, StaticAsset)except that this does not depend on an uploaded file and can support more generic use casesvoidcreateStaticAssetStorageFromFile(org.springframework.web.multipart.MultipartFile file, StaticAsset staticAsset) Persists the file to the DB or FileSystem according to the staticAsset's StorageType.voiddelete(StaticAssetStorage assetStorage) Removes a static asset from the database.protected StaticAssetfindStaticAsset(String fullUrl) Returns a StaticAssetStorage object.getCacheFileModel(String fullUrl, Map<String, String> parameterMap) protected intprotected StringgetFileExtension(String assetPath) protected FilegetFileFromLocalRepository(String cachedFileName) protected longprotected longprotected longgetMaxUploadSizeForFile(String fileName) protected booleanisImageFile(String fileName) protected FilelookupAssetAndCreateLocalFile(StaticAsset staticAsset, File baseLocalFile) protected StringReturns a StaticAssetStorage object using the id of a related StaticAsset.save(StaticAssetStorage assetStorage) Persists a static asset to the database.protected booleanshouldRecompress(String mimeType) protected booleanvoidvalidateFileSize(org.springframework.web.multipart.MultipartFile file) Validates given file with the maximum upload file size value
-
Field Details
-
DEFAULT_ASSET_UPLOAD_SIZE
public static final long DEFAULT_ASSET_UPLOAD_SIZE- See Also:
-
DEFAULT_ADMIN_IMAGE_EXTENSIONS
- See Also:
-
DEFAULT_BUFFER_SIZE
protected static final int DEFAULT_BUFFER_SIZE- See Also:
-
cacheDirectory
-
env
@Autowired protected org.springframework.core.env.Environment env -
staticAssetService
-
broadleafFileService
-
artifactService
-
staticAssetStorageDao
-
namedOperationManager
-
extensionManager
-
transUtil
-
recompressFormats
-
defaultMultipartSettings
@Autowired(required=false) protected org.springframework.boot.autoconfigure.web.servlet.MultipartProperties defaultMultipartSettings -
concurrentFileOutputStream
-
-
Constructor Details
-
StaticAssetStorageServiceImpl
public StaticAssetStorageServiceImpl()
-
-
Method Details
-
findStaticAsset
-
getFileFromLocalRepository
-
lookupAssetAndCreateLocalFile
protected File lookupAssetAndCreateLocalFile(StaticAsset staticAsset, File baseLocalFile) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
createLocalFileFromClassPathResource
protected void createLocalFileFromClassPathResource(StaticAsset staticAsset, File baseLocalFile) throws IOException - Throws:
IOException
-
createLocalFileFromInputStream
protected void createLocalFileFromInputStream(InputStream is, File baseLocalFile) throws IOException - Throws:
IOException
-
getCacheFileModel
public Map<String,String> getCacheFileModel(String fullUrl, Map<String, String> parameterMap) throws Exception- Specified by:
getCacheFileModelin interfaceStaticAssetStorageService- Returns:
- Throws:
Exception
-
shouldRecompress
-
buildModel
-
findStaticAssetStorageById
Description copied from interface:StaticAssetStorageServiceReturns a StaticAssetStorage object. Assumes that the asset is stored in the Database.Storing Assets in the DB is not the preferred mechanism for Broadleaf as of 3.0 so in most cases, this method would not be used by Broadleaf implementations.
- Specified by:
findStaticAssetStorageByIdin interfaceStaticAssetStorageService- Returns:
-
create
- Specified by:
createin interfaceStaticAssetStorageService- Returns:
-
readStaticAssetStorageByStaticAssetId
Description copied from interface:StaticAssetStorageServiceReturns a StaticAssetStorage object using the id of a related StaticAsset. Assumes that the asset is stored in the Database.Storing Assets in the DB is not the preferred mechanism for Broadleaf as of 3.0 so in most cases, this method would not be used by Broadleaf implementations.
- Specified by:
readStaticAssetStorageByStaticAssetIdin interfaceStaticAssetStorageService- Returns:
-
save
Description copied from interface:StaticAssetStorageServicePersists a static asset to the database. Not typically used since Broadleaf 3.0 as the preferred method for storing assets is on a shared-filesystem.- Specified by:
savein interfaceStaticAssetStorageService- Returns:
-
delete
Description copied from interface:StaticAssetStorageServiceRemoves a static asset from the database. Not typically used since Broadleaf 3.0 as the preferred method for storing assets is on a shared-filesystem.- Specified by:
deletein interfaceStaticAssetStorageService
-
createBlob
public Blob createBlob(org.springframework.web.multipart.MultipartFile uploadedFile) throws IOException - Specified by:
createBlobin interfaceStaticAssetStorageService- Returns:
- Throws:
IOException
-
createBlob
Description copied from interface:StaticAssetStorageServiceCreates a blob from an input stream with a given filesize. This method wraps the call in a transactional tag.- Specified by:
createBlobin interfaceStaticAssetStorageService- Returns:
- Throws:
IOException
-
constructCacheFileName
Builds a file system path for the passed in static asset and paramaterMap.- Parameters:
staticAsset-parameterMap-- Returns:
-
pad
-
createStaticAssetStorageFromFile
@Transactional("blTransactionManagerAssetStorageInfo") public void createStaticAssetStorageFromFile(org.springframework.web.multipart.MultipartFile file, StaticAsset staticAsset) throws IOException Description copied from interface:StaticAssetStorageServicePersists the file to the DB or FileSystem according to the staticAsset's StorageType. Typically, the MultipartFile is passed in from a Controller like the AdminAssetUploadController- Specified by:
createStaticAssetStorageFromFilein interfaceStaticAssetStorageService- Parameters:
file- the uploaded file from the Spring controllerstaticAsset- theStaticAssetentity to obtain storage information from like file size and the file name, usually created fromStaticAssetService.createStaticAssetFromFile(MultipartFile, Map)- Throws:
IOException
-
createStaticAssetStorage
@Transactional("blTransactionManagerAssetStorageInfo") public void createStaticAssetStorage(InputStream fileInputStream, StaticAsset staticAsset) throws IOException Description copied from interface:StaticAssetStorageServiceSimilar toStaticAssetStorageService.createStaticAssetStorageFromFile(MultipartFile, StaticAsset)except that this does not depend on an uploaded file and can support more generic use cases- Specified by:
createStaticAssetStoragein interfaceStaticAssetStorageService- Parameters:
fileInputStream- the input stream of the uploaded filestaticAsset- theStaticAssetentity to obtain storage information from like file size and the file name, usually created fromStaticAssetService.createStaticAsset(InputStream, String, long, Map)- Throws:
IOException
-
getMaxUploadSizeForFile
-
isImageFile
-
getFileExtension
-
getMaxUploadableFileSize
protected long getMaxUploadableFileSize() -
getMaxUploadableImageSize
protected long getMaxUploadableImageSize() -
getFileBufferSize
protected int getFileBufferSize() -
getAdminImageFileExtensions
-
validateFileSize
public void validateFileSize(org.springframework.web.multipart.MultipartFile file) throws IOException Description copied from interface:StaticAssetStorageServiceValidates given file with the maximum upload file size value- Specified by:
validateFileSizein interfaceStaticAssetStorageService- Throws:
IOException
-