Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Asset getMetadata() returns Object Array instead of String

Avatar

Former Community Member

Hi,

I'm trying to pull the meta data (namely the 'dc:description' and 'dc:title') off of an DAM Asset:

ResourceResolver resourceResolver = slingRequest.getResourceResolver(); Resource res = resourceResolver.getResource(imagePath); Asset asset = res.adaptTo(Asset.class); // this is empty: asset.getMetadataValue("dc:description") // this returns [Ljava.lang.Object;@4281a636 asset.getMetadata("dc:description").toString() // doing this returns all metadata, do I can see that dc:description does exist:
asset.getMetadata()
/* {dam:Progressive=no, dam:sha1=60dcef16fc38f6d96240bf91edd05f05608bf9fd, dam:Physicalwidthindpi=-1, stRef:instanceID=xmp.iid:D7BC5564CF9D11E2A8C9A7B002094D24, dam:MIMEtype=image/png, stRef:documentID=xmp.did:D7BC5565CF9D11E2A8C9A7B002094D24, dc:description=[Ljava.lang.Object;@4281a636, xmpMM:InstanceID=xmp.iid:D7BC5566CF9D11E2A8C9A7B002094D24, dam:Fileformat=PNG, tiff:ImageLength=114, dam:extracted=2014-01-23T10:00:12.333-08:00, dc:format=image/png, tiff:ImageWidth=114, xml:lang=x-default, dam:Comments=Pauls test comment, xmp:CreatorTool=Adobe Photoshop CS6 (Windows), dam:Physicalheightindpi=-1, dc:title=[Ljava.lang.Object;@4dc74556, dam:size=2468, xmpMM:DocumentID=xmp.did:D7BC5567CF9D11E2A8C9A7B002094D24, dam:Physicalheightininches=-1.0, dam:Numberofimages=1, dam:Numberoftextualcomments=2, dam:Physicalwidthininches=-1.0, dam:Bitsperpixel=32, dc:modified=2014-01-28T15:17:29.996-08:00} */

 

I'm just wondering what I'm doing wrong. My understanding was that 'getMetadataValue' returns the string value. If that's not true for objects, how do I get the string off of asset.getMetadata("dc:description")?

 

Thanks,

Paul

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi Paul,

getMetadataValue() internally queries the metadata node first and then starts to look up the XMP metadata in the binary itself. If you get back an empty string as result, it's probably caused because a property with that name is just not there. (And as far as I have seen, it requires, that you are requesting always a property with a namespace (requires a colon, e.g. "dc:title", but not "title"), otherwise it will return "".

getMetadata(String name) is a small convenience function around getMetadata().

getMetadata() does a lot of complex stuff with reading properties via XMP...

So I fully agree, that this API is quite confusing and should be better documented. Would you kindly open a Daycare ticket for it?

Jörg

View solution in original post

2 Replies

Avatar

Correct answer by
Employee Advisor

Hi Paul,

getMetadataValue() internally queries the metadata node first and then starts to look up the XMP metadata in the binary itself. If you get back an empty string as result, it's probably caused because a property with that name is just not there. (And as far as I have seen, it requires, that you are requesting always a property with a namespace (requires a colon, e.g. "dc:title", but not "title"), otherwise it will return "".

getMetadata(String name) is a small convenience function around getMetadata().

getMetadata() does a lot of complex stuff with reading properties via XMP...

So I fully agree, that this API is quite confusing and should be better documented. Would you kindly open a Daycare ticket for it?

Jörg

Avatar

Former Community Member

Thanks Joerg.

Yeah, I was actually trying to get the metadata that's defined in the DAM and therefore stored in '...image.png/jcr:content/metadata'. I thought the getMetadata() would be an easy access function for that and not accessing the XMP meta data. My bad.

So just for the sake of completeness, I ended up using the normal node property functions:

title = node.getNode("jcr:content/metadata").getProperty("dc:title").getString(); description = node.getNode("jcr:content/metadata").getProperty("dc:description").getString();