incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1590592 - in /sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl: ./ mapping/
Date Mon, 28 Apr 2014 10:37:37 GMT
Author: asanso
Date: Mon Apr 28 10:37:36 2014
New Revision: 1590592

URL: http://svn.apache.org/r1590592
Log:
SLING-3428 - vanity paths might be shadowed by url mappings

Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java?rev=1590592&r1=1590591&r2=1590592&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
Mon Apr 28 10:37:36 2014
@@ -199,6 +199,10 @@ public class CommonResourceResolverFacto
     public boolean isOptimizeAliasResolutionEnabled() {
         return this.activator.isOptimizeAliasResolutionEnabled();
     }
+    
+    public boolean hasVanityPathPrecedence() {
+        return this.activator.hasVanityPathPrecedence();
+    }
 
     public List<VanityPathConfig> getVanityPathConfig() {
         final String[] includes = this.activator.getVanityPathWhiteList();

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java?rev=1590592&r1=1590591&r2=1590592&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
Mon Apr 28 10:37:36 2014
@@ -206,7 +206,14 @@ public class ResourceResolverFactoryActi
                     "such a list is configured,vanity paths from resources starting with
this prefix " +
                     " are not considered. If the list is empty, all vanity paths are used.")
     private static final String PROP_DENIED_VANITY_PATH_PREFIX = "resource.resolver.vanitypath.blacklist";
-
+    
+    private static final boolean DEFAULT_VANITY_PATH_PRECEDENCE = false;
+    @Property(boolValue = DEFAULT_VANITY_PATH_PRECEDENCE ,
+              label = "Vanity Path Precedence",
+              description ="This flag controls whether vanity paths" +
+                      " will have precedence over existing /etc/map mapping")
+    private static final String PROP_VANITY_PATH_PRECEDENCE = "resource.resolver.vanity.precedence";
+ 
     /** Tracker for the resource decorators. */
     private final ResourceDecoratorTracker resourceDecoratorTracker = new ResourceDecoratorTracker();
 
@@ -252,6 +259,10 @@ public class ResourceResolverFactoryActi
 
     /** alias resource resolution optimization enabled? */
     private boolean enableOptimizeAliasResolution = DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION;
+    
+    /** vanity paths will have precedence over existing /etc/map mapping? */
+    private boolean vanityPathPrecedence = DEFAULT_VANITY_PATH_PRECEDENCE;
+
 
     /** Vanity path whitelist */
     private String[] vanityPathWhiteList;
@@ -332,6 +343,10 @@ public class ResourceResolverFactoryActi
     public String[] getVanityPathBlackList() {
         return this.vanityPathBlackList;
     }
+    
+    public boolean hasVanityPathPrecedence() {
+        return this.vanityPathPrecedence;
+    }
 
     // ---------- SCR Integration ---------------------------------------------
 
@@ -435,6 +450,8 @@ public class ResourceResolverFactoryActi
 
         this.enableOptimizeAliasResolution = PropertiesUtil.toBoolean(properties.get(PROP_ENABLE_OPTIMIZE_ALIAS_RESOLUTION),
DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION);
 
+        this.vanityPathPrecedence = PropertiesUtil.toBoolean(properties.get(PROP_VANITY_PATH_PRECEDENCE),
DEFAULT_VANITY_PATH_PRECEDENCE);
+        
         final BundleContext bc = componentContext.getBundleContext();
 
         // check for required property

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java?rev=1590592&r1=1590591&r2=1590592&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
Mon Apr 28 10:37:36 2014
@@ -41,6 +41,8 @@ public interface MapConfigurationProvide
     boolean isVanityPathEnabled();
 
     boolean isOptimizeAliasResolutionEnabled();
+    
+    boolean hasVanityPathPrecedence();
 
     public class VanityPathConfig implements Comparable<VanityPathConfig> {
         public final boolean isExclude;

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java?rev=1590592&r1=1590591&r2=1590592&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
Mon Apr 28 10:37:36 2014
@@ -112,6 +112,8 @@ public class MapEntries implements Event
     private final boolean enabledVanityPaths;
 
     private final boolean enableOptimizeAliasResolution;
+    
+    private final boolean vanityPathPrecedence;
 
     private final List<VanityPathConfig> vanityPathConfig;
 
@@ -130,6 +132,7 @@ public class MapEntries implements Event
         this.enabledVanityPaths = true;
         this.enableOptimizeAliasResolution = true;
         this.vanityPathConfig = null;
+        this.vanityPathPrecedence = false;
     }
 
     @SuppressWarnings("unchecked")
@@ -141,6 +144,7 @@ public class MapEntries implements Event
         this.enabledVanityPaths = factory.isVanityPathEnabled();
         this.vanityPathConfig = factory.getVanityPathConfig();
         this.enableOptimizeAliasResolution = factory.isOptimizeAliasResolutionEnabled();
+        this.vanityPathPrecedence = factory.hasVanityPathPrecedence();
         this.eventAdmin = eventAdmin;
 
         this.resolveMapsMap = Collections.singletonMap(GLOBAL_LIST_KEY, (List<MapEntry>)Collections.EMPTY_LIST);
@@ -342,7 +346,7 @@ public class MapEntries implements Event
             key = requestPath.substring(secondIndex);
         }
 
-        return new MapEntryIterator(key, resolveMapsMap);
+        return new MapEntryIterator(key, resolveMapsMap, vanityPathPrecedence);
     }
 
     public Collection<MapEntry> getMapMaps() {
@@ -851,11 +855,14 @@ public class MapEntries implements Event
 
         private Iterator<MapEntry> specialIterator;
         private MapEntry nextSpecial;
+        
+        private boolean vanityPathPrecedence;
 
-        public MapEntryIterator(final String startKey, final Map<String, List<MapEntry>>
resolveMapsMap) {
+        public MapEntryIterator(final String startKey, final Map<String, List<MapEntry>>
resolveMapsMap, final boolean vanityPathPrecedence) {
             this.key = startKey;
             this.resolveMapsMap = resolveMapsMap;
             this.globalListIterator = this.resolveMapsMap.get(GLOBAL_LIST_KEY).iterator();
+            this.vanityPathPrecedence = vanityPathPrecedence;
             this.seek();
         }
 
@@ -923,12 +930,18 @@ public class MapEntries implements Event
             if (this.nextSpecial == null) {
                 this.next = this.nextGlobal;
                 this.nextGlobal = null;
-            } else if (this.nextGlobal == null) {
-                this.next = this.nextSpecial;
-                this.nextSpecial = null;
-            } else if (this.nextGlobal.getPattern().length() >= this.nextSpecial.getPattern().length())
{
-                this.next = this.nextGlobal;
-                this.nextGlobal = null;
+            } else if (!this.vanityPathPrecedence){
+                if (this.nextGlobal == null) {
+                    this.next = this.nextSpecial;
+                    this.nextSpecial = null;
+                } else if (this.nextGlobal.getPattern().length() >= this.nextSpecial.getPattern().length())
{
+                    this.next = this.nextGlobal;
+                    this.nextGlobal = null;
+
+                }else {
+                    this.next = this.nextSpecial;
+                    this.nextSpecial = null;
+                }                
             } else {
                 this.next = this.nextSpecial;
                 this.nextSpecial = null;



Mime
View raw message