protected void getWeightedResources()

in src/main/java/org/apache/sling/servlets/resolver/internal/helper/NamedScriptResourceCollector.java [91:132]


    protected void getWeightedResources(final Set<WeightedResource> resources,
                                        final Resource location) {
        final ResourceResolver resolver = location.getResourceResolver();
        // if extension is set, we first check for an exact script match
        if ( this.extension != null ) {
            final String path = ResourceUtil.normalize(location.getPath() + '/' + this.scriptName);
            if ( SlingServletResolver.isPathAllowed(path, this.executionPaths) ) {
                final Resource current = getResourceOrNull(resolver, path, useResourceCaching);
                if ( current != null ) {
                    this.addWeightedResource(resources, current, 0, WeightedResource.WEIGHT_EXTENSION);
                }
            }
        }
        // if the script name denotes a path we have to get the denoted resource
        // first
        final Resource current;
        final String name;
        final int pos = this.scriptName.lastIndexOf('/');
        if ( pos == -1 ) {
            current = location;
            name = this.scriptName;
        } else {
            current = getResource(resolver, location.getPath() + '/' + this.scriptName.substring(0, pos), useResourceCaching);
            name = this.scriptName.substring(pos + 1);
        }
        final List<Resource> children = getChildrenList(current, useResourceCaching);
        for (Resource child: children) {

            if ( SlingServletResolver.isPathAllowed(child.getPath(), this.executionPaths) ) {
                final String currentScriptName = child.getName();
                final int lastDot = currentScriptName.lastIndexOf('.');
                if (lastDot < 0) {
                    // no extension in the name, this is not a script
                    continue;
                }

                if ( currentScriptName.substring(0, lastDot).equals(name) ) {
                    this.addWeightedResource(resources, child, 0, WeightedResource.WEIGHT_PREFIX);
                }
            }
        }
    }