public Collection getSitemapInfo()

in src/main/java/org/apache/sling/sitemap/impl/SitemapServiceImpl.java [118:195]


    public Collection<SitemapInfo> getSitemapInfo(@NotNull Resource resource) {
        Resource sitemapRoot = normalizeSitemapRoot(resource);

        if (sitemapRoot == null) {
            LOG.debug("Not a sitemap root: {}", resource.getPath());
            return Collections.emptySet();
        }

        Resource topLevelSitemapRoot = isTopLevelSitemapRoot(sitemapRoot)
                ? sitemapRoot
                : getTopLevelSitemapRoot(sitemapRoot);
        String baseUrl = externalize(topLevelSitemapRoot);

        if (baseUrl == null) {
            LOG.debug("Could not get absolute url to sitemap: {}", resource.getPath());
            return Collections.emptySet();
        }

        Collection<String> names = new HashSet<>(generatorManager.getNames(sitemapRoot));
        Set<String> onDemandNames = generatorManager.getOnDemandNames(sitemapRoot);
        Collection<SitemapInfo> infos = new ArrayList<>(names.size() + 1);

        if (requiresSitemapIndex(sitemapRoot)) {
            String location = baseUrl + '.' + SitemapServlet.SITEMAP_INDEX_SELECTOR + '.' +
                    SitemapServlet.SITEMAP_EXTENSION;
            infos.add(newSitemapIndexInfo(location));
        }

        // write on demand sitemaps
        for (Iterator<String> it = names.iterator(); it.hasNext(); ) {
            String name = it.next();

            if (!onDemandNames.contains(name)) {
                continue;
            }

            it.remove();
            String selector = getSitemapSelector(sitemapRoot, topLevelSitemapRoot, name);
            String location = newSitemapUrl(baseUrl, selector);
            infos.add(newOnDemandSitemapInfo(location, name));
        }

        if (names.isEmpty()) {
            // early exit when only sitemap-index / on-demand sitemaps are served for the given root
            return infos;
        }

        for (SitemapStorageInfo storageInfo : storage.getSitemaps(sitemapRoot, names)) {
            String location = newSitemapUrl(baseUrl, storageInfo.getSitemapSelector());
            infos.add(
                    newStoredSitemapInfo(storageInfo.getPath(), location, storageInfo.getName(), storageInfo.getSize(),
                            storageInfo.getEntries()));
            names.remove(storageInfo.getName());
        }

        if (names.isEmpty()) {
            // early exit when all sitemaps are either on-demand or stored
            return infos;
        }

        // now names will contain only sitemaps that are either scheduled or not scheduled (generated on a different
        // host)
        ServiceReference<SitemapScheduler>[] schedulerRefs = schedulers.getServiceReferences();
        for (String name : names) {
            // check if a scheduler applicable for the name exists
            boolean hasApplicableScheduler = schedulerRefs != null && Arrays.stream(schedulerRefs)
                    .map(schedulers::getService)
                    .map(scheduler -> scheduler.getApplicableNames(resource))
                    .anyMatch(applicableNames -> applicableNames.contains(name));
            String selector = getSitemapSelector(sitemapRoot, topLevelSitemapRoot, name);
            String location = newSitemapUrl(baseUrl, selector);
            infos.add(newOnDemandSitemapInfo(location, name,
                    hasApplicableScheduler ? SitemapInfo.Status.SCHEDULED : SitemapInfo.Status.UNKNOWN));
        }


        return infos;
    }