有没有办法以编程方式设置资产的元数据? [英] Is there a way to programmatically set metadata of an asset?

查看:130
本文介绍了有没有办法以编程方式设置资产的元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CQ5中添加了名称为./dc:sample的自定义元数据.有没有办法以编程方式为资产设置此元数据?

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

我编写了一个工作流,该工作流将拦截上载的资产,并将其替换为从第三方服务发送的inputstream.我通过在工作流程中执行以下操作来完成此任务.

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());

问题

这时,我想将./dc:sample元数据设置为类似测试检查"的字符串.这可能吗?

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

推荐答案

您可以将Asset修改为Resource,获取其jcr:content/metadata孙子,然后将其修改为ModifiableValueMap:

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();

这篇关于有没有办法以编程方式设置资产的元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆