如何在 aem 中将文本内容保存为 jcr:data 属性?
how can I save text content as jcr:data property in aem?
我有一个节点,其中包含大量存储为 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()
之前少了一个括号
我有一个节点,其中包含大量存储为 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()
之前少了一个括号