*/
public SlingScript findScript(final ResourceResolver resourceResolver, final String name)
throws SlingException {
// is the path absolute
SlingScript script = null;
if (name.startsWith("/")) {
final String path = ResourceUtil.normalize(name);
if ( this.isPathAllowed(path) ) {
final Resource resource = resourceResolver.getResource(path);
if ( resource != null ) {
script = resource.adaptTo(SlingScript.class);
}
}
} else {
// relative script resolution against search path
final String[] path = resourceResolver.getSearchPath();
for (int i = 0; script == null && i < path.length; i++) {
final String scriptPath = ResourceUtil.normalize(path[i] + name);
if ( this.isPathAllowed(scriptPath) ) {
final Resource resource = resourceResolver.getResource(scriptPath);
if (resource != null) {
script = resource.adaptTo(SlingScript.class);
}
}
}
}
// some logging
if (script != null) {
LOGGER.debug("findScript: Using script {} for {}", script.getScriptResource().getPath(), name);
} else {
LOGGER.info("findScript: No script {} found in path", name);
}
// and finally return the script (null or not)