You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by di...@apache.org on 2021/06/11 12:42:43 UTC

[sling-whiteboard] branch master updated: updated readme

This is an automated email from the ASF dual-hosted git repository.

diru pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 74ba698  updated readme
74ba698 is described below

commit 74ba6985c231276ff7f070233f296d3e1f8ba84b
Author: Dirk Rudolph <di...@apache.org>
AuthorDate: Fri Jun 11 14:42:31 2021 +0200

    updated readme
---
 sitemap/README.md                                  | 19 +++++++------
 .../apache/sling/sitemap/impl/SitemapServlet.java  | 31 ++++++++++++----------
 2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/sitemap/README.md b/sitemap/README.md
index 6123049..73e4909 100644
--- a/sitemap/README.md
+++ b/sitemap/README.md
@@ -108,16 +108,15 @@ particular cases.
 #### On-demand Generation
 
 For smaller sites, calculating sitemaps in the background may not be necessary and serving sitemaps when they get
-requested may even result in higher accuracy. On the other hand it highly depends on the amount of content and
-the `SitemapGeneator` implementation(s) used, if it is possible to serve a sitemap within the timeout of the different
-crawlers. Because of that, serving sitemaps on-demand must be explicitly enabled.
-
-To configure serving sitemaps on-demand, set the `onDemandNames` of the `SitemapServiceImpl`. When set, the
-`SitemapServlet` slightly changes its behaviour. The sitemap index is now served based on a query of all sitemap roots
-below the requested resource to check if any of them generates a sitemap for the on-demand names, instead of simply
-creating an index of all stored sitemaps at the requested sitemap root. For the sitemaps the sitemap selector will be
-resolved to sitemap-root-name pairs to check if any of them can be served on-demand, instead of serving a file from the
-storage. However in either of the cases the mechanism falls back to the sitemaps generated in the background.
+requested may even result in higher accuracy. On the other hand serving a sitemap on-demand within the timeout of 
+different crawlers highly depends on the amount of content and the `SitemapGeneator` implementation(s) used. Because of 
+that, serving sitemaps on-demand must be explicitly enabled.
+
+To configure serving sitemaps on-demand, set the `onDemandGenerators` of the `SitemapServiceConfiguration` PID. When 
+set, the `SitemapServlet` queries for all sitemap root resources and checks if any of them is served with a name of the
+on-demand generators. If so the sitemap root with the name will be added to the sitemap-index or the sitemap being 
+requested on-demand will be served respectively. In any case the mechanism always fallback serving sitemaps from 
+storage.   
 
 ### Sitemap Extensions
 
diff --git a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java
index 6d00910..a420fca 100644
--- a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java
+++ b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java
@@ -153,20 +153,22 @@ public class SitemapServlet extends SlingSafeMethodsServlet {
 
     protected void doGetSitemap(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response,
                                 Resource topLevelSitemapRoot, String sitemapSelector) throws SitemapException, IOException {
-        // resolve the actual sitemap root from the sitemapFileName
-        Map<Resource, String> candidates = resolveSitemapRoots(topLevelSitemapRoot, sitemapSelector);
-
-        for (Map.Entry<Resource, String> entry : candidates.entrySet()) {
-            Resource sitemapRoot = entry.getKey();
-            String name = entry.getValue();
-            SitemapGenerator generator = generatorManager.getGenerator(sitemapRoot, name);
-
-            if (generator != null
-                    && sitemapServiceConfiguration.getOnDemandGenerators().contains(generator.getClass().getName())) {
-                SitemapImpl sitemap = new SitemapImpl(response.getWriter(), extensionProviderManager);
-                generator.generate(sitemapRoot, name, sitemap, NOOP_CONTEXT);
-                sitemap.close();
-                return;
+        if (sitemapServiceConfiguration.getOnDemandGenerators().size() > 0) {
+            // resolve the actual sitemap root from the sitemapFileName
+            Map<Resource, String> candidates = resolveSitemapRoots(topLevelSitemapRoot, sitemapSelector);
+
+            for (Map.Entry<Resource, String> entry : candidates.entrySet()) {
+                Resource sitemapRoot = entry.getKey();
+                String name = entry.getValue();
+                SitemapGenerator generator = generatorManager.getGenerator(sitemapRoot, name);
+
+                if (generator != null
+                        && sitemapServiceConfiguration.getOnDemandGenerators().contains(generator.getClass().getName())) {
+                    SitemapImpl sitemap = new SitemapImpl(response.getWriter(), extensionProviderManager);
+                    generator.generate(sitemapRoot, name, sitemap, NOOP_CONTEXT);
+                    sitemap.close();
+                    return;
+                }
             }
         }
 
@@ -191,6 +193,7 @@ public class SitemapServlet extends SlingSafeMethodsServlet {
         if (onDemandSitemaps.isEmpty()) {
             return Collections.emptySet();
         }
+
         Set<String> addedSitemapSelectors = new HashSet<>();
         Iterator<Resource> sitemapRoots = findSitemapRoots(request.getResourceResolver(), parentSitemapRoot.getPath());
         if (!sitemapRoots.hasNext()) {