Skip to content

Commit

Permalink
treat nt:resource and oak:resource the same when detecting content type
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 12, 2024
1 parent 1728b0a commit 40d7a1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/io/wcm/handler/media/impl/JcrBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.wcm.handler.media.impl;

import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants;
import org.apache.sling.api.resource.Resource;
import org.osgi.annotation.versioning.ProviderType;

Expand Down Expand Up @@ -50,7 +51,9 @@ public static boolean isNtFile(Resource resource) {
* @return true if resource is nt:file node
*/
public static boolean isNtResource(Resource resource) {
return isNt(resource, JcrConstants.NT_RESOURCE);
return isNt(resource, JcrConstants.NT_RESOURCE)
// also check for oak:resource which is used in replacement of nt:resource
|| isNt(resource, NodeTypeConstants.NT_OAK_RESOURCE);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/io/wcm/handler/media/impl/JcrBinaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -54,6 +55,14 @@ void testIsNtFileResource_Resource() {
assertTrue(JcrBinary.isNtFileOrResource(resource));
}

@Test
void testIsNtFileResource_OakResource() {
when(resource.getResourceType()).thenReturn(NodeTypeConstants.NT_OAK_RESOURCE);
assertFalse(JcrBinary.isNtFile(resource));
assertTrue(JcrBinary.isNtResource(resource));
assertTrue(JcrBinary.isNtFileOrResource(resource));
}

@Test
void testIsNtFileResource_File() {
when(resource.getResourceType()).thenReturn(JcrConstants.NT_FILE);
Expand Down

0 comments on commit 40d7a1c

Please sign in to comment.