Author: cziegeler
Date: Sat Oct 15 16:04:25 2016
New Revision: 1765089
URL: http://svn.apache.org/viewvc?rev=1765089&view=rev
Log:
SLING-6159 : Implementation should not rely on sling:VanityPath mixin
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
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.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=1765089&r1=1765088&r2=1765089&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
Sat Oct 15 16:04:25 2016
@@ -34,6 +34,7 @@ import org.apache.commons.collections.Bi
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.api.resource.path.Path;
import
org.apache.sling.resourceresolver.impl.console.ResourceResolverWebConsolePlugin;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
import org.apache.sling.resourceresolver.impl.helper.ResourceResolverControl;
@@ -380,7 +381,7 @@ public class CommonResourceResolverFacto
}
@Override
- public String[] getObservationPaths() {
+ public Path[] getObservationPaths() {
return this.activator.getObservationPaths();
}
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=1765089&r1=1765088&r2=1765089&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
Sat Oct 15 16:04:25 2016
@@ -40,6 +40,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.References;
import org.apache.sling.api.resource.ResourceDecorator;
import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.api.resource.path.Path;
import org.apache.sling.api.resource.runtime.RuntimeService;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
@@ -347,7 +348,7 @@ public class ResourceResolverFactoryActi
private volatile String[] vanityPathBlackList;
/** Observation paths */
- private volatile String[] observationPaths;
+ private volatile Path[] observationPaths;
private final FactoryPreconditions preconds = new FactoryPreconditions();
@@ -441,7 +442,7 @@ public class ResourceResolverFactoryActi
return logResourceResolverClosing;
}
- public String[] getObservationPaths() {
+ public Path[] getObservationPaths() {
return this.observationPaths;
}
@@ -506,7 +507,11 @@ public class ResourceResolverFactoryActi
mapRoot = PropertiesUtil.toString(properties.get(PROP_MAP_LOCATION),
MapEntries.DEFAULT_MAP_ROOT);
mapRootPrefix = mapRoot + '/';
- observationPaths =
PropertiesUtil.toStringArray(properties.get(PROP_OBSERVATION_PATHS), new
String[] {"/"});
+ final String[] paths =
PropertiesUtil.toStringArray(properties.get(PROP_OBSERVATION_PATHS), new
String[] {"/"});
+ this.observationPaths = new Path[paths.length];
+ for(int i=0;i<paths.length;i++) {
+ this.observationPaths[i] = new Path(paths[i]);
+ }
defaultVanityPathRedirectStatus =
PropertiesUtil.toInteger(properties.get(PROP_DEFAULT_VANITY_PATH_REDIRECT_STATUS),
MapEntries.DEFAULT_DEFAULT_VANITY_PATH_REDIRECT_STATUS);
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=1765089&r1=1765088&r2=1765089&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
Sat Oct 15 16:04:25 2016
@@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.api.resource.path.Path;
/**
* Internal interface representing the additional methods
@@ -34,7 +35,7 @@ public interface MapConfigurationProvide
boolean isMapConfiguration(String path);
- String[] getObservationPaths();
+ Path[] getObservationPaths();
Map<?, ?> getVirtualURLMap();
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=1765089&r1=1765088&r2=1765089&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
Sat Oct 15 16:04:25 2016
@@ -60,6 +60,7 @@ import org.apache.sling.api.resource.Val
import
org.apache.sling.api.resource.observation.ExternalResourceChangeListener;
import org.apache.sling.api.resource.observation.ResourceChange;
import org.apache.sling.api.resource.observation.ResourceChangeListener;
+import org.apache.sling.api.resource.path.Path;
import org.apache.sling.resourceresolver.impl.ResourceResolverFactoryImpl;
import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
import
org.apache.sling.resourceresolver.impl.mapping.MapConfigurationProvider.VanityPathConfig;
@@ -159,7 +160,11 @@ public class MapEntries implements
doInit();
final Dictionary<String, Object> props = new Hashtable<String,
Object>();
- props.put(ResourceChangeListener.PATHS, factory.getObservationPaths());
+ final String[] paths = new
String[factory.getObservationPaths().length];
+ for(int i=0 ; i < paths.length; i++) {
+ paths[i] = factory.getObservationPaths()[i].getPath();
+ }
+ props.put(ResourceChangeListener.PATHS, paths);
log.info("Registering for {}",
Arrays.toString(factory.getObservationPaths()));
props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Map Entries
Observation");
props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
@@ -795,9 +800,8 @@ public class MapEntries implements
Map<String, List<MapEntry>> entryMap = new HashMap<String,
List<MapEntry>>();
- // sling:VanityPath (uppercase V) is the mixin name
- // sling:vanityPath (lowercase) is the property name
- final String queryString = "SELECT sling:vanityPath, sling:redirect,
sling:redirectStatus FROM sling:VanityPath WHERE sling:vanityPath ="
+ // sling:vanityPath (lowercase) is the property name
+ final String queryString = "SELECT sling:vanityPath, sling:redirect,
sling:redirectStatus FROM nt:base WHERE sling:vanityPath ="
+
"'"+escapeIllegalXpathSearchChars(vanityPath).replaceAll("'", "''")+"' OR
sling:vanityPath ="+
"'"+escapeIllegalXpathSearchChars(vanityPath.substring(1)).replaceAll("'",
"''")+"' ORDER BY sling:vanityOrder DESC";
ResourceResolver queryResolver = null;
@@ -807,12 +811,21 @@ public class MapEntries implements
final Iterator<Resource> i =
queryResolver.findResources(queryString, "sql");
while (i.hasNext()) {
final Resource resource = i.next();
- if (this.factory.isMaxCachedVanityPathEntriesStartup() ||
vanityCounter.longValue() < this.factory.getMaxCachedVanityPathEntries()) {
- loadVanityPath(resource, resolveMapsMap, vanityTargets,
true, false);
- entryMap = resolveMapsMap;
- } else {
- final Map <String, List<String>> targetPaths = new HashMap
<String, List<String>>();
- loadVanityPath(resource, entryMap, targetPaths, true,
false);
+ boolean isValid = false;
+ for(final Path sPath : this.factory.getObservationPaths()) {
+ if ( sPath.matches(resource.getPath())) {
+ isValid = true;
+ break;
+ }
+ }
+ if ( isValid ) {
+ if (this.factory.isMaxCachedVanityPathEntriesStartup() ||
vanityCounter.longValue() < this.factory.getMaxCachedVanityPathEntries()) {
+ loadVanityPath(resource, resolveMapsMap,
vanityTargets, true, false);
+ entryMap = resolveMapsMap;
+ } else {
+ final Map <String, List<String>> targetPaths = new
HashMap <String, List<String>>();
+ loadVanityPath(resource, entryMap, targetPaths, true,
false);
+ }
}
}
} catch (LoginException e) {
@@ -1087,22 +1100,30 @@ public class MapEntries implements
* mixin
*/
private Map <String, List<String>> loadVanityPaths(boolean
createVanityBloomFilter) {
- // sling:VanityPath (uppercase V) is the mixin name
// sling:vanityPath (lowercase) is the property name
final Map <String, List<String>> targetPaths = new ConcurrentHashMap
<String, List<String>>();
- final String queryString = "SELECT sling:vanityPath, sling:redirect,
sling:redirectStatus FROM sling:VanityPath WHERE sling:vanityPath IS NOT NULL";
+ final String queryString = "SELECT sling:vanityPath, sling:redirect,
sling:redirectStatus FROM nt:base WHERE sling:vanityPath IS NOT NULL";
final Iterator<Resource> i = resolver.findResources(queryString,
"sql");
while (i.hasNext() && (createVanityBloomFilter ||
isAllVanityPathEntriesCached() || vanityCounter.longValue() <
this.factory.getMaxCachedVanityPathEntries())) {
final Resource resource = i.next();
- if (isAllVanityPathEntriesCached() || vanityCounter.longValue() <
this.factory.getMaxCachedVanityPathEntries()) {
- // fill up the cache and the bloom filter
- loadVanityPath(resource, resolveMapsMap, targetPaths, true,
- createVanityBloomFilter);
- } else {
- // fill up the bloom filter
- loadVanityPath(resource, resolveMapsMap, targetPaths, false,
- createVanityBloomFilter);
+ boolean isValid = false;
+ for(final Path sPath : this.factory.getObservationPaths()) {
+ if ( sPath.matches(resource.getPath())) {
+ isValid = true;
+ break;
+ }
+ }
+ if ( isValid ) {
+ if (isAllVanityPathEntriesCached() ||
vanityCounter.longValue() < this.factory.getMaxCachedVanityPathEntries()) {
+ // fill up the cache and the bloom filter
+ loadVanityPath(resource, resolveMapsMap, targetPaths, true,
+ createVanityBloomFilter);
+ } else {
+ // fill up the bloom filter
+ loadVanityPath(resource, resolveMapsMap, targetPaths,
false,
+ createVanityBloomFilter);
+ }
}
}
Modified:
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java?rev=1765089&r1=1765088&r2=1765089&view=diff
==============================================================================
---
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
(original)
+++
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
Sat Oct 15 16:04:25 2016
@@ -51,6 +51,7 @@ import org.apache.sling.api.resource.Res
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.resource.path.Path;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
import
org.apache.sling.resourceresolver.impl.mapping.MapConfigurationProvider.VanityPathConfig;
@@ -114,7 +115,7 @@ public class MapEntriesTest {
when(resourceResolverFactory.isVanityPathEnabled()).thenReturn(true);
when(resourceResolverFactory.getVanityPathConfig()).thenReturn(configs);
when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(true);
- when(resourceResolverFactory.getObservationPaths()).thenReturn(new
String[] {"/"});
+ when(resourceResolverFactory.getObservationPaths()).thenReturn(new
Path[] {new Path("/")});
when(resourceResolverFactory.getMapRoot()).thenReturn(MapEntries.DEFAULT_MAP_ROOT);
when(resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(-1L);
when(resourceResolverFactory.isMaxCachedVanityPathEntriesStartup()).thenReturn(true);