@NotNull @Override public String[] getSearchPath() { return wrapped.getSearchPath(); }
/** * Makes the given resource type relative by stripping off any search path prefix. * In case the given resource type does not start with any of these prefixes it is returned unmodified. * @param resourceType The resource type to make relative. * @param resourceResolver Resource resolver * @return Relative resource type */ public static @NotNull String makeRelative(@NotNull String resourceType, @NotNull ResourceResolver resourceResolver) { String[] searchPaths = resourceResolver.getSearchPath(); for (String prefix : searchPaths) { if (StringUtils.startsWith(resourceType, prefix)) { return resourceType.substring(prefix.length()); } } return resourceType; }
private static boolean isInSearchPath(Resource resource) { String resourcePath = resource.getPath(); ResourceResolver resolver = resource.getResourceResolver(); for (String path : resolver.getSearchPath()) { if (resourcePath.startsWith(path)) { return true; } } return false; }
private static Resource locateInSearchPath(ResourceResolver resourceResolver, String path) { for (String searchPath : resourceResolver.getSearchPath()) { String fullPath = searchPath + path; Resource resource = resourceResolver.getResource(fullPath); if (resource != null && resource.getPath().startsWith(searchPath)) { //prevent path traversal attack return resource; } } return null; }
@Override public boolean allowImport(String importedClass) { for (String searchPath : scriptingResourceResolverProvider.getRequestScopedResourceResolver().getSearchPath()) { String subPackage = JavaEscapeUtils.makeJavaPackage(searchPath); if (importedClass.startsWith(subPackage)) { return false; } } return true; } }
/** * Creates an instance of this iterator starting with a location built from * the resource type of the <code>resource</code> and ending with the * given <code>baseResourceType</code>. * * @param resourceType the initial resource type. * @param resourceSuperType the initial resource super type. * @param baseResourceType The base resource type. * @param resolver The resource resolver */ public LocationIterator(String resourceType, String resourceSuperType, String baseResourceType, ResourceResolver resolver) { this.resolver = resolver; this.baseResourceType = baseResourceType; String[] tmpPath = resolver.getSearchPath(); if (tmpPath == null || tmpPath.length == 0) { tmpPath = new String[] { "/" }; } searchPath = tmpPath; this.firstResourceType = resourceType; this.firstResourceSuperType = resourceSuperType; // we start with the first resource type this.resourceType = firstResourceType; this.usedResourceTypes.add(this.resourceType); nextLocation = seek(); }
private String resolveProxiedClientLibrary(LibraryType libraryType, String proxiedPath, ResourceResolver resourceResolver, boolean refreshCacheIfNotFound) { final String relativePath = proxiedPath.substring(PROXY_PREFIX.length()); for (final String prefix : resourceResolver.getSearchPath()) { final String absolutePath = prefix + relativePath; // check whether the ClientLibrary exists before calling HtmlLibraryManager#getLibrary in order // to avoid WARN log messages that are written when an unknown HtmlLibrary is requested if (hasProxyClientLibrary(libraryType, absolutePath)) { return absolutePath; } } if (refreshCacheIfNotFound) { // maybe the library has appeared and our copy of the cache is stale log.info("Refreshing client libraries cache, because {} could not be found", proxiedPath); clientLibrariesCache = null; return resolveProxiedClientLibrary(libraryType, proxiedPath, resourceResolver, false); } return null; }
public ResourceType getResourceType() { for (String currentSearchPath : administrativeResourceResolver.getSearchPath()) { Resource potentialResourceType = administrativeResourceResolver.getResource(currentSearchPath + resource.getResourceType()); if (potentialResourceType != null) { return new DefaultResourceType(potentialResourceType); } } return null; } }
final String[] searchPath = resolver.getSearchPath();
private Resource searchForResourceSuperType(Resource currentResourceType) { if (StringUtils.isBlank(currentResourceType.getResourceSuperType())) { return null; } for (String searchPath : currentResourceType.getResourceResolver().getSearchPath()) { Resource potentialSuperType = currentResourceType.getResourceResolver().getResource(searchPath + "/" + currentResourceType.getResourceSuperType()); if (potentialSuperType != null) { return potentialSuperType; } } return null; }
/** * <p> * Resolves the resource accessed by a {@code request}. Since the {@code request} can use an anonymous {@code ResourceResolver}, the * passed {@code resolver} parameter should have read access rights to resources from the search path. * </p> * * @param resolver a {@link ResourceResolver} that has read access rights to resources from the search path * @param request the request * @return the resource identified by the {@code request} or {@code null} if no resource was found */ public static Resource getResourceForRequest(ResourceResolver resolver, SlingHttpServletRequest request) { String resourceType = request.getResource().getResourceType(); if (StringUtils.isNotEmpty(resourceType)) { if (resourceType.startsWith("/")) { return resolver.getResource(resourceType); } for (String searchPath : resolver.getSearchPath()) { String componentPath = ResourceUtil.normalize(searchPath + "/" + resourceType); if (componentPath != null) { Resource componentResource = resolver.getResource(componentPath); if (componentResource != null) { return componentResource; } } } } return null; }
private String getProxyPath(ClientLibrary lib) { String path = lib.getPath(); if (lib.allowProxy()) { for (String searchPath : request.getResourceResolver().getSearchPath()) { if (path.startsWith(searchPath)) { path = request.getContextPath() + "/etc.clientlibs/" + path.replaceFirst(searchPath, ""); } } } else { if (request.getResourceResolver().getResource(lib.getPath()) == null) { path = null; } } if (path != null) { path = path + "/resources"; } return path; }
private String buildCrxDeLinkToResourceType(HttpServletRequest request, String type) { return getResourceResolver().map(r -> { try { String path = resourceTypeToPath(type); Resource resource = null; Resource iconResource = null; for (String searchPath : r.getSearchPath()) { resource = r.getResource(searchPath + path); if (resource != null && !isNonExistingResource(resource) && !isSyntheticResource(resource)) { iconResource = resource.getChild("icon.png"); break; } } return resource != null ? "<a href=\"" + request.getContextPath() + "/crx/de/#" + resource.getPath() + "\" " + "class=\"crxdelink\">" + "<img class=\"componentIcon\" src=\"" + getLabel() + API_PATH + API_COMPONENTICON + (iconResource == null ? "" : resource.getPath()) + "\"/>" + type + "</a>" : "<span class=\"unresolved\">" + type + "</span>"; } finally { r.close(); } }).orElse("#"); }
for (String basepath : resrev.getSearchPath()) { script = resrev.resolve(basepath + absolutePath); if (script!=null&&!(script instanceof NonExistingResource)) {
for (String sp: rr.getSearchPath()) { if (parentPath.startsWith(sp)) { parentPath = parentPath.substring(sp.length());
final String[] path = resourceResolver.getSearchPath(); for (int i = 0; script == null && i < path.length; i++) { final String scriptPath = ResourceUtil.normalize(path[i] + name);
for (String sp : resolver.getSearchPath()) { if (parentPath.startsWith(sp)) { parentPath = parentPath.substring(sp.length());