Expand my Community achievements bar.

How to get metadata properties for an Asset in a component?

Avatar

Level 2

I have an asset in AEM that has properties in the metadata. It looks like this:

[img]Screen Shot 2015-06-29 at 12.45.55 PM.png[/img]

I would like to display the note.title property. However, it isn't working. I am able to get the InputStream from the original perfectly fine but can't seem to get the note.title or other metadata properties.

This is what I'm doing in my Java Class that extends WCMUse

@Override public void activate() throws Exception { fileReference = getProperties().get("fileReference", String.class); if(fileReference != null){ Resource rs = getResourceResolver().getResource(fileReference); Asset asset = rs.adaptTo(Asset.class); Resource original = asset.getOriginal(); InputStream stream = original.adaptTo(InputStream.class); //Put the inputstream into a string to return BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); htmloutput = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { htmloutput.append(line); } title = asset.getMetadata("note.title").toString(); } //getter setter for title and html }

In my HTML page I have the following;

<div  data-sly-use.ev="Foo" class="${ev.cssClass || ''}" title="${ev.title || ''}" > This is html: ${ev.html  @ context='unsafe'}<br/> This is title: ${ev.title  @ context='unsafe'}<br/> </div>  

After, I select the asset I can see the html but I don't see the title.

Why am I not getting the metadata properties?

1 Reply