private Set addOnDemandSitemapsToIndex()

in src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java [193:224]


    private Set<String> addOnDemandSitemapsToIndex(SlingHttpServletRequest request, Resource topLevelSitemapRoot,
            SitemapIndexImpl index) throws SitemapException {
        Set<String> addedSitemapSelectors = new HashSet<>();
        Iterator<Resource> sitemapRoots = findSitemapRoots(request.getResourceResolver(), topLevelSitemapRoot.getPath());
        if (!sitemapRoots.hasNext()) {
            // serve at least the top level sitemap
            sitemapRoots = Collections.singleton(topLevelSitemapRoot).iterator();
        } else {
            // chain with the given sitemap root as it is not part of the result set
            sitemapRoots = new ChainedIterator<>(
                sitemapRoots,
                Collections.singleton(topLevelSitemapRoot).iterator()
            );
        }
        while (sitemapRoots.hasNext()) {
            Resource sitemapRoot = sitemapRoots.next();
            Set<String> applicableNames = generatorManager.getOnDemandNames(sitemapRoot);
            // applicable names we may serve directly, not applicable names, if any, we have to serve from storage
            for (String applicableName : applicableNames) {
                String sitemapSelector = getSitemapSelector(sitemapRoot, topLevelSitemapRoot, applicableName);
                String location = externalize(request, getSitemapLink(topLevelSitemapRoot, sitemapSelector));
                if (location != null) {
                    index.addSitemap(location);
                    addedSitemapSelectors.add(sitemapSelector);
                } else {
                    LOG.debug("Could not get absolute url for on-demand sitemap: {}", sitemapSelector);
                }
            }
        }

        return addedSitemapSelectors;
    }