private String buildResourcePath(String path, String name) { return ResourceUtil.normalize(path + "/" + name); }
protected String makeAbsolutePath(final String relativePath) { String absolutePath = relativePath; // ensure the path is absolute and normalized if (!StringUtils.startsWith(absolutePath, "/")) { absolutePath = this.path + "/" + absolutePath; //NOPMD } return ResourceUtil.normalize(absolutePath); }
/** * Returns the <code>paramName</code> as an absolute (unnormalized) property * path by prepending the response path (<code>response.getPath</code>) to * the parameter name if not already absolute. */ private String toPropertyPath(String paramName, PostResponse response) { if (!paramName.startsWith("/")) { paramName = ResourceUtil.normalize(response.getPath() + '/' + paramName); } return paramName; }
/** * Utility method returns the name of the given <code>path</code>, which is * normalized by {@link #normalize(String)} before resolving the name. * * @param path The path whose name (the last path element) is to be * returned. * @return The empty string if <code>path</code> is the root path ( * <code>/</code>) or if <code>path</code> is a single name * containing no slash (<code>/</code>) characters. * @throws IllegalArgumentException If the path cannot be normalized by the * {@link #normalize(String)} method. * @throws NullPointerException If <code>path</code> is <code>null</code>. */ public static @NotNull String getName(@NotNull String path) { if ("/".equals(path)) { return ""; } // normalize path (remove . and ..) path = normalize(path); if ("/".equals(path)) { return ""; } // find the last slash return path.substring(path.lastIndexOf('/') + 1); }
/** * Sets the path of the repository item from which the content for this * property is to be copied or moved. The path may be relative in which case * it will be resolved relative to the absolute path of this property. * * @param sourcePath The path of the repository item to get the content from * @param isMove <code>true</code> if the source content is to be moved, * otherwise the source content is copied from the repository * item. */ public void setRepositorySource(String sourcePath, boolean isMove) { // make source path absolute if (!sourcePath.startsWith("/")) { sourcePath = getParentPath() + "/" + sourcePath; sourcePath = ResourceUtil.normalize(sourcePath); } this.repositoryResourcePath = sourcePath; this.isRepositoryResourceMove = isMove; }
/** * Add a new resource. * If the path is relative, this resource is added as a child to the previous resource. * If the path is relative and starts with a dot, this resource is added as a peer to the previous resource. * @param path Resource path * @return this */ public @NotNull MockHelper resource(@NotNull final String path) { final String fullPath; if ( path.startsWith("/") ) { fullPath = path; } else if ( path.startsWith(".") ) { final Description d = this.stack.peek(); fullPath = ResourceUtil.normalize(d.path + "/../" + path.substring(1)); } else { final Description d = this.stack.peek(); fullPath = d.path + "/" + path; } final Description d = new Description(); d.path = fullPath; this.stack.push(d); return this; }
public RequestProperty(String path) { assert path.startsWith("/"); this.path = ResourceUtil.normalize(path); this.parentPath = ResourceUtil.getParent(path); this.name = ResourceUtil.getName(path); }
private String normalizePath(SlingHttpServletRequest request, String path) { if (!path.startsWith("/")) { path = request.getResource().getPath() + "/" + path; } return ResourceUtil.normalize(path); } }
private String normalizePath(SlingHttpServletRequest request, final String path) { String actualPath = path; if (!path.startsWith("/")) { actualPath = request.getResource().getPath() + "/" + path; } return ResourceUtil.normalize(actualPath); }
private String checkPath(final ContextResource contextResource, final String checkRef, final Collection<String> bucketNames) { // combine full path if relativeRef is present String ref = ResourceUtil.normalize(checkRef); for (String bucketName : bucketNames) { String notAllowedPostfix = "/" + bucketName; if (ref != null && ref.endsWith(notAllowedPostfix)) { log.warn("Ignoring reference to {} from {} - Probably misconfigured as it ends with '{}'", contextResource.getConfigRef(), contextResource.getResource().getPath(), notAllowedPostfix); ref = null; } } return ref; }
private String buildPath(String path, Map<String, Object> options, Resource currentResource) { String prependPath = getOption(OPTION_PREPEND_PATH, options, StringUtils.EMPTY); if (prependPath == null) { prependPath = StringUtils.EMPTY; } if (StringUtils.isNotEmpty(prependPath)) { if (!prependPath.startsWith("/")) { prependPath = "/" + prependPath; } if (!prependPath.endsWith("/")) { prependPath += "/"; } } path = getOption(OPTION_PATH, options, StringUtils.isNotEmpty(path) ? path : StringUtils.EMPTY); String appendPath = getOption(OPTION_APPEND_PATH, options, StringUtils.EMPTY); if (appendPath == null) { appendPath = StringUtils.EMPTY; } if (StringUtils.isNotEmpty(appendPath)) { if (!appendPath.startsWith("/")) { appendPath = "/" + appendPath; } } String finalPath = prependPath + path + appendPath; if (!finalPath.startsWith("/")) { finalPath = currentResource.getPath() + "/" + finalPath; } return ResourceUtil.normalize(finalPath); }
@Test public void testMapResourceAlias() throws Exception { // define an alias for the rootPath String alias = "testAlias"; rootNode.setProperty("sling:alias", alias); saveMappings(session); try { String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias); String mapped = resResolver.map(rootNode.getPath()); assertEquals(path, mapped); Node child = rootNode.addNode("child"); session.save(); path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias+"/child"); mapped = resResolver.map(child.getPath()); assertEquals(path, mapped); } finally { rootNode.getProperty("sling:alias").remove(); if ( rootNode.hasNode("child") ) { rootNode.getNode("child").remove(); } session.save(); } }
@Test public void testMapResourceAliasJcrContent() throws Exception { // define an alias for the rootPath in the jcr:content child node String alias = "testAlias"; Node content = rootNode.addNode("jcr:content", "nt:unstructured"); content.setProperty("sling:alias", alias); saveMappings(session); try { String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias); String mapped = resResolver.map(rootNode.getPath()); assertEquals(path, mapped); path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias+"/_jcr_content"); mapped = resResolver.map(content.getPath()); assertEquals(path, mapped); Node child = content.addNode("child"); session.save(); path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/" + alias+"/_jcr_content/child"); mapped = resResolver.map(child.getPath()); assertEquals(path, mapped); } finally { content.remove(); session.save(); } }
/** * Create an absolute URI suitable for the "Location" response header * including any selectors, extension, suffix and query from the current * request. */ static String toRedirectPath(String targetPath, SlingHttpServletRequest request) { // make sure the target path is absolute final String rawAbsPath; if (targetPath.startsWith("/")) { rawAbsPath = targetPath; } else { rawAbsPath = request.getResource().getPath() + "/" + targetPath; } final StringBuilder target = new StringBuilder(); // and ensure the path is normalized, us unnormalized if not possible final String absPath = ResourceUtil.normalize(rawAbsPath); if (absPath == null) { target.append(rawAbsPath); } else { target.append(absPath); } appendSelectorsExtensionSuffixQuery(request, target); // return the mapped full path return request.getResourceResolver().map(request, target.toString()); }
String normalizedPath = ResourceUtil.normalize(path); if (normalizedPath == null) { 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; }
path = ResourceUtil.normalize(getPath() + "/" + relPath);
private Resource getResourceInternal(Resource parent, String path) { Resource result = null; if ( path != null ) { // if the path is absolute, normalize . and .. segments and get res if (path.startsWith("/")) { final ParsedParameters parsedPath = new ParsedParameters(path); path = ResourceUtil.normalize(parsedPath.getRawPath()); result = (path != null) ? getAbsoluteResourceInternal(parent, path, parsedPath.getParameters(), false) : null; if (result != null) { result = this.factory.getResourceDecoratorTracker().decorate(result); } } else { // otherwise we have to apply the search path // (don't use this.getSearchPath() to save a few cycle for not cloning) for (final String prefix : factory.getSearchPath()) { result = getResource(prefix + path); if (result != null) { break; } } } } return result; }
(currentPageLanguageRoot)) { Page languageCopySearchRoot = pageManager.getPage(ResourceUtil.normalize(currentPageLanguageRoot.getPath() + "/" + getRelativePath(searchRootLanguageRoot, rootPage))); if (languageCopySearchRoot != null) {