public SlingUriBuilder rebaseResourcePath()

in src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java [422:455]


    public SlingUriBuilder rebaseResourcePath() {
        if (schemeSpecificPart != null || resourcePath == null) {
            return this;
        }
        if (resourceResolver == null) {
            throw new IllegalStateException("setResourceResolver() needs to be called before balanceResourcePath()");
        }

        String path = assemblePath(false);
        if (path == null) {
            return this; // nothing to rebase
        }
        ResourcePathIterator it = new ResourcePathIterator(path);
        String availableResourcePath = null;
        while (it.hasNext()) {
            availableResourcePath = it.next();
            if (resourceResolver.getResource(availableResourcePath) != null) {
                break;
            }
        }
        if (availableResourcePath == null) {
            return this; // nothing to rebase
        }

        selectors.clear();
        extension = null;
        suffix = null;
        if (availableResourcePath.length() == path.length()) {
            resourcePath = availableResourcePath;
        } else {
            setPathWithDefinedResourcePosition(path, availableResourcePath.length());
        }
        return this;
    }