[ https://issues.apache.org/jira/browse/SLING-9417?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Robert Munteanu updated SLING-9417: ----------------------------------- Fix Version/s: JCR Resource 3.0.22 > Content-type and InputStream are null when accessing nt:file resources with > ";v=" > --------------------------------------------------------------------------------- > > Key: SLING-9417 > URL: https://issues.apache.org/jira/browse/SLING-9417 > Project: Sling > Issue Type: Bug > Components: JCR > Reporter: Matthias Herold > Priority: Minor > Fix For: JCR Resource 3.0.22 > > Original Estimate: 1h > Time Spent: 2h 20m > Remaining Estimate: 0h > > When using the methods resource.getMetadata().getContentType() or > resource.adaptTo(InputStream.class), both methods return null when: > # the resource is a child of a versionable node, > # the resource is of type nt:file, and > # resource has been looked up with a version identifier in the URL (";v="). > From my understanding, both methods should return the relevant values from > the frozen node. The error occurs because of line 185 in JcrNodeResource.java > {{Node content = node.isNodeType(NT_FILE)}} > {{? node.getNode(JCR_CONTENT)}} > {{: node.isNodeType(NT_LINKEDFILE) ? node.getProperty(JCR_CONTENT).getNode() > : node;}} > When the resource is looked up with a version modifier, the node type will > not nt:file. Instead it is jcr:frozenNode with a property > jcr:frozenPrimaryType set to nt:file. Therefore, the above code fails and > will not use the jcr:content subnode, but the node itself. In my opinion, it > would be better to change this to: > {{{{Node content = (node.isNodeType(NodeType.NT_FILE) || > (node.isNodeType("nt:frozenNode") && > node.hasProperty("jcr:frozenPrimaryType") }}}} > {{ && > node.getProperty("jcr:frozenPrimaryType").getString().equals(NT_FILE)))}} > {{ ? node.getNode(Node.JCR_CONTENT)}}}} > {{ : node.isNodeType(JcrConstants.NT_LINKEDFILE) ? > node.getProperty(Node.JCR_CONTENT).getNode() : node;}} > > JcrResourceMetadata has the same issue (line 65): > {{ if ( (!nodePromotionChecked) && node.isNodeType(NT_FILE)) {}} > This could be changed to: > {{ if ( (!nodePromotionChecked) && (node.isNodeType(NT_FILE) ||}} > {{ (node.isNodeType("nt:frozenNode") && > node.hasProperty("jcr:frozenPrimaryType") }} > {{ && > node.getProperty("jcr:frozenPrimaryType").getString().equals(NT_FILE)))) {}} > > As I'm still a newbie in Sling, I'm not sure if the proposed solution is > completely right. At the moment, I use a ResourceDecorator for my project > with these changes and this fixes my problem - but there might be a better > way to solve this. > > -- This message was sent by Atlassian Jira (v8.3.4#803005)