@Override public String getParentResourceType(String resourceType) { return wrapped.getParentResourceType(resourceType); }
@Override public String getParentResourceType(Resource resource) { return wrapped.getParentResourceType(resource); }
private boolean ifFormResourceSuperType(ResourceResolver scriptResourceResolver, Resource resource) { boolean result = false; Resource componentResource = scriptResourceResolver.getResource(resource.getResourceType()); String parentResourceType = scriptResourceResolver.getParentResourceType(componentResource); while (!result && parentResourceType != null) { if (parentResourceType.startsWith(FormConstants.RT_CORE_FORM_PREFIX)) { result = true; } else { parentResourceType = scriptResourceResolver.getParentResourceType(parentResourceType); } } return result; }
private boolean resolveNext() { String nextResourceType = this.resolver.getParentResourceType(this.currentResourceType); if (nextResourceType == null && isProvideSyntheticResourceRoot()) { nextResourceType = SYNTHETIC_RESOURCETYPE_ROOT; } this.nextResourceType = nextResourceType; return nextResourceType != null; }
/** * Returns the super type of the given resource type. This method converts * the resource type to a resource path by calling * {@link #resourceTypeToPath(String)} and uses the * <code>resourceResolver</code> to get the corresponding resource. If the * resource exists, the {@link Resource#getResourceSuperType()} method is * called. * * @param resourceResolver The <code>ResourceResolver</code> used to access * the resource whose path (relative or absolute) is given by the * <code>resourceType</code> parameter. * @param resourceType The resource type whose super type is to be returned. * This type is turned into a path by calling the * {@link #resourceTypeToPath(String)} method before trying to * get the resource through the <code>resourceResolver</code>. * @return the super type of the <code>resourceType</code> or * <code>null</code> if the resource type does not exists or returns * <code>null</code> for its super type. * @throws IllegalStateException if the resource resolver has already been * closed}. * @since 2.0.6 (Sling API Bundle 2.0.6) * @deprecated Use {@link ResourceResolver#getParentResourceType(String)} */ @Deprecated public static @Nullable String getResourceSuperType( final @NotNull ResourceResolver resourceResolver, final String resourceType) { return resourceResolver.getParentResourceType(resourceType); }
/** * Returns the super type of the given resource. This method checks first if * the resource itself knows its super type by calling * {@link Resource#getResourceSuperType()}. If that returns * <code>null</code> {@link #getResourceSuperType(ResourceResolver, String)} * is invoked with the resource type of the resource. * * @param resource The resource to return the resource super type for. * @return the super type of the <code>resource</code> or <code>null</code> * if no super type could be computed. * @throws IllegalStateException if the resource resolver has already been * closed}. * @since 2.0.6 (Sling API Bundle 2.0.6) * @deprecated Use {@link ResourceResolver#getParentResourceType(Resource)} */ @Deprecated public static @Nullable String findResourceSuperType(@NotNull final Resource resource) { if ( resource == null ) { return null; } return resource.getResourceResolver().getParentResourceType(resource); }
private static Resource findSuperComponent(Resource base) { ResourceResolver resolver = base.getResourceResolver(); String superType = resolver.getParentResourceType(base); if (superType == null) { return null; } return resolver.getResource(superType); }
/** * Dumps the information about the provided resource to a {@link PrintWriter}. * @param pw the PrintWriter * @param r the resource * @param map the resource's properties */ protected void dump(PrintWriter pw, Resource r, Map<String, Object> map) { pw.println("** Resource dumped by " + getClass().getSimpleName() + "**"); pw.println("Resource path:" + r.getPath()); pw.println("Resource metadata: " + r.getResourceMetadata()); pw.println("Resource type: " + r.getResourceType()); String resourceSuperType = r.getResourceResolver().getParentResourceType(r); if (resourceSuperType == null) { resourceSuperType = "-"; } pw.println("Resource super type: " + resourceSuperType); pw.println("\n** Resource properties **"); final Iterator<Map.Entry<String,Object>> pi = map.entrySet().iterator(); while ( pi.hasNext() ) { final Map.Entry<String,Object> p = pi.next(); printPropertyValue(pw, p.getKey(), p.getValue(), true); pw.println(); } }
/** * Calls {@link ResourceUtil#getResourceSuperType(ResourceResolver, String)} * method to dynamically resolve the resource super type of this star * resource. */ @Override public String getResourceSuperType() { // Yes, this isn't how you're supposed to compare Strings, but this is // intentional. if (resourceSuperType == UNSET_RESOURCE_SUPER_TYPE) { resourceSuperType = this.getResourceResolver().getParentResourceType(this.getResourceType()); } return resourceSuperType; }
private void printResourceInfo(final PrintWriter pw, final Resource r) { pw.print("<h1>Resource dumped by "); pw.print(xssApi.encodeForHTML(getClass().getSimpleName())); pw.println("</h1>"); pw.print("<p>Resource path: <b>"); pw.print(xssApi.encodeForHTML(r.getPath())); pw.println("</b></p>"); pw.print("<p>Resource metadata: <b>"); pw.print(xssApi.encodeForHTML(String.valueOf(r.getResourceMetadata()))); pw.println("</b></p>"); pw.print("<p>Resource type: <b>"); pw.print(xssApi.encodeForHTML(r.getResourceType())); pw.println("</b></p>"); String resourceSuperType = r.getResourceResolver().getParentResourceType(r); if (resourceSuperType == null) { resourceSuperType = "-"; } pw.print("<p>Resource super type: <b>"); pw.print(xssApi.encodeForHTML(resourceSuperType)); pw.println("</b></p>"); }
private SlingServletView resolveScriptingView(String resourceType) { final ResourceResolver resourceResolver = ((SlingHttpServletRequest) ((ServletRequestAttributes) getRequestAttributes()).getRequest()).getResourceResolver(); // Support script inheritance by traversing the type hierarchy of the resource. // The type hierarchy is also traversed by the Servlet Resolver, but the resolver // only does this compliant to the Sling Script resolution when invoked with a HTTP request. // However, invocation with a request relies on an undocumented and unstable API contract, // depending, amongst others, on the HTTP method, request path, suffix, selector and extension // of the request path, which cannot be leveraged for controller responses. // Thus, the script is resolved explicitly. String currentResourceType = resourceType; do { int separatorPos = currentResourceType.lastIndexOf('/'); if (separatorPos != -1) { // Since the view resolution is not sensitive to request state, resolve the default view name // for a resource type, e.g. "myType" in app/components/myType, for instance app/components/myType/myType.html String defaultScriptName = currentResourceType.substring(separatorPos); Servlet servlet = getServlet(resourceResolver, currentResourceType, defaultScriptName); if (servlet != null) { return new SlingServletView(resourceType, servlet); } } currentResourceType = resourceResolver.getParentResourceType(currentResourceType); } while (currentResourceType != null); return null; }
String superType = resolver.getParentResourceType(resource); while (!result && superType != null) { if (ResourceType.equals(resourceType, superType)) { superType = resolver.getParentResourceType(superType); if (superType != null && superTypesChecked.contains(superType)) { throw new SlingException("Cyclic dependency for resourceSuperType hierarchy detected on resource " + resource.getPath(), null);
private Resource getComponentEditPath(Resource component) { if (component != null) { if (component.getChild("edit") != null) { return component.getChild("edit"); } else { String parentResourceType = component.getResourceResolver().getParentResourceType(component); if (StringUtils.isNotBlank(parentResourceType)) { component = component.getResourceResolver().getResource(parentResourceType); if (component != null) { return getComponentEditPath(component); } } } } return null; }