Programatically Set/Get the metadata of an Asset: Adobe CQ5/Adobe AEM
The Adobe Experience Manager(AEM) version referred here is 5.6.1@Reference
private ResourceResolverFactory resolverFactory;
ResourceResolver resourceResolver =null;
try
{
String resourcePath = "/content/dam/geometrixx-outdoors/banners/adventure.jpg";
resourceResolver= resolverFactory.getAdministrativeResourceResolver(null);
Resource res = resourceResolver.getResource(resourcePath);
Resource metadataRes =res.getChild("jcr:content/metadata");
ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class);
//set metadata
map.put("dc:samplemetadata", "sample metadata");
resourceResolver.commit();
//get metadata
String metadata=map.get("dc:samplemetadata").toString();
}catch(Exception e)
{
}finally
{
resourceResolver.close();
}
Dependency in pom.xml
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
No comments:
Post a Comment