On Thursday, March 14, 2013, Ulrich wrote:
> When running this code:
>
>
> Property jcrdata;
> for (PropertyIterator pi = fileNode.getProperties(); pi.hasNext(); ) {
> Property p = pi.nextProperty();
> LOGGER.info("Property is: " + p.getName() + "=" +
> p.getValue().getString());
> }
> jcrdata = fileNode.getProperty("jcr:data");
>
> the for-loop works fine and displays the property "jcr:data" and it's
> value. But
> the last line:
> Property jcrdata = fileNode.getProperty("jcr:data");
> fails with "javax.jcr.PathNotFoundException: jcr:data".
what is the node type of fileNode?
i assume it's nt:file. nt:file doesn't declare a jcr:data property.
it declares a jcr:content node which commonly is a nt:resource.
nt:resource does declare a jcr:data property.
i.e. fileNode.getNode("jcr:content").getProperty("jcr:data")
cheers
stefan
When I change the code to
> Property jcrdata;
> for (PropertyIterator pi = fileNode.getProperties(); pi.hasNext(); ) {
> Property p = pi.nextProperty();
> LOGGER.info("Property is: " + p.getName() + "=" +
> p.getValue().getString());
> if (p.getName().equals("jcr:data")) {
> jcrdata = p;
> }
> the program works fine.
>
> I don't see what might go wrong in the first sample. I would rather prefer
> the
> first one. Does anyone has an explanation for this?
>
> Ulrich
>