Is there a way to programmatically set metadata of an asset?

久未见 提交于 2019-12-13 00:13:25

问题


I added a custom metadata in CQ5 with name ./dc:sample. Is there a way I can programmatically set this metadata for an asset?

I've written a workflow that intercepts the uploaded assets and replaces them with inputstream sent from the third party service. I accomplish this by doing the following in my workflow.

Rendition rendition = resource.adaptTo(Rendition.class);
Asset asset = rendition.getAsset();
InputStream newInputStream = myService.sendFile(is);
asset.addRendition(rendition.getName(),newInputStream,asset.getMimeType());

Question

At this time I would like to set the ./dc:sample metadata to a string like "test checking". Is this possible to do?


回答1:


You can adapt the Asset to Resource, get its jcr:content/metadata grandchild and adapt it to ModifiableValueMap:

Resource metadataRes = asset.adaptTo(Resource.class).getChild("jcr:content/metadata");
ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class);
map.put("dc:sample", "test checking");
resourceResolver.commit();


来源:https://stackoverflow.com/questions/24653070/is-there-a-way-to-programmatically-set-metadata-of-an-asset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!