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

commit 44ae8dc9076de00ae4644919e9911f0d66316e1d
Author: Dirk Rudolph <d...@apache.org>
AuthorDate: Thu Jun 10 10:01:01 2021 +0200

    add the sitemap name to the info returned by the SitemapService
---
 .../java/org/apache/sling/sitemap/SitemapInfo.java | 11 ++++++++++
 .../sling/sitemap/impl/SitemapServiceImpl.java     | 25 ++++++++++++++++------
 .../apache/sling/sitemap/impl/SitemapStorage.java  |  3 +++
 .../sling/sitemap/impl/SitemapStorageInfo.java     | 16 ++++++++++----
 4 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/sitemap/src/main/java/org/apache/sling/sitemap/SitemapInfo.java 
b/sitemap/src/main/java/org/apache/sling/sitemap/SitemapInfo.java
index 6579b23..da1afb9 100644
--- a/sitemap/src/main/java/org/apache/sling/sitemap/SitemapInfo.java
+++ b/sitemap/src/main/java/org/apache/sling/sitemap/SitemapInfo.java
@@ -28,6 +28,8 @@ import org.osgi.annotation.versioning.ProviderType;
 @ProviderType
 public interface SitemapInfo {
 
+    String SITEMAP_INDEX_NAME = "<sitemap-index>";
+
     /**
      * Returns a resource path to the node the sitemap is stored. May return 
null if the sitemap or sitemap-index is
      * served on-demand.
@@ -46,6 +48,15 @@ public interface SitemapInfo {
     String getUrl();
 
     /**
+     * Returns the name of the sitemap. This returns null when the sitemap has 
the default name or it is a sitemap
+     * index.
+     *
+     * @return
+     */
+    @Nullable
+    String getName();
+
+    /**
      * Returns the size of the sitemap in bytes. -1 for sitemap-index or 
sitemaps served on-demand.
      *
      * @return
diff --git 
a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapServiceImpl.java 
b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapServiceImpl.java
index f5c8935..1641b8b 100644
--- 
a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapServiceImpl.java
+++ 
b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapServiceImpl.java
@@ -178,7 +178,8 @@ public class SitemapServiceImpl implements SitemapService {
             } else {
                 location += storageInfo.getSitemapSelector() + '.' + 
SitemapServlet.SITEMAP_EXTENSION;
             }
-            infos.add(newSitemapInfo(storageInfo.getPath(), location, 
storageInfo.getSize(), storageInfo.getEntries()));
+            infos.add(newSitemapInfo(storageInfo.getPath(), location, 
storageInfo.getName(), storageInfo.getSize(),
+                    storageInfo.getEntries()));
         }
 
         return infos;
@@ -244,7 +245,7 @@ public class SitemapServiceImpl implements SitemapService {
             String selector = getSitemapSelector(sitemapRoot, 
topLevelSitemapRoot, name);
             String location = topLevelSitemapRootUrl + selector + '.' + 
SitemapServlet.SITEMAP_EXTENSION;
             if (onDemandNames.contains(name)) {
-                infos.add(newSitemapInfo(null, location, -1, -1));
+                infos.add(newSitemapInfo(null, location, name, -1, -1));
             } else {
                 if (storageInfos == null) {
                     storageInfos = storage.getSitemaps(sitemapRoot, names);
@@ -254,7 +255,7 @@ public class SitemapServiceImpl implements SitemapService {
                         .findFirst();
                 if (storageInfoOpt.isPresent()) {
                     SitemapStorageInfo storageInfo = storageInfoOpt.get();
-                    infos.add(newSitemapInfo(storageInfo.getPath(), location, 
storageInfo.getSize(), storageInfo.getEntries()));
+                    infos.add(newSitemapInfo(storageInfo.getPath(), location, 
name, storageInfo.getSize(), storageInfo.getEntries()));
                 }
             }
         }
@@ -267,25 +268,29 @@ public class SitemapServiceImpl implements SitemapService 
{
     }
 
     private SitemapInfo newSitemapIndexInfo(@NotNull String url) {
-        return new SitemapInfoImpl(null, url, -1, -1, true, true);
+        return new SitemapInfoImpl(null, url, null, -1, -1, true, true);
     }
 
-    private SitemapInfo newSitemapInfo(@Nullable String path, @NotNull String 
url, int size, int entries) {
-        return new SitemapInfoImpl(path, url, size, entries, false, 
isWithinLimits(size, entries));
+    private SitemapInfo newSitemapInfo(@Nullable String path, @NotNull String 
url, @Nullable String name, int size,
+                                       int entries) {
+        return new SitemapInfoImpl(path, url, name, size, entries, false, 
isWithinLimits(size, entries));
     }
 
     private static class SitemapInfoImpl implements SitemapInfo {
 
         private final String url;
         private final String path;
+        private final String name;
         private final int size;
         private final int entries;
         private final boolean isIndex;
         private final boolean withinLimits;
 
-        private SitemapInfoImpl(@Nullable String path, @NotNull String url, 
int size, int entries, boolean isIndex, boolean withinLimits) {
+        private SitemapInfoImpl(@Nullable String path, @NotNull String url, 
@Nullable String name, int size,
+                                int entries, boolean isIndex, boolean 
withinLimits) {
             this.path = path;
             this.url = url;
+            this.name = name;
             this.size = size;
             this.entries = entries;
             this.isIndex = isIndex;
@@ -305,6 +310,12 @@ public class SitemapServiceImpl implements SitemapService {
         }
 
         @Override
+        @Nullable
+        public String getName() {
+            return name;
+        }
+
+        @Override
         public int getSize() {
             return size;
         }
diff --git 
a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java 
b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
index 2b283e3..f368de5 100644
--- a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
+++ b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
@@ -80,6 +80,7 @@ public class SitemapStorage implements Runnable {
 
     static final String PN_SITEMAP_ENTRIES = "entries";
     static final String PN_SITEMAP_SIZE = "size";
+    static final String PN_SITEMAP_NAME = "name";
 
     private static final Logger LOG = 
LoggerFactory.getLogger(SitemapStorage.class);
     private static final Map<String, Object> AUTH = 
Collections.singletonMap(ResourceResolverFactory.SUBSERVICE,
@@ -211,6 +212,7 @@ public class SitemapStorage implements Runnable {
                 properties.put(JcrConstants.JCR_PRIMARYTYPE, 
JcrConstants.NT_UNSTRUCTURED);
                 properties.put(JcrConstants.JCR_LASTMODIFIED, 
Calendar.getInstance());
                 properties.put(JcrConstants.JCR_DATA, data);
+                properties.put(PN_SITEMAP_NAME, name);
                 properties.put(PN_SITEMAP_ENTRIES, entries);
                 properties.put(PN_SITEMAP_SIZE, size);
                 properties.put(PN_RESOURCE_TYPE, RT_SITEMAP_FILE);
@@ -280,6 +282,7 @@ public class SitemapStorage implements Runnable {
                     .map(child -> new SitemapStorageInfo(
                             child.getPath(),
                             child.getName().substring(0, 
child.getName().lastIndexOf('.')),
+                            child.getValueMap().get(PN_SITEMAP_NAME, 
String.class),
                             
child.getValueMap().get(JcrConstants.JCR_LASTMODIFIED, Calendar.class),
                             child.getValueMap().get(PN_SITEMAP_SIZE, 0),
                             child.getValueMap().get(PN_SITEMAP_ENTRIES, 0)))
diff --git 
a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorageInfo.java 
b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorageInfo.java
index 312fe9e..2b284f8 100644
--- 
a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorageInfo.java
+++ 
b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorageInfo.java
@@ -26,28 +26,36 @@ import java.util.Calendar;
 class SitemapStorageInfo {
 
     private final String sitemapSelector;
+    private final String name;
     private final String path;
     private final Calendar lastModified;
     private final int size;
     private final int entries;
 
-    SitemapStorageInfo(@NotNull String path, @NotNull String sitemapSelector, 
@Nullable Calendar lastModified, int size,
+    SitemapStorageInfo(@NotNull String path, @NotNull String sitemapSelector, 
@NotNull String name,
+                       @Nullable Calendar lastModified, int size,
                        int entries) {
-        this.sitemapSelector = sitemapSelector;
         this.path = path;
+        this.sitemapSelector = sitemapSelector;
+        this.name = name;
         this.lastModified = lastModified;
         this.size = size;
         this.entries = entries;
     }
 
     @NotNull
+    public String getPath() {
+        return path;
+    }
+
+    @NotNull
     public String getSitemapSelector() {
         return sitemapSelector;
     }
 
     @NotNull
-    public String getPath() {
-        return path;
+    public String getName() {
+        return name;
     }
 
     @Nullable

Reply via email to