如何从AEM的Java文件中获取给定格式副本的资产路径?



我想在我的 html 页面中将我的图像资产的 'cq5dam.thumbnail.140.100.png' 再现显示为缩略图。 对于给定的格式副本,如何在 java/JSP 中获取 DAM 中我的一个资产的资产路径

这个函数就可以了

public static String getImageAssetPath(SlingHttpServletRequest slingRequest,String actualDamPath,String renditionParam,String defaultPath) {
try {
if(StringUtils.isNotEmpty(actualPath)){
Resource resource = slingRequest.getResourceResolver().getResource(actualPath);
Asset asset = resource.adaptTo(Asset.class);
String imageAssetPath = asset.getRendition(renditionParam).getPath();
LOGGER.info("imageAssetPath for given rendition: " + imageAssetPath);
return imageAssetPath;
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
return defaultPath;
}

将此函数放在标记库中,以便可以在 JSP 中使用相同的函数

${mytaglib:getAssetPath(slingRequest,property.previewImage,'cq5dam.thumbnail.140.100.png','')}

最新更新