private String getActualContentPath(final String path){ final String checkPath; if ( path.endsWith(JCR_CONTENT_SUFFIX) ) { checkPath = ResourceUtil.getParent(path); } else { checkPath = path; } return checkPath; }
@Override public Resource getParent() { if (path == null) { return null; } return SyntheticNavigatableResource.get(ResourceUtil.getParent(path), resolver); }
public RequestProperty(String path) { assert path.startsWith("/"); this.path = ResourceUtil.normalize(path); this.parentPath = ResourceUtil.getParent(path); this.name = ResourceUtil.getName(path); }
@Override public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException { return getNode(ResourceUtil.getParent(getPath())); }
private void create(@NotNull final String path, @NotNull final Map<String, Object> properties) throws PersistenceException { final String parentPath = ResourceUtil.getParent(path); final String name = ResourceUtil.getName(path); final Resource parent = this.resolver.getResource(parentPath); this.resolver.create(parent, name, properties); }
public Resource getParent(Resource child) { final String parentPath = ResourceUtil.getParent(child.getPath()); if (parentPath == null) { return null; } return this.getResource(parentPath); }
@Override public Node getParent() throws RepositoryException { return (Node)getSession().getItem(ResourceUtil.getParent(this.path)); }
private static Resource getContentResourceOrParentFromPath(SlingHttpServletRequest slingRequest, String contentPath) { if (StringUtils.isNotEmpty(contentPath)) { Resource contentResource = slingRequest.getResourceResolver().getResource(contentPath); if (contentResource != null) { return contentResource; } else { return getContentResourceOrParentFromPath(slingRequest, ResourceUtil.getParent(contentPath)); } } return null; }
private ContentFile getFile(String path, String subPath) { if (!StringUtils.startsWith(path, providerRootPrefix)) { return null; } String relPath = Escape.resourceToFileName(path.substring(providerRootPrefix.length())); for (String filenameSuffix : contentFileExtensions.getSuffixes()) { File file = new File(providerFile, relPath + filenameSuffix); if (fileStatCache.exists(file)) { return new ContentFile(file, path, subPath, contentFileCache); } } // try to find in parent path which contains content fragment String parentPath = ResourceUtil.getParent(path); String nextSubPath = path.substring(parentPath.length() + 1) + (subPath != null ? "/" + subPath : ""); return getFile(parentPath, nextSubPath); }
private Resource createResourceHierarchy(String path) { String parentPath = ResourceUtil.getParent(path); if (parentPath == null) { return null; } Resource parentResource = resourceResolver.getResource(parentPath); if (parentResource == null) { parentResource = createResourceHierarchy(parentPath); } Map<String, Object> props = new HashMap<>(); props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED); try { return resourceResolver.create(parentResource, ResourceUtil.getName(path), props); } catch (PersistenceException ex) { throw new RuntimeException(ex); } }
@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(); } }
@Override public Item getAncestor(final int depth) throws RepositoryException { if (depth < 0 || depth > getDepth()) { throw new ItemNotFoundException(); } return this.session.getItem(ResourceUtil.getParent(this.path, depth)); }
private static Resource retrieveParent(Resource resource) { String parentPath = ResourceUtil.getParent(resource.getPath()); if (parentPath == null) { return null; } return resource.getResourceResolver().getResource(parentPath); } }
private static Resource createResource(Resource root, String relPath) throws PersistenceException { ResourceResolver resourceResolver = root.getResourceResolver(); String path = root.getPath() + "/" + relPath; final String parentPath = ResourceUtil.getParent(path); final String name = ResourceUtil.getName(path); Resource parent = ResourceUtil.getOrCreateResource(resourceResolver, parentPath, RESOURCE_FOLDER, RESOURCE_FOLDER, false); Map<String, Object> props = Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) RESOURCE_FOLDER); return resourceResolver.create(parent, name, props); }
/** * * @return the parent resource (might be a {@link NonExistingResource} in case the parent does not exist either). */ public Resource getParent() { Resource parent = super.getParent(); if (parent == null) { return new NonExistingResource(getResourceResolver(), ResourceUtil.getParent(getPath())); } else { return parent; } }
/** * Import binary file as nt:resource binary node into repository. * Auto-creates parent hierarchies as nt:unstrucured nodes if missing. * @param inputStream Input stream for binary data * @param path Path to mount binary data to (parent nodes created automatically) * @param mimeType Mime type of binary data * @return Resource with binary data */ public Resource binaryResource(InputStream inputStream, String path, String mimeType) { String parentPath = ResourceUtil.getParent(path, 1); String name = ResourceUtil.getName(path); Resource parentResource = resourceResolver.getResource(parentPath); if (parentResource == null) { parentResource = createResourceHierarchy(parentPath); } return binaryResource(inputStream, parentResource, name, mimeType); }
@Nullable private String getRedirectLocation(SlingHttpServletRequest request, long lastModifiedEpoch) { RequestPathInfo requestPathInfo = request.getRequestPathInfo(); if (request.getResource().isResourceType(IMAGE_RESOURCE_TYPE)) { return Joiner.on('.').join(Text.escapePath(request.getContextPath() + requestPathInfo.getResourcePath()), requestPathInfo.getSelectorString(), requestPathInfo.getExtension() + "/" + lastModifiedEpoch, requestPathInfo.getExtension()); } long lastModifiedSuffix = getRequestLastModifiedSuffix(request.getPathInfo()); String resourcePath = lastModifiedSuffix > 0 ? ResourceUtil.getParent(request.getPathInfo()) : request.getPathInfo(); String extension = FilenameUtils.getExtension(resourcePath); if (StringUtils.isNotEmpty(resourcePath)) { if (StringUtils.isNotEmpty(extension)) { resourcePath = resourcePath.substring(0, resourcePath.length() - extension.length() - 1); } return request.getContextPath() + Text.escapePath(resourcePath) + "/" + lastModifiedEpoch + "." + requestPathInfo.getExtension(); } return null; }
/** * Import binary file as nt:file binary node into repository. * Auto-creates parent hierarchies as nt:unstrucured nodes if missing. * @param inputStream Input stream for binary data * @param path Path to mount binary data to (parent nodes created automatically) * @param mimeType Mime type of binary data * @return Resource with binary data */ public Resource binaryFile(InputStream inputStream, String path, String mimeType) { String parentPath = ResourceUtil.getParent(path, 1); String name = ResourceUtil.getName(path); Resource parentResource = resourceResolver.getResource(parentPath); if (parentResource == null) { parentResource = createResourceHierarchy(parentPath); } return binaryFile(inputStream, parentResource, name, mimeType); }
private Page createPage(ResourceResolver resolver, String path, String template) throws PersistenceException { // ensure parent path hierarchy exists - if not create it using pages with structure template String parentPath = ResourceUtil.getParent(path); if (parentPath == null) { throw new RuntimeException("Unable to get parent path from: " + path); } if (resolver.getResource(parentPath) == null) { createPage(resolver, parentPath, getStructurePageTemplate()); } // create path with given template String name = ResourceUtil.getName(path); PageManager pageManager = resolver.adaptTo(PageManager.class); try { return pageManager.create(parentPath, name, StringUtils.defaultString(template), name, true); } catch (WCMException ex) { throw new PersistenceException("Creating page at " + path + " failed.", ex); } }
@Override public Resource getParent(final Resource child) { Resource rsrc = null; final String parentPath = ResourceUtil.getParent(child.getPath()); if ( parentPath != null ) { // if the parent path is relative, resolve using search paths. if ( !parentPath.startsWith("/") ) { rsrc = context.getResourceResolver().getResource(parentPath); } else { rsrc = this.control.getParent(this.context, parentPath, child); if (rsrc != null ) { rsrc.getResourceMetadata().setResolutionPath(rsrc.getPath()); rsrc = this.factory.getResourceDecoratorTracker().decorate(rsrc); } } } return rsrc; }