in src/main/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGenerator.java [96:122]
private Stream<Resource> traverse(@NotNull Resource sitemapRoot, @Nullable String skipTo) {
Stream<Resource> children = StreamSupport.stream(sitemapRoot.getChildren().spliterator(), false)
.filter(this::shouldFollow);
if (skipTo != null) {
AtomicBoolean found = new AtomicBoolean(false);
// advance children until skipTo starts either with the child's path or it is equal to it
return children.flatMap(child -> {
if (found.get()) {
return traverse(child, null);
} else if (skipTo.equals(child.getPath())) {
found.set(true);
return traverse(child, null);
} else if (skipTo.startsWith(child.getPath() + '/')) {
found.set(true);
return traverse(child, skipTo);
} else {
return Stream.empty();
}
});
} else {
return Stream.concat(
shouldInclude(sitemapRoot) ? Stream.of(sitemapRoot) : Stream.empty(),
children.flatMap(child -> traverse(child, null))
);
}
}