in src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResourceMapper.java [75:131]
public Iterator<Resource> getChildren(final ResourceResolver resolver, final Resource parent) {
final String parentPath = parent.getPath();
File parentFile = parent.adaptTo(File.class);
// not a FsResource, try to create one from the resource
if (parentFile == null) {
// if the parent path is at or below the provider root, get
// the respective file
parentFile = getFile(parentPath);
// if the parent path is actually the parent of the provider
// root, return a single element iterator just containing the
// provider file, unless the provider file is a directory and
// a repository item with the same path actually exists
if (parentFile == null) {
if (!StringUtils.startsWith(parentPath, providerRoot)) {
String parentPathPrefix = parentPath.concat("/");
if (providerRoot.startsWith(parentPathPrefix)) {
String relPath = providerRoot.substring(parentPathPrefix.length());
if (relPath.indexOf('/') < 0) {
Resource res = new FileResource(resolver, providerRoot, providerFile, contentFileExtensions, contentFileCache, fileStatCache);
return IteratorUtils.singletonIterator(res);
}
}
}
// no children here
return null;
}
}
File[] files = parentFile.listFiles();
if (files == null) {
return null;
}
Arrays.sort(files, FileNameComparator.INSTANCE);
Iterator<File> children = IteratorUtils.filteredIterator(IteratorUtils.arrayIterator(files), new Predicate() {
@Override
public boolean evaluate(Object object) {
File file = (File)object;
return !contentFileExtensions.matchesSuffix(file);
}
});
if (!children.hasNext()) {
return null;
}
return IteratorUtils.transformedIterator(children, new Transformer() {
@Override
public Object transform(Object input) {
File file = (File)input;
String path = parentPath + "/" + Escape.fileToResourceName(file.getName());
return new FileResource(resolver, path, file, contentFileExtensions, contentFileCache, fileStatCache);
}
});
}