private boolean doesSitemapRootExist()

in src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java [391:419]


    private boolean doesSitemapRootExist(Resource sitemapFile) {
        String path = sitemapFile.getPath();
        String parentPath = ResourceUtil.getParent(path);
        String sitemapRootPath = parentPath.substring(rootPath.length());
        Resource sitemapRoot = sitemapFile.getResourceResolver().getResource(sitemapRootPath);

        if (sitemapRoot == null || !SitemapUtil.isTopLevelSitemapRoot(sitemapRoot)) {
            LOG.debug("Sitemap file's top level sitemap root does not exist: {}", sitemapRootPath);
            return false;
        }

        String name = sitemapFile.getName();
        int lastDot = name.lastIndexOf('.');

        if (lastDot < 0) {
            LOG.debug("Unexpected name, missing extension: {}", name);
            return false;
        }

        Map<Resource, String> candidates = SitemapUtil.resolveSitemapRoots(sitemapRoot, name.substring(0, lastDot));
        // check if for any of the candidate resource roots a generator with the name exists
        return candidates.entrySet().stream()
                .anyMatch(entry -> {
                    Resource resource = entry.getKey();
                    Set<String> names = generatorManager.getNames(resource);
                    Set<String> onDemandNames = generatorManager.getOnDemandNames(resource);
                    return names.contains(entry.getValue()) && !onDemandNames.contains(entry.getValue());
                });
    }