问题
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