【问题标题】:how can I save text content as jcr:data property in aem?如何将文本内容保存为 aem 中的 jcr:data 属性?
【发布时间】:2017-08-05 17:19:59
【问题描述】:

我有一个节点,其中包含大量存储为 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

【问题讨论】:

    标签: java groovy osgi aem


    【解决方案1】:

    你记得导入 javax.jcr.Binary 吗?

    Esit:您在 .array() 之前缺少一个括号

    【讨论】:

    • 是的,我已经导入了这个......虽然它仍然看不到Binary......但也许还有其他方法可以将我自己的内容写入jcr:data,而不是使用Binary?
    • 嘿伙计,在 array() 之后缺少括号,谢谢你注意到它!
    猜你喜欢
    • 2013-03-13
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多