Prevail
Prevail

Reputation: 57

Update content of node in JCR 2.0

I try to update node in JCR 2.0

InputStream content = node.getProperty("jcr:content").getProperty("jcr:data").getBinary().getStream();

//TODO same with stream
Binary value = ...;

Node contentNode = node.getProperty("jcr:content");
contentNode.setProperty("jcr:content", value);

And I get exception "javax.jcr.nodetype.ConstraintViolationException: Item is protected". What`s wrong?

Upvotes: 4

Views: 3820

Answers (1)

Jukka Zitting
Jukka Zitting

Reputation: 1092

The "jcr:content" you're referring to is typically the name of a child node (usually of type nt:resource, or something similar), rather than a property. Thus your code sample should rather be:

// read value
Binary value = node.getNode("jcr:content").getProperty("jcr:data").getBinary();

// update value
Binary value = ...;
node.getNode("jcr:content").setProperty("jcr:data", value);

See also the putFile() utility methods in the JcrUtils class of the jackrabbit-jcr-commons library.

Upvotes: 5

Related Questions