private void populateMappingsFromMapEntries()

in src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java [265:311]


    private void populateMappingsFromMapEntries(List<String> mappings, List<String> mappedPathList,
            final RequestContext requestContext) {
        boolean mappedPathIsUrl = false;
        for ( String mappedPath : mappedPathList ) {
            for (final MapEntry mapEntry : mapEntries.getMapMaps()) {
                final String[] mappedPaths = mapEntry.replace(mappedPath);
                if (mappedPaths != null) {
    
                    logger.debug("map: Match for Entry {}", mapEntry);
    
                    mappedPathIsUrl = !mapEntry.isInternal();
    
                    if (mappedPathIsUrl && requestContext.hasUri() ) {
    
                        mappedPath = null;
    
                        for (final String candidate : mappedPaths) {
                            if (candidate.startsWith(requestContext.getUri())) {
                                mappedPath = candidate.substring(requestContext.getUri().length() - 1);
                                mappedPathIsUrl = false;
                                logger.debug("map: Found host specific mapping {} resolving to {}", candidate, mappedPath);
                                break;
                            } else if (candidate.startsWith(requestContext.getSchemeWithPrefix()) && mappedPath == null) {
                                mappedPath = candidate;
                            }
                        }
    
                        if (mappedPath == null) {
                            mappedPath = mappedPaths[0];
                        }
    
                    } else {
    
                        // we can only go with assumptions selecting the first entry
                        mappedPath = mappedPaths[0];
    
                    }
    
                    logger.debug("map: MapEntry {} matches, mapped path is {}", mapEntry, mappedPath);
                    
                    mappings.add(mappedPath);
    
                    break;
                }
            }
        }
    }