use of org.broadleafcommerce.cms.file.domain.StaticAsset in project BroadleafCommerce by BroadleafCommerce.
the class StaticAssetStorageServiceImpl method getCacheFileModel.
@Override
public Map<String, String> getCacheFileModel(String fullUrl, Map<String, String> parameterMap) throws Exception {
StaticAsset staticAsset = findStaticAsset(fullUrl);
if (staticAsset == null) {
throw new AssetNotFoundException("Unable to find an asset for the url (" + fullUrl + ")");
}
String mimeType = staticAsset.getMimeType();
// extract the values for any named parameters
Map<String, String> convertedParameters = namedOperationManager.manageNamedParameters(parameterMap);
String cachedFileName = constructCacheFileName(staticAsset, convertedParameters);
// Look for a shared file (this represents a file that was based on a file originally in the classpath.
File cacheFile = getFileFromLocalRepository(cachedFileName);
if (cacheFile.exists()) {
return buildModel(cacheFile.getAbsolutePath(), mimeType);
}
// Obtain the base file (that we may need to convert based on the parameters
String baseCachedFileName = constructCacheFileName(staticAsset, null);
File baseLocalFile = getFileFromLocalRepository(baseCachedFileName);
if (!baseLocalFile.exists()) {
if (broadleafFileService.checkForResourceOnClassPath(staticAsset.getFullUrl())) {
cacheFile = broadleafFileService.getSharedLocalResource(cachedFileName);
baseLocalFile = broadleafFileService.getSharedLocalResource(baseCachedFileName);
createLocalFileFromClassPathResource(staticAsset, baseLocalFile);
} else {
baseLocalFile = lookupAssetAndCreateLocalFile(staticAsset, baseLocalFile);
}
}
if (convertedParameters.isEmpty()) {
return buildModel(baseLocalFile.getAbsolutePath(), mimeType);
} else {
FileInputStream assetStream = new FileInputStream(baseLocalFile);
BufferedInputStream original = new BufferedInputStream(assetStream);
original.mark(0);
Operation[] operations = artifactService.buildOperations(convertedParameters, original, staticAsset.getMimeType());
InputStream converted = artifactService.convert(original, operations, staticAsset.getMimeType());
createLocalFileFromInputStream(converted, cacheFile);
if ("image/gif".equals(mimeType)) {
mimeType = "image/png";
}
return buildModel(cacheFile.getAbsolutePath(), mimeType);
}
}
use of org.broadleafcommerce.cms.file.domain.StaticAsset in project BroadleafCommerce by BroadleafCommerce.
the class StaticAssetDaoImpl method readAllStaticAssets.
public List<StaticAsset> readAllStaticAssets() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<StaticAsset> criteria = builder.createQuery(StaticAsset.class);
Root<StaticAssetImpl> handler = criteria.from(StaticAssetImpl.class);
criteria.select(handler);
List<Predicate> restrictions = new ArrayList<Predicate>();
List<Order> sorts = new ArrayList<Order>();
try {
if (queryExtensionManager != null) {
queryExtensionManager.getProxy().setup(StaticAssetImpl.class, null);
queryExtensionManager.getProxy().refineRetrieve(StaticAssetImpl.class, null, builder, criteria, handler, restrictions);
queryExtensionManager.getProxy().refineOrder(StaticAssetImpl.class, null, builder, criteria, handler, sorts);
}
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
return em.createQuery(criteria).getResultList();
} catch (NoResultException e) {
return new ArrayList<StaticAsset>();
}
}
Aggregations