gpt4 book ai didi

java - 如何将文本内容另存为 jcr :data property in aem?

转载 作者:行者123 更新时间:2023-12-02 12:25:21 25 4
gpt4 key购买 nike

我有一个节点,其中包含存储为其 jcr:data 属性的大量文本。我可以通过以下 groovy 代码读取它并在控制台中显示它:

InputStream content = node.getNode("jcr:content").getProperty("jcr:data")
.getStream()
println(content.text) //it shows me its content = text

现在我想更改此文本中的一些字符,并将其再次设置为 jcr:data 属性。我尝试这样做:

ValueFactory factory = session.getValueFactory()
InputStream is = new ByteArrayInputStream(Charset.forName("UTF-8")
.encode(content.text.replaceAll("xx", "yy").array())
Binary binary = factory.createBinary(is)
Value value = factory.createValue(binary)
node.setProperty("jcr:data", value)

但这会引发错误:

unexpected token: Binary

最佳答案

您还记得导入 javax.jcr.Binary 吗?

Esit: .array() 之前缺少括号

关于java - 如何将文本内容另存为 jcr :data property in aem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45524574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com