use of org.apache.sling.fsprovider.internal.parser.ContentElement in project sling by apache.
the class FileVaultResourceMapper method getChildren.
@SuppressWarnings("unchecked")
@Override
public Iterator<Resource> getChildren(final ResourceResolver resolver, final Resource parent) {
String parentPath = parent.getPath();
Set<String> childPaths = new LinkedHashSet<>();
// get children from content resource of parent
ContentFile parentContentFile = getContentFile(parentPath, null);
if (parentContentFile != null) {
Iterator<Map.Entry<String, ContentElement>> childMaps = parentContentFile.getChildren();
while (childMaps.hasNext()) {
Map.Entry<String, ContentElement> entry = childMaps.next();
String childPath = parentPath + "/" + entry.getKey();
if (pathMatches(childPath)) {
childPaths.add(childPath);
}
}
}
// additional check for children in file system
File parentFile = getFile(parentPath);
if (parentFile != null && parentFile.isDirectory()) {
for (File childFile : parentFile.listFiles()) {
String childPath = parentPath + "/" + PlatformNameFormat.getRepositoryName(childFile.getName());
if (pathMatches(childPath) && !childPaths.contains(childPath)) {
childPaths.add(childPath);
}
}
}
if (childPaths.isEmpty()) {
return null;
} else {
return IteratorUtils.transformedIterator(childPaths.iterator(), new Transformer() {
@Override
public Object transform(Object input) {
String path = (String) input;
return getResource(resolver, path);
}
});
}
}
use of org.apache.sling.fsprovider.internal.parser.ContentElement in project sling by apache.
the class ContentFileTest method testRootContent.
@Test
public void testRootContent() {
File file = new File("src/test/resources/fs-test/folder2/content.json");
ContentFile underTest = new ContentFile(file, "/fs-test/folder2/content", null, contentFileCache);
assertEquals(file, underTest.getFile());
assertNull(underTest.getSubPath());
assertTrue(underTest.hasContent());
ContentElement content = underTest.getContent();
assertEquals("app:Page", content.getProperties().get("jcr:primaryType"));
assertEquals("app:PageContent", content.getChild("jcr:content").getProperties().get("jcr:primaryType"));
ValueMap props = underTest.getValueMap();
assertEquals("app:Page", props.get("jcr:primaryType"));
assertNull(props.get("jcr:content"));
}
Aggregations