You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by re...@apache.org on 2025/05/19 15:29:36 UTC

(sling-org-apache-sling-resourceresolver) 01/01: SLING-12787: ResourceResolver: alias refactoring - use Resource instead of Path when getting aliases

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

reschke pushed a commit to branch SLING-12787
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit 704161a61ba465391c90033baf5156b1491a749b
Author: Julian Reschke <re...@apache.org>
AuthorDate: Mon May 19 16:29:15 2025 +0100

    SLING-12787: ResourceResolver: alias refactoring - use Resource instead of Path when getting aliases
---
 .../impl/mapping/ResourceMapperImpl.java               | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
index 2366ebc3..c02663b2 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
@@ -233,16 +233,18 @@ public class ResourceMapperImpl implements ResourceMapper {
 
     private void resolveAliases(Resource res, PathGenerator pathBuilder) {
         String path = res.getPath();
+        Resource current = res;
 
-        while (path != null) {
+        while (path != null && current != null) {
             Collection<String> aliases = Collections.emptyList();
             // read alias only if we can read the resources and it's not a jcr:content leaf
             if (!path.endsWith(ResourceResolverImpl.JCR_CONTENT_LEAF)) {
-                aliases = readAliases(path);
+                aliases = readAliases(current);
             }
             // build the path from the name segments or aliases
             pathBuilder.insertSegment(aliases, ResourceUtil.getName(path));
             path = ResourceUtil.getParent(path);
+            current = current.getParent();
             if ("/".equals(path)) {
                 path = null;
             }
@@ -251,15 +253,17 @@ public class ResourceMapperImpl implements ResourceMapper {
 
     /**
      * Resolve the aliases for the given resource by a lookup in MapEntries
-     * @param path path for which to lookup aliases
+     * @param resource resource for which to lookup aliases
      * @return collection of aliases for that resource
      */
-    private Collection<String> readAliases(String path) {
-        String parentPath = ResourceUtil.getParent(path);
-        if (parentPath == null) {
+    private Collection<String> readAliases(Resource resource) {
+        Resource parent = resource.getParent();
+        if (parent == null) {
             return Collections.emptyList();
         } else {
-            return mapEntries.getAliasMap(parentPath).getOrDefault(ResourceUtil.getName(path), Collections.emptyList());
+            return mapEntries
+                    .getAliasMap(parent)
+                    .getOrDefault(ResourceUtil.getName(resource.getPath()), Collections.emptyList());
         }
     }