在我的应用程序中,我有一个从网页的页面属性部分中的 dam 内容获取 pdf 文件的路径,如果文件存在,我们有一个下载组件试图显示 pdf 文件的标题和描述。我使用这篇文章作为参考:http: //jenikya.com/blog/2014/05/file-titles-cq.html。我的 HTL 部分是这样的:
<div data-sly-test="${pageProperties.pdfFileReference}" class="download-container ${properties['backgroundColor']}">
<sly data-sly-use.pdfInfo="${'xx.xxx.PDFInfoDataProvider @ pdfPath=pageProperties['pdfFileReference']}">
<a class="download-title" href="${pageProperties.pdfFileReference}" data-analytics-cta-text="${pdfInfo.fileTitle}">
<span class="download-title">${pdfInfo.fileTitle}</span>
</a>
<div class="download-description">${pdfInfo.fileDescription}</div>
</sly>
</div>
我的 java 部分如下所示。看起来它永远不会得到标题和描述。如果有人可以帮助指出可能是什么问题,或者在任何地方寻找解决方案,我将不胜感激。
package ....
import ....
public class PDFInfoDataProvider extends WCMUsePojo {
private String fileTitle;
private String fileDescription;
private String pdfPath;
@Override
public void activate() throws Exception {
pdfPath = get("pdfPath", String.class);
resolve();
}
private void resolve() {
Resource resource = getResourceResolver().getResource(pdfPath);
Asset asset = resource.adaptTo(Asset.class);
String title = asset.getMetadataValue("dc:title");
String description = asset.getMetadataValue("dc:description");
fileTitle = title;
fileDescription = description;
}
public String getTitle() { return fileTitle; }
public String getFileDescription() { return fileDescription; }
}