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 ArtifactService
protected BroadleafFileService
protected String
protected ConcurrentFileOutputStream
protected static final String
static final long
protected static final int
protected org.springframework.boot.autoconfigure.web.servlet.MultipartProperties
protected org.springframework.core.env.Environment
protected StaticAssetServiceExtensionManager
protected NamedOperationManager
protected String
protected StaticAssetService
protected StaticAssetStorageDao
protected StreamingTransactionCapableUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildModel
(String returnFilePath, String mimeType) protected String
constructCacheFileName
(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 void
createLocalFileFromClassPathResource
(StaticAsset staticAsset, File baseLocalFile) protected void
createLocalFileFromInputStream
(InputStream is, File baseLocalFile) void
createStaticAssetStorage
(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 casesvoid
createStaticAssetStorageFromFile
(org.springframework.web.multipart.MultipartFile file, StaticAsset staticAsset) Persists the file to the DB or FileSystem according to the staticAsset's StorageType.void
delete
(StaticAssetStorage assetStorage) Removes a static asset from the database.protected StaticAsset
findStaticAsset
(String fullUrl) Returns a StaticAssetStorage object.getCacheFileModel
(String fullUrl, Map<String, String> parameterMap) protected int
protected String
getFileExtension
(String assetPath) protected File
getFileFromLocalRepository
(String cachedFileName) protected long
protected long
protected long
getMaxUploadSizeForFile
(String fileName) protected boolean
isImageFile
(String fileName) protected File
lookupAssetAndCreateLocalFile
(StaticAsset staticAsset, File baseLocalFile) protected String
Returns a StaticAssetStorage object using the id of a related StaticAsset.save
(StaticAssetStorage assetStorage) Persists a static asset to the database.protected boolean
shouldRecompress
(String mimeType) protected boolean
void
validateFileSize
(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:
IOException
SQLException
-
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:
getCacheFileModel
in interfaceStaticAssetStorageService
- Returns:
- Throws:
Exception
-
shouldRecompress
-
buildModel
-
findStaticAssetStorageById
Description copied from interface:StaticAssetStorageService
Returns 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:
findStaticAssetStorageById
in interfaceStaticAssetStorageService
- Returns:
-
create
- Specified by:
create
in interfaceStaticAssetStorageService
- Returns:
-
readStaticAssetStorageByStaticAssetId
Description copied from interface:StaticAssetStorageService
Returns 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:
readStaticAssetStorageByStaticAssetId
in interfaceStaticAssetStorageService
- Returns:
-
save
Description copied from interface:StaticAssetStorageService
Persists 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:
save
in interfaceStaticAssetStorageService
- Returns:
-
delete
Description copied from interface:StaticAssetStorageService
Removes 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:
delete
in interfaceStaticAssetStorageService
-
createBlob
public Blob createBlob(org.springframework.web.multipart.MultipartFile uploadedFile) throws IOException - Specified by:
createBlob
in interfaceStaticAssetStorageService
- Returns:
- Throws:
IOException
-
createBlob
Description copied from interface:StaticAssetStorageService
Creates a blob from an input stream with a given filesize. This method wraps the call in a transactional tag.- Specified by:
createBlob
in 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:StaticAssetStorageService
Persists 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:
createStaticAssetStorageFromFile
in interfaceStaticAssetStorageService
- Parameters:
file
- the uploaded file from the Spring controllerstaticAsset
- theStaticAsset
entity 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:StaticAssetStorageService
Similar toStaticAssetStorageService.createStaticAssetStorageFromFile(MultipartFile, StaticAsset)
except that this does not depend on an uploaded file and can support more generic use cases- Specified by:
createStaticAssetStorage
in interfaceStaticAssetStorageService
- Parameters:
fileInputStream
- the input stream of the uploaded filestaticAsset
- theStaticAsset
entity 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:StaticAssetStorageService
Validates given file with the maximum upload file size value- Specified by:
validateFileSize
in interfaceStaticAssetStorageService
- Throws:
IOException
-