@Test public void loadSingleResourceFromRoot() { Resource resource = context.resourceResolver().getResource("/md-test"); assertThat("resource", resource, notNullValue()); assertThat("resource.getValueMap()", resource.getValueMap(), notNullValue()); assertThat("resource.getMetadata()", resource.getResourceMetadata(), notNullValue()); assertThat("resource.getMetadata().getPath()", resource.getResourceMetadata().getResolutionPath(), equalTo("/md-test2")); assertThat("valueMap[jcr:title]", resource.getValueMap().get("jcr:title", String.class), equalTo("Simple markdown file")); assertThat("valueMap[jcr:description]", resource.getValueMap().get("jcr:description", String.class), equalTo("<p>This is an example of a simple markdown file</p>\n")); assertThat("valueMap[sling:resourceType]", resource.getValueMap().get("sling:resourceType", String.class), equalTo("sling/markdown/file")); assertThat("valueMap[author]", resource.getValueMap().get("author", String.class), equalTo("John Doe")); assertThat("valueMap[keywords]", resource.getValueMap().get("keywords", String[].class), equalTo(new String[] {"news", "simple"})); ValueMap adapted = resource.adaptTo(ValueMap.class); assertThat("adapted ValueMap", adapted, notNullValue()); assertThat("adapted Map", resource.adaptTo(Map.class), notNullValue()); }
@Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { Path filePath = Paths.get(fsPath, path, INDEX_FILE_NAME); File backingFile = filePath.toFile(); if ( !backingFile.canRead() ) { filePath = Paths.get(fsPath, path + MARKDOWN_EXTENSION); backingFile = filePath.toFile(); if ( !backingFile.canRead() ) return null; } return new MarkdownResource(ctx.getResourceResolver(), path, backingFile); }
MarkdownResourceProvider extends ResourceProvider<Object> { @Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { Path filePath = Paths.get(fsPath, path, INDEX_FILE_NAME); File backingFile = filePath.toFile(); if ( !backingFile.canRead() ) { filePath = Paths.get(fsPath, path + MARKDOWN_EXTENSION); backingFile = filePath.toFile(); if ( !backingFile.canRead() ) return null; } return new MarkdownResource(ctx.getResourceResolver(), path, backingFile); } }
MarkdownResourceProvider extends ResourceProvider<Object> { @Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { Path filePath = Paths.get(fsPath, path, INDEX_FILE_NAME); File backingFile = filePath.toFile(); if ( !backingFile.canRead() ) { filePath = Paths.get(fsPath, path + MARKDOWN_EXTENSION); backingFile = filePath.toFile(); if ( !backingFile.canRead() ) return null; } return new MarkdownResource(ctx.getResourceResolver(), path, backingFile); }  }
MarkdownResourceProvider extends ResourceProvider<Object> { @Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { Path filePath = Paths.get(fsPath, path, INDEX_FILE_NAME); File backingFile = filePath.toFile(); if ( !backingFile.canRead() ) { filePath = Paths.get(fsPath, path + MARKDOWN_EXTENSION); backingFile = filePath.toFile(); if ( !backingFile.canRead() ) return null; } return new MarkdownResource(ctx.getResourceResolver(), path, backingFile); }  @Override Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext,
            Resource parent); @Override Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent); }
MarkdownResourceProvider extends ResourceProvider<Object> { @Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { Path filePath = Paths.get(fsPath, path, INDEX_FILE_NAME); File backingFile = filePath.toFile(); if ( !backingFile.canRead() ) { filePath = Paths.get(fsPath, path + MARKDOWN_EXTENSION); backingFile = filePath.toFile(); if ( !backingFile.canRead() ) return null; } return new MarkdownResource(ctx.getResourceResolver(), path, backingFile); }  @Override Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext,
            Resource parent); @Override Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent);  }