2

In my application, I have a path to get a pdf file from dam content in the page property part of a web page, and we have a download component trying to display the pdf file title and description if the file exists. I'm using this article as a reference:http://jenikya.com/blog/2014/05/file-titles-cq.html. My HTL part is like:

<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>

My java part is like below. Looks it never get the title and description back. I'm highly appreciated if somebody could help to point out what may be the problem, or anywhere to look for solutions.

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; }

}
  • Did you check the `jcr:content/metadata` node to see if the `dc:title` and `dc:description` properties were populated for that PDF? – Vlad Mar 29 '21 at 07:41
  • Thank you for your message! I have checked the node, and the dc:title and dc:description are there. The code builds successfully, but the page with the component can not be viewed as published. When I try to add a new download component to the page, the error seems to be ScriptEvaluationException pointing to ${'xx.xxx.PDFInfoDataProvider ...} part. I tried to debug, but the code did not stop at the break point. I'm also wondering if "/content/dam/../xxx.pdf" is a correct path. – user15496195 Mar 30 '21 at 12:32
  • Update: after java 8 update 281, it works and getTitle() should be getFieTitle(). – user15496195 Apr 01 '21 at 18:56

0 Answers0