Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
<version>2.21.0</version>
<version>2.23.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jetbrains.annotations.NotNull;

import org.apache.commons.collections4.BidiMap;
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.mapping.PathToUriMappingService;
import org.apache.sling.api.resource.path.Path;
import org.apache.sling.resourceresolver.impl.console.ResourceResolverWebConsolePlugin;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
Expand All @@ -48,6 +47,7 @@
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
import org.apache.sling.spi.resource.provider.ResourceProvider;
import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
Expand Down Expand Up @@ -405,6 +405,11 @@ public ResourceAccessSecurityTracker getResourceAccessSecurityTracker () {
return this.activator.getResourceAccessSecurityTracker();
}

/** gets PathToUriMappingServiceImpl */
public PathToUriMappingService getPathToUriMappingService() {
return this.activator.getPathToUriMappingService();
}

@NotNull
@Override
public ResourceResolver getServiceResourceResolver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import org.apache.commons.collections4.bidimap.TreeBidiMap;
import org.apache.sling.api.resource.ResourceDecorator;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.resource.path.Path;
import org.apache.sling.api.resource.runtime.RuntimeService;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
import org.apache.sling.resourceresolver.impl.mapping.Mapping;
import org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProvider;
import org.apache.sling.resourceresolver.impl.observation.ResourceChangeListenerWhiteboard;
Expand Down Expand Up @@ -119,6 +121,9 @@ private static final class FactoryRegistration {
@Reference
ResourceAccessSecurityTracker resourceAccessSecurityTracker;

@Reference
PathToUriMappingService pathToUriMappingService;

volatile ResourceProviderTracker resourceProviderTracker;

volatile ResourceChangeListenerWhiteboard changeListenerWhiteboard;
Expand Down Expand Up @@ -153,6 +158,10 @@ public ResourceAccessSecurityTracker getResourceAccessSecurityTracker() {
return this.resourceAccessSecurityTracker;
}

public PathToUriMappingService getPathToUriMappingService() {
return this.pathToUriMappingService;
}

public EventAdmin getEventAdmin() {
return this.eventAdmin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
import java.util.Set;
import java.util.StringTokenizer;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import javax.jcr.Session;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.adapter.annotations.Adaptable;
import org.apache.sling.adapter.annotations.Adapter;
import org.apache.sling.api.SlingException;
Expand All @@ -48,6 +47,7 @@
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ResourceWrapper;
import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.resource.mapping.ResourceMapper;
import org.apache.sling.resourceresolver.impl.helper.RedirectResource;
import org.apache.sling.resourceresolver.impl.helper.ResourceIteratorDecorator;
Expand All @@ -62,6 +62,7 @@
import org.apache.sling.resourceresolver.impl.params.ParsedParameters;
import org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider;
import org.apache.sling.spi.resource.provider.ResourceProvider;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -625,7 +626,7 @@ public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {

if ( type == ResourceMapper.class )
return (AdapterType) new ResourceMapperImpl(this, factory.getResourceDecoratorTracker(), factory.getMapEntries(),
factory.isOptimizeAliasResolutionEnabled(), factory.getNamespaceMangler());
factory.isOptimizeAliasResolutionEnabled(), factory.getNamespaceMangler(), factory.getPathToUriMappingService());

final AdapterType result = this.control.adaptTo(this.context, type);
if ( result != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.resource.mapping.ResourceMapper;
import org.apache.sling.api.uri.SlingUri;
import org.apache.sling.resourceresolver.impl.JcrNamespaceMangler;
import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
import org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker;
Expand All @@ -53,15 +55,17 @@ public class ResourceMapperImpl implements ResourceMapper {
private final MapEntriesHandler mapEntries;
private final boolean optimizedAliasResolutionEnabled;
private final Object namespaceMangler;

private final PathToUriMappingService pathToUriMappingService;

public ResourceMapperImpl(ResourceResolverImpl resolver, ResourceDecoratorTracker resourceDecorator,
MapEntriesHandler mapEntries, boolean optimizedAliasResolutionEnabled, Object namespaceMangler) {
MapEntriesHandler mapEntries, boolean optimizedAliasResolutionEnabled, Object namespaceMangler,
PathToUriMappingService pathToUriMappingService) {
this.resolver = resolver;
this.resourceDecorator = resourceDecorator;
this.mapEntries = mapEntries;
this.optimizedAliasResolutionEnabled = optimizedAliasResolutionEnabled;
this.namespaceMangler = namespaceMangler;
this.pathToUriMappingService = pathToUriMappingService;
}

@Override
Expand Down Expand Up @@ -166,6 +170,13 @@ public Collection<String> getAllMappings(String resourcePath, HttpServletRequest
// vanity paths are prepended to make sure they get returned last
mappings.addAll(0, vanityPaths);


// Apply mappings from Resource Mappers
PathToUriMappingService.Result mappingResult = pathToUriMappingService.map(request, mappings.get(mappings.size() - 1));
for (Map.Entry<String, SlingUri> mappingFromChain : mappingResult.getIntermediateMappings().entrySet()) {
mappings.add(mappingFromChain.getValue().toString());
}

// 7. apply context path if needed
mappings.replaceAll(new ApplyContextPath(request));

Expand All @@ -174,10 +185,10 @@ public Collection<String> getAllMappings(String resourcePath, HttpServletRequest
mappings.replaceAll(path -> path.concat(fragmentQuery));
}

mappings.forEach( path ->
logger.debug("map: Returning URL {} as mapping for path {}", path, resourcePath)
);
mappings.forEach( path -> {
logger.debug("map: Returning URL {} as mapping for path {}", path, resourcePath);
});

Collections.reverse(mappings);

return new LinkedHashSet<>(mappings);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.sling.resourceresolver.impl.urimapping;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.uri.SlingUri;
import org.apache.sling.spi.urimapping.MappingChainContext;

class MappingChainContextInternal implements MappingChainContext {

private final ResourceResolver resourceResolver;
private final Map<String, Object> attributes = new HashMap<>();
private final Map<String, SlingUri> intermediateMappings = new LinkedHashMap<>();
private boolean skipRemainingChain = false;


MappingChainContextInternal(ResourceResolver resourceResolver) {
this.resourceResolver = resourceResolver;
}

@Override
public void skipRemainingChain() {
skipRemainingChain = true;
}

@Override
public Map<String, Object> getAttributes() {
return attributes;
}

@Override
public Map<String, SlingUri> getIntermediateMappings() {
return Collections.unmodifiableMap(intermediateMappings);
}

@Override
public ResourceResolver getResourceResolver() {
return resourceResolver;
}

boolean isMarkedAsSkipRemainingChain() {
return skipRemainingChain;
}

void addIntermediateMapping(String name, SlingUri resourceUri) {
intermediateMappings.put(name, resourceUri);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.sling.resourceresolver.impl.urimapping;

import java.util.Map;

import org.apache.sling.api.resource.mapping.PathToUriMappingService;
import org.apache.sling.api.uri.SlingUri;

class MappingChainResult implements PathToUriMappingService.Result {

private final SlingUri slingUri;
private final Map<String, SlingUri> intermediateMappings;

public MappingChainResult(SlingUri slingUri, Map<String, SlingUri> intermediateMappings) {
this.slingUri = slingUri;
this.intermediateMappings = intermediateMappings;
}

public SlingUri getUri() {
return slingUri;
}

public Map<String, SlingUri> getIntermediateMappings() {
return intermediateMappings;
}


}
Loading