This is an automated email from the ASF dual-hosted git repository.
dklco 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 40e0a7b Adding a method to list the renditions available on a file
40e0a7b is described below
commit 40e0a7b9ce03a267deb2f268bd659fe598aeaa68
Author: Dan Klco <[email protected]>
AuthorDate: Fri Jul 16 14:50:26 2021 -0400
Adding a method to list the renditions available on a file
---
.../org/apache/sling/thumbnails/RenditionSupport.java | 10 ++++++++++
.../sling/thumbnails/internal/RenditionSupportImpl.java | 16 ++++++++++++++++
2 files changed, 26 insertions(+)
diff --git
a/org.apache.sling.thumbnails/src/main/java/org/apache/sling/thumbnails/RenditionSupport.java
b/org.apache.sling.thumbnails/src/main/java/org/apache/sling/thumbnails/RenditionSupport.java
index f389e89..f655e24 100644
---
a/org.apache.sling.thumbnails/src/main/java/org/apache/sling/thumbnails/RenditionSupport.java
+++
b/org.apache.sling.thumbnails/src/main/java/org/apache/sling/thumbnails/RenditionSupport.java
@@ -17,6 +17,7 @@
package org.apache.sling.thumbnails;
import java.io.InputStream;
+import java.util.List;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
@@ -52,6 +53,15 @@ public interface RenditionSupport {
InputStream getRenditionContent(@NotNull Resource file, @NotNull String
renditionName);
/**
+ * Retrieves all of the renditions for the specified file.
+ *
+ * @param file the file from which to retrieve the renditions
+ * @return the renditions
+ */
+ @NotNull
+ List<Resource> listRenditions(@NotNull Resource file);
+
+ /**
* Returns true if the requested rendition exists for the specified file.
*
* @param file the file to check
diff --git
a/org.apache.sling.thumbnails/src/main/java/org/apache/sling/thumbnails/internal/RenditionSupportImpl.java
b/org.apache.sling.thumbnails/src/main/java/org/apache/sling/thumbnails/internal/RenditionSupportImpl.java
index a17c13d..cad8477 100644
---
a/org.apache.sling.thumbnails/src/main/java/org/apache/sling/thumbnails/internal/RenditionSupportImpl.java
+++
b/org.apache.sling.thumbnails/src/main/java/org/apache/sling/thumbnails/internal/RenditionSupportImpl.java
@@ -17,10 +17,13 @@
package org.apache.sling.thumbnails.internal;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.stream.StreamSupport;
import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.resource.LoginException;
@@ -65,6 +68,19 @@ public class RenditionSupportImpl implements
RenditionSupport {
}
@Override
+ public @NotNull List<Resource> listRenditions(@NotNull Resource file) {
+ List<Resource> renditions = new ArrayList<>();
+ if (this.supportsRenditions(file)) {
+
Optional.ofNullable(file.getChild(thumbnailSupport.getRenditionPath(file.getResourceType())))
+ .ifPresent(renditionFolder -> {
+
StreamSupport.stream(renditionFolder.getChildren().spliterator(), false)
+ .filter(c ->
JcrConstants.NT_FILE.equals(c.getResourceType())).forEach(renditions::add);
+ });
+ }
+ return renditions;
+ }
+
+ @Override
public boolean renditionExists(@NotNull Resource file, @NotNull String
renditionName) {
return getRendition(file, renditionName) != null;
}