private String getPath()

in src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/URIManipulationFilterExtension.java [180:233]


    private String getPath(
            RuntimeObjectModel runtimeObjectModel,
            String originalPath,
            Map<String, Object> options,
            boolean isAbsolute) {
        SlingUriBuilder requestPathInfo = StringUtils.isBlank(originalPath)
                ? SlingUriBuilder.create()
                : SlingUriBuilder.parse(originalPath, null);
        final String prependPath = getOption(PREPEND_PATH, options, StringUtils.EMPTY, true);
        final String path = getOption(
                PATH,
                options,
                requestPathInfo.getResourcePath(),
                true); // empty path option should not remove existing path!
        final String appendPath = getOption(APPEND_PATH, options, StringUtils.EMPTY, true);
        if (!options.containsKey(PATH) && StringUtils.isEmpty(path)) {
            // no not prepend/append if path is neither set initially nor through option
            LOG.debug("Do not modify path because original path was empty and not set through an option either!");
            // dealing with selectors, extension or suffix is not allowed then either
            return requestPathInfo.build().toString();
        } else {
            String newPath = concatenateWithSlashes(prependPath, path, appendPath);

            // do we need to make the path absolute?
            if (isAbsolute && !newPath.startsWith("/")) {
                newPath = '/' + newPath;
            }
            // modify resource path
            requestPathInfo.setResourcePath(newPath);
        }

        handleSelectors(runtimeObjectModel, requestPathInfo, options);
        // handle extension
        String extension = getOption(EXTENSION, options, requestPathInfo.getExtension(), false);
        requestPathInfo.setExtension(extension);

        // modify suffix!
        String prependSuffix = getOption(PREPEND_SUFFIX, options, StringUtils.EMPTY, true);
        // remove suffix if option is empty
        String suffix = getOption(SUFFIX, options, requestPathInfo.getSuffix(), false);
        String appendSuffix = getOption(APPEND_SUFFIX, options, StringUtils.EMPTY, true);

        String newSuffix = concatenateWithSlashes(prependSuffix, suffix, appendSuffix);
        if (StringUtils.isNotEmpty(newSuffix)) {
            // make sure it starts with a slash
            if (!newSuffix.startsWith("/")) {
                newSuffix = '/' + newSuffix;
            }
            requestPathInfo.setSuffix(newSuffix);
        } else {
            requestPathInfo.setSuffix(null);
        }
        return requestPathInfo.build().toString();
    }