try to get dc:title and dc:descrption from asset metadata using HTL and java in adobe aem

1.8k Views Asked by At

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

}
0

There are 0 best solutions below