You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:00:01 UTC

[sling-org-apache-sling-resourceresolver] 31/47: SLING-2598 : Don't process already defined vanity paths

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

rombert pushed a commit to annotated tag org.apache.sling.resourceresolver-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit 14913d4d25ccaf046b6549bd3f35e94464c6f6c2
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Sep 14 12:28:28 2012 +0000

    SLING-2598 :  Don't process already defined vanity paths
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/resourceresolver@1384739 13f79535-47bb-0310-9956-ffa450edef68
---
 .../resourceresolver/impl/mapping/MapEntries.java  | 53 ++++++++++++----------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
index 7b43f3f..01afbae 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
@@ -525,9 +525,11 @@ public class MapEntries implements EventHandler {
         // sling:VanityPath (uppercase V) is the mixin name
         // sling:vanityPath (lowercase) is the property name
         final Set<String> targetPaths = new HashSet<String>();
-        final String queryString = "SELECT sling:vanityPath, sling:redirect, sling:redirectStatus FROM sling:VanityPath WHERE sling:vanityPath IS NOT NULL ORDER BY sling:vanityOrder DESC";
+        final String queryString = "SELECT sling:vanityPath, sling:redirect, sling:redirectStatus, sling:vanityOrder FROM sling:VanityPath WHERE sling:vanityPath IS NOT NULL ORDER BY sling:vanityOrder DESC";
         final Iterator<Resource> i = resolver.findResources(queryString, "sql");
 
+        final Set<String> processedVanityPaths = new HashSet<String>();
+
         while (i.hasNext()) {
             final Resource resource = i.next();
 
@@ -552,33 +554,36 @@ public class MapEntries implements EventHandler {
                 if (result != null) {
                     final String url = result[0] + result[1];
 
-                    // redirect target is the node providing the
-                    // sling:vanityPath
-                    // property (or its parent if the node is called
-                    // jcr:content)
-                    final String redirect;
-                    if (resource.getName().equals("jcr:content")) {
-                        redirect = resource.getParent().getPath();
-                    } else {
-                        redirect = resource.getPath();
-                    }
+                    if ( !processedVanityPaths.contains(url) ) {
+                        processedVanityPaths.add(url);
+                        // redirect target is the node providing the
+                        // sling:vanityPath
+                        // property (or its parent if the node is called
+                        // jcr:content)
+                        final String redirect;
+                        if (resource.getName().equals("jcr:content")) {
+                            redirect = resource.getParent().getPath();
+                        } else {
+                            redirect = resource.getPath();
+                        }
 
-                    // whether the target is attained by a 302/FOUND or by an
-                    // internal redirect is defined by the sling:redirect
-                    // property
-                    final int status = props.get("sling:redirect", false) ? props.get(
-                                    PROP_REDIRECT_EXTERNAL_REDIRECT_STATUS, HttpServletResponse.SC_FOUND)
-                                    : -1;
+                        // whether the target is attained by a 302/FOUND or by an
+                        // internal redirect is defined by the sling:redirect
+                        // property
+                        final int status = props.get("sling:redirect", false) ? props.get(
+                                        PROP_REDIRECT_EXTERNAL_REDIRECT_STATUS, HttpServletResponse.SC_FOUND)
+                                        : -1;
 
-                                    final String checkPath = result[1];
-                                    // 1. entry with exact match
-                                    this.addEntry(entryMap, checkPath, new MapEntry(url + "$", status, false, redirect + ".html"));
+                        final String checkPath = result[1];
+                        // 1. entry with exact match
+                        this.addEntry(entryMap, checkPath, new MapEntry(url + "$", status, false, redirect + ".html"));
 
-                                    // 2. entry with match supporting selectors and extension
-                                    this.addEntry(entryMap, checkPath, new MapEntry(url + "(\\..*)", status, false, redirect + "$1"));
+                        // 2. entry with match supporting selectors and extension
+                        this.addEntry(entryMap, checkPath, new MapEntry(url + "(\\..*)", status, false, redirect + "$1"));
 
-                                    // 3. keep the path to return
-                                    targetPaths.add(redirect);
+                        // 3. keep the path to return
+                        targetPaths.add(redirect);
+                    }
                 }
             }
         }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.