public MockPropertyResource(final String path, final ValueMap props, final ResourceResolver resolver) { this.path = path; this.props = props; this.key = ResourceUtil.getName(path); this.resolver = resolver; }
/** * @see org.apache.sling.api.resource.AbstractResource#getName() */ @Override public String getName() { return ResourceUtil.getName(this.path); }
@Override public String getName() { return ResourceUtil.getName(this.path); }
/** * Returns the name of this resource. * <p> * This method is implemented as a pure string operation by calling the * {@link ResourceUtil#getName(String)} method with the path of this * resource. */ public String getName() { return ResourceUtil.getName(getPath()); }
private long getRequestLastModifiedSuffix(@Nullable String suffix) { long requestLastModified = 0; if (StringUtils.isNotEmpty(suffix) && suffix.contains(".")) { // check if the 13 digits UTC milliseconds timestamp is present in the suffix Pattern p = Pattern.compile("\\(|\\)|\\d{13}"); Matcher m = p.matcher(suffix); if (!m.find()) { return requestLastModified; } try { requestLastModified = Long.parseLong(ResourceUtil.getName(m.group())); } catch (NumberFormatException e) { // do nothing } } return requestLastModified; }
private String relativePath(final String basePath, final String path) { final String suffix = StringUtils.removeStart(path, basePath); final String normalizedPath = StringUtils.replaceChars(suffix, '\\', '/'); // If path starts with a '.', it is likely the descriptor file that // is a sibling of the providerFilePath, i.e. most likely a .json file. // We need to fix that up, as it is not a child of the providerFilePath. if (normalizedPath == null || normalizedPath.startsWith(".") && normalizedPath.length() > 2) { return "../" + ResourceUtil.getName(path); } return normalizedPath; }
/** * Utility method returns the name of the resource. * * @param rsrc The resource to get the name from. * @return The name of the resource * @throws NullPointerException If <code>rsrc</code> is <code>null</code>. * @deprecated since 2.1.0, use {@link Resource#getName()} instead */ @Deprecated public static @NotNull String getName(@NotNull Resource rsrc) { /* * Same as AbstractResource.getName() implementation to prevent problems * if there are implementations of the pre-2.1.0 Resource interface in * the framework. */ return getName(rsrc.getPath()); }
public RequestProperty(String path) { assert path.startsWith("/"); this.path = ResourceUtil.normalize(path); this.parentPath = ResourceUtil.getParent(path); this.name = ResourceUtil.getName(path); }
@Override public void run() { if ( isRunning.get() ) { final String scheduleKey = ResourceHelper.filterName(ResourceUtil.getName(path)); if ( scheduleKey != null ) { synchronized ( scheduledJobs ) { final Holder h = scheduledJobs.remove(scheduleKey); if ( h != null && h.info != null ) { jobScheduler.unscheduleJob(h.info); } } } } } });
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); }
/** * Adds a resource in the JSON tree. * * @param resource The resource to add * @param level The level where this resource is located. * @throws JSONException */ private JSONObject collectResource(Resource resource, final JSONObject parent) throws JSONException { final JSONObject o = adapt(resource); parent.put(ResourceUtil.getName(resource), o); return o; }
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); } }
/** Dump a single node */ private static void createSingleResource(final Resource n, final JSONObject parent, final int currentRecursionLevel, final int maxRecursionLevels) throws JSONException { if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) { parent.put(ResourceUtil.getName(n), create(n, currentRecursionLevel + 1, maxRecursionLevels)); } }
@Override public boolean move(final @Nonnull ResolveContext<JcrProviderState> ctx, final String srcAbsPath, final String destAbsPath) throws PersistenceException { final String srcNodePath = srcAbsPath; final String dstNodePath = destAbsPath + '/' + ResourceUtil.getName(srcAbsPath); try { ctx.getProviderState().getSession().move(srcNodePath, dstNodePath); return true; } catch (final RepositoryException e) { throw new PersistenceException("Unable to move resource to " + destAbsPath, e, srcAbsPath, null); } }
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); }
/** * 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); }
/** * 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); }
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 getResource(final String path) { Resource resource = getResourceInternal(path); // if not resource found check if this is a reference to a property if (resource == null && path != null) { String parentPath = ResourceUtil.getParent(path); if (parentPath != null) { String name = ResourceUtil.getName(path); Resource parentResource = getResourceInternal(parentPath); if (parentResource!=null) { ValueMap props = ResourceUtil.getValueMap(parentResource); if (props.containsKey(name)) { return new MockPropertyResource(path, props, this); } } } } return resource; }