org.broadleafcommerce.cms.file.service
Class StaticAssetStorageServiceImpl

java.lang.Object
  extended by org.broadleafcommerce.cms.file.service.StaticAssetStorageServiceImpl
All Implemented Interfaces:
StaticAssetStorageService

@Service(value="blStaticAssetStorageService")
public class StaticAssetStorageServiceImpl
extends Object
implements StaticAssetStorageService

Author:
Jeff Fischer, Brian Polster

Field Summary
protected  ArtifactService artifactService
           
protected  BroadleafFileService broadleafFileService
           
protected  String cacheDirectory
           
protected  int fileBufferSize
           
protected  long maxUploadableFileSize
           
protected  NamedOperationManager namedOperationManager
           
protected  StaticAssetService staticAssetService
           
protected  StaticAssetStorageDao staticAssetStorageDao
           
 
Constructor Summary
StaticAssetStorageServiceImpl()
           
 
Method Summary
protected  String appendTrailingSlash(String path)
          Removes trailing "/" and ensures that there is a beginning "/"
protected  Map<String,String> buildModel(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.
 StaticAssetStorage create()
           
 Blob createBlob(org.springframework.web.multipart.MultipartFile uploadedFile)
           
protected  void createLocalFileFromClassPathResource(StaticAsset staticAsset, File baseLocalFile)
           
protected  void createLocalFileFromInputStream(InputStream is, File baseLocalFile)
           
 void 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)
           
 StaticAssetStorage findStaticAssetStorageById(Long id)
          Returns a StaticAssetStorage object.
 Map<String,String> getCacheFileModel(String fullUrl, Map<String,String> parameterMap)
           
protected  File getFileFromLocalRepository(String cachedFileName)
           
protected  File lookupAssetAndCreateLocalFile(StaticAsset staticAsset, File baseLocalFile)
           
protected  String pad(String s, int length, char pad)
           
 StaticAssetStorage readStaticAssetStorageByStaticAssetId(Long id)
          Returns a StaticAssetStorage object using the id of a related StaticAsset.
protected  String removeLeadingSlash(String path)
          Removes trailing "/" and ensures that there is a beginning "/"
 StaticAssetStorage save(StaticAssetStorage assetStorage)
          Persists a static asset to the database.
protected  boolean shouldUseSharedFile(InputStream is)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxUploadableFileSize

@Value(value="${asset.server.max.uploadable.file.size}")
protected long maxUploadableFileSize

fileBufferSize

@Value(value="${asset.server.file.buffer.size}")
protected int fileBufferSize

cacheDirectory

protected String cacheDirectory

staticAssetService

protected StaticAssetService staticAssetService

broadleafFileService

protected BroadleafFileService broadleafFileService

artifactService

protected ArtifactService artifactService

staticAssetStorageDao

protected StaticAssetStorageDao staticAssetStorageDao

namedOperationManager

protected NamedOperationManager namedOperationManager
Constructor Detail

StaticAssetStorageServiceImpl

public StaticAssetStorageServiceImpl()
Method Detail

findStaticAsset

protected StaticAsset findStaticAsset(String fullUrl)

appendTrailingSlash

protected String appendTrailingSlash(String path)
Removes trailing "/" and ensures that there is a beginning "/"

Parameters:
path -
Returns:

removeLeadingSlash

protected String removeLeadingSlash(String path)
Removes trailing "/" and ensures that there is a beginning "/"

Parameters:
path -
Returns:

shouldUseSharedFile

protected boolean shouldUseSharedFile(InputStream is)

getFileFromLocalRepository

protected File getFileFromLocalRepository(String cachedFileName)

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

@Transactional(value="blTransactionManagerAssetStorageInfo")
public Map<String,String> getCacheFileModel(String fullUrl,
                                                          Map<String,String> parameterMap)
                                     throws Exception
Specified by:
getCacheFileModel in interface StaticAssetStorageService
Returns:
Throws:
Exception

buildModel

protected Map<String,String> buildModel(String returnFilePath,
                                        String mimeType)

findStaticAssetStorageById

@Transactional(value="blTransactionManagerAssetStorageInfo")
public StaticAssetStorage findStaticAssetStorageById(Long id)
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 interface StaticAssetStorageService
Returns:

create

@Transactional(value="blTransactionManagerAssetStorageInfo")
public StaticAssetStorage create()
Specified by:
create in interface StaticAssetStorageService
Returns:

readStaticAssetStorageByStaticAssetId

@Transactional(value="blTransactionManagerAssetStorageInfo")
public StaticAssetStorage readStaticAssetStorageByStaticAssetId(Long id)
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 interface StaticAssetStorageService
Returns:

save

@Transactional(value="blTransactionManagerAssetStorageInfo")
public StaticAssetStorage save(StaticAssetStorage assetStorage)
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 interface StaticAssetStorageService
Returns:

delete

@Transactional(value="blTransactionManagerAssetStorageInfo")
public void delete(StaticAssetStorage assetStorage)
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 interface StaticAssetStorageService

createBlob

@Transactional(value="blTransactionManagerAssetStorageInfo")
public Blob createBlob(org.springframework.web.multipart.MultipartFile uploadedFile)
                throws IOException
Specified by:
createBlob in interface StaticAssetStorageService
Returns:
Throws:
IOException

constructCacheFileName

protected String constructCacheFileName(StaticAsset staticAsset,
                                        Map<String,String> parameterMap)
Builds a file system path for the passed in static asset and paramaterMap.

Parameters:
staticAsset -
parameterMap -
useSharedFile -
Returns:

pad

protected String pad(String s,
                     int length,
                     char pad)

createStaticAssetStorageFromFile

@Transactional(value="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 interface StaticAssetStorageService
Throws:
IOException


Copyright © 2013. All Rights Reserved.