use of com.day.cq.commons.DownloadResource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class DownloadImpl method initAssetDownload.
private void initAssetDownload(String fileReference) {
Resource downloadResource = resourceResolver.getResource(fileReference);
if (downloadResource != null) {
Asset downloadAsset = downloadResource.adaptTo(Asset.class);
if (downloadAsset != null) {
Calendar resourceLastModified = properties.get(JcrConstants.JCR_LASTMODIFIED, Calendar.class);
if (resourceLastModified != null) {
lastModified = resourceLastModified.getTimeInMillis();
}
long assetLastModified = downloadAsset.getLastModified();
if (assetLastModified > lastModified) {
lastModified = assetLastModified;
}
filename = downloadAsset.getName();
format = downloadAsset.getMetadataValue(DamConstants.DC_FORMAT);
if (StringUtils.isNoneEmpty(format)) {
extension = mimeTypeService.getExtension(format);
}
if (StringUtils.isEmpty(extension)) {
extension = FilenameUtils.getExtension(filename);
}
url = linkHandler.getLink(getDownloadUrl(downloadResource), null).map(Link::getURL).orElse(null);
if (titleFromAsset) {
title = downloadAsset.getMetadataValue(DamConstants.DC_TITLE);
}
if (descriptionFromAsset) {
String assetDescription = downloadAsset.getMetadataValue(DamConstants.DC_DESCRIPTION);
if (StringUtils.isNotBlank(assetDescription)) {
description = assetDescription;
}
}
long rawFileSize;
Object rawFileSizeObject = downloadAsset.getMetadata(DamConstants.DAM_SIZE);
if (rawFileSizeObject != null) {
rawFileSize = (Long) rawFileSizeObject;
} else {
rawFileSize = downloadAsset.getOriginal().getSize();
}
size = FileUtils.byteCountToDisplaySize(rawFileSize);
}
}
}
Aggregations