private Iterator findChildren()

in src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java [151:203]


    private Iterator<Resource> findChildren(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 = resolveFile(parentPath);
        if (parentFile != null && fileStatCache.isDirectory(parentFile)) {
            File[] files = parentFile.listFiles();
            Arrays.sort(files, FileNameComparator.INSTANCE);
            for (File childFile : files) {
                String childPath = parentPath + "/" + PlatformNameFormat.getRepositoryName(childFile.getName());
                File file = resolveFile(childPath);
                if (file != null && pathMatches(childPath) && !childPaths.contains(childPath)) {
                    childPaths.add(childPath);
                    continue;
                }

                // strip xml extension unless it's .content.xml - the xml extension is re-added inside getContentFile
                if (!childPath.endsWith('/' + DOT_CONTENT_XML)) {
                    childPath = StringUtils.removeEnd(childPath, XML_SUFFIX);
                }
                ContentFile contentFile = getContentFile(childPath, null);
                if (contentFile != null && pathMatches(childPath) && !childPaths.contains(childPath)) {
                    childPaths.add(childPath);
                }
            }
        }

        if (childPaths.isEmpty()) {
            return null;
        } else {
            return IteratorUtils.transformedIterator(childPaths.iterator(), new Transformer<String, Resource>() {
                @Override
                public Resource transform(final String path) {
                    return findResource(resolver, path);
                }
            });
        }
    }