Helper method for getting the site path for a uri.<p>

@param uri a VFS uri
@return the site path
331478
protected String getSitePath(String uri) {

        if (m_internal) {
            String siteRoot = getSiteRoot();
            if (siteRoot != null) {
                return uri.substring(siteRoot.length());
            } else {
                return uri;
            }
        }
        return null;
    }
1192044
public synchronized SiteNode findClosestParent(URI uri) {
    	if (uri == null) {
    		return null;
    	}
        SiteNode lastParent = null;
        SiteNode parent = getRoot();
        String folder = "";
        
        try {
        	String host = getHostName(uri);
        	
            // no host yet
            parent = findChild(parent, host);
            if (parent == null) {
                return null;
        	}
            lastParent = parent;
            
            List<String> path = model.getSession().getTreePath(uri);
            for (int i=0; i < path.size(); i++) {
            	folder = path.get(i);
                if (folder != null && !folder.equals("")) {
                    if (i == path.size()-1) {
                        lastParent = parent;
                    } else {
                        parent = findChild(parent, folder);
                        if (parent == null) {
                            break;
                        }
                        lastParent = parent;
                    }
                }
            }
        } catch (URIException e) {
            log.error(e.getMessage(), e);
        }
        
        return lastParent;
    }
1156175
public Server getServerByUri(final String uri) {
        for (Server server : SERVERS) {
            if (server.getManagementUri().equals(uri)) {
                return server;
            }
        }

        return null;
    }
73056
public String getPath() {
        final Object path = getHeader(DynamicEndpointUriResolver.REQUEST_PATH_HEADER_NAME);

        if (path != null) {
            return path.toString();
        }

        return null;
    }
812661
public static String resourceName(URI uri) {
        if (!CLASSPATH_SCHEME.equals(uri.getScheme())) {
            throw new IllegalArgumentException("uri must have classpath scheme " + uri);
        }

        String resourceName = uri.getSchemeSpecificPart();
        if (resourceName.startsWith("/")) {
            return resourceName.substring(1);
        }
        return resourceName;
    }
781320
public static String getResourceUri(Resource resource) {
        try {
            return resource.getURI().toString();
        } catch (FileNotFoundException e) {
            return resource.getDescription();
        } catch (IOException e) {
            throw new RuntimeException("Could not create URI for resource: " + resource, e);
        }
    }
40504
public static String getName(URI uri) {
        if (uri == null) {
            throw MESSAGES.nullArgument("uri");
        }
        String name = uri.getPath();
        if (name != null) {
            // TODO: Not correct for certain uris like jar:...!/
            int lastSlash = name.lastIndexOf('/');
            if (lastSlash > 0) { name = name.substring(lastSlash + 1); }
        }
        return name;
    }
915445
public String getPath() {
        if (path == null) {
            // create a URI to automatically decode the path
            URI uri = URI.create(httpServletRequest.getRequestURL().toString());
            String requestUri = uri.getPath();

            path = applicationPath.isEmpty() ? requestUri : requestUri.substring(applicationPath.length());
            if (StringUtils.isNullOrEmpty(path)) {
                path = "/";
            }
        }

        return path;
    }
120960
public static String getURL(String sourceURI) {
        String retval = sourceURI;
        int qPos = sourceURI.indexOf("?");
        if (qPos != -1) {
            retval = retval.substring(0, qPos);
        }

        return retval;
    }
364398
public static function sites(String $uri = NULL) : String
    {
        return str_replace(SSL_STATUS, Http::fix(true), self::site($uri));
    }
287051
public static URI uriParent(URI uri) {
        return uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve(".");
    }
1047707
public URI getURI() {
        final URI locationURI = getClasspathElementURI();
        final String resourcePath = getPathRelativeToClasspathElement();
        final String locationURIStr = locationURI.toString();
        // Check if this is a directory-based module (location URI will end in "/")
        final boolean isDir = locationURIStr.endsWith("/");
        try {
            return new URI((isDir || locationURIStr.startsWith("jar:") ? "" : "jar:") + locationURIStr
                    + (isDir ? "" : "!/") + resourcePath);
        } catch (final URISyntaxException e) {
            throw new IllegalArgumentException("Could not form URL for classpath element: " + locationURIStr
                    + " ; path: " + resourcePath + " : " + e);
        }
    }
1213763
public static String getBasePath(String siteConfigFile) {

        if (siteConfigFile.endsWith(CmsADEManager.CONFIG_SUFFIX)) {
            return CmsResource.getParentFolder(CmsResource.getParentFolder(siteConfigFile));
        }
        return null;
    }
1192838
public function sitePath($uri)
    {
        $expression = array_filter(explode('/', $this->request->server['REQUEST_URI']));
        $index = (false !== array_search(Router::$indexPage, $expression)) ? Router::$indexPage.'/' : '';
        
        return $this->getBase().$index.$uri;
    }
449546
protected String getSimpleRootPath(CmsObject cms, String targetUri, String basePath) {

        if (cms == null) {
            // required by unit test cases
            return targetUri;
        }

        URI uri;
        String path;
        String suffix = "";

        // malformed uri
        try {
            uri = new URI(targetUri);
            path = uri.getPath();
            suffix = getSuffix(uri);
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn(Messages.get().getBundle().key(Messages.LOG_MALFORMED_URI_1, targetUri), e);
            }
            return null;
        }
        // opaque URI
        if (uri.isOpaque()) {
            return null;
        }

        // in case the target is the workplace UI
        if (CmsLinkManager.isWorkplaceUri(uri)) {
            return null;
        }

        // in case the target is a static resource served from the class path
        if (CmsStaticResourceHandler.isStaticResourceUri(uri)) {
            return CmsStringUtil.joinPaths(
                CmsStaticResourceHandler.STATIC_RESOURCE_PREFIX,
                CmsStaticResourceHandler.removeStaticResourcePrefix(path));
        }

        CmsStaticExportManager exportManager = OpenCms.getStaticExportManager();
        if (exportManager.isValidRfsName(path)) {
            String originalSiteRoot = cms.getRequestContext().getSiteRoot();
            String vfsName = null;
            try {
                cms.getRequestContext().setSiteRoot("");
                vfsName = exportManager.getVfsName(cms, path);
                if (vfsName != null) {
                    return vfsName;
                }
            } finally {
                cms.getRequestContext().setSiteRoot(originalSiteRoot);
            }
        }

        // absolute URI (i.e. URI has a scheme component like http:// ...)
        if (uri.isAbsolute()) {
            CmsSiteMatcher targetMatcher = new CmsSiteMatcher(targetUri);
            if (OpenCms.getSiteManager().isMatching(targetMatcher)
                || targetMatcher.equals(cms.getRequestContext().getRequestMatcher())) {

                path = CmsLinkManager.removeOpenCmsContext(path);
                boolean isWorkplaceServer = OpenCms.getSiteManager().isWorkplaceRequest(targetMatcher)
                    || targetMatcher.equals(cms.getRequestContext().getRequestMatcher());
                if (isWorkplaceServer) {
                    String selectedPath;
                    String targetSiteRoot = OpenCms.getSiteManager().getSiteRoot(path);
                    if (targetSiteRoot != null) {
                        selectedPath = getRootPathForSite(cms, path, targetSiteRoot, true);
                    } else {
                        // set selectedPath with the path for the current site
                        selectedPath = getRootPathForSite(cms, path, cms.getRequestContext().getSiteRoot(), false);
                        String pathForMatchedSite = getRootPathForSite(
                            cms,
                            path,
                            OpenCms.getSiteManager().matchSite(targetMatcher).getSiteRoot(),
                            false);
                        String originalSiteRoot = cms.getRequestContext().getSiteRoot();
                        try {
                            cms.getRequestContext().setSiteRoot("");
                            // the path for the current site normally is preferred, but if it doesn't exist and the path for the matched site
                            // does exist, then use the path for the matched site
                            if (!cms.existsResource(selectedPath, CmsResourceFilter.ALL)
                                && cms.existsResource(pathForMatchedSite, CmsResourceFilter.ALL)) {
                                selectedPath = pathForMatchedSite;
                            }
                        } finally {
                            cms.getRequestContext().setSiteRoot(originalSiteRoot);
                        }
                    }
                    return selectedPath + suffix;
                } else {
                    // add the site root of the matching site
                    return getRootPathForSite(
                        cms,
                        path + suffix,
                        OpenCms.getSiteManager().matchSite(targetMatcher).getSiteRoot(),
                        false);
                }
            } else {
                return null;
            }
        }

        // relative URI (i.e. no scheme component, but filename can still start with "/")
        String context = OpenCms.getSystemInfo().getOpenCmsContext();
        String vfsPrefix = OpenCms.getStaticExportManager().getVfsPrefix();
        if ((context != null) && (path.startsWith(context + "/") || (path.startsWith(vfsPrefix + "/")))) {
            // URI is starting with opencms context

            // cut context from path
            path = CmsLinkManager.removeOpenCmsContext(path);

            String targetSiteRoot = getTargetSiteRoot(cms, path, basePath);

            return getRootPathForSite(
                cms,
                path + suffix,
                targetSiteRoot,
                (targetSiteRoot != null) && path.startsWith(targetSiteRoot));
        }

        // URI with relative path is relative to the given relativePath if available and in a site,
        // otherwise invalid
        if (CmsStringUtil.isNotEmpty(path) && (path.charAt(0) != '/')) {
            if (basePath != null) {
                String absolutePath;
                int pos = path.indexOf("../../galleries/pics/");
                if (pos >= 0) {
                    // HACK: mixed up editor path to system gallery image folder
                    return CmsWorkplace.VFS_PATH_SYSTEM + path.substring(pos + 6) + suffix;
                }
                absolutePath = CmsLinkManager.getAbsoluteUri(path, cms.getRequestContext().addSiteRoot(basePath));
                if (OpenCms.getSiteManager().getSiteRoot(absolutePath) != null) {
                    return absolutePath + suffix;
                }
                // HACK: some editor components (e.g. HtmlArea) mix up the editor URL with the current request URL
                absolutePath = CmsLinkManager.getAbsoluteUri(
                    path,
                    cms.getRequestContext().getSiteRoot() + CmsWorkplace.VFS_PATH_EDITORS);
                if (OpenCms.getSiteManager().getSiteRoot(absolutePath) != null) {
                    return absolutePath + suffix;
                }
                // HACK: same as above, but XmlContent editor has one path element more
                absolutePath = CmsLinkManager.getAbsoluteUri(
                    path,
                    cms.getRequestContext().getSiteRoot() + CmsWorkplace.VFS_PATH_EDITORS + "xmlcontent/");
                if (OpenCms.getSiteManager().getSiteRoot(absolutePath) != null) {
                    return absolutePath + suffix;
                }
            }

            return null;
        }

        if (CmsStringUtil.isNotEmpty(path)) {
            String targetSiteRoot = getTargetSiteRoot(cms, path, basePath);

            return getRootPathForSite(
                cms,
                path + suffix,
                targetSiteRoot,
                (targetSiteRoot != null) && path.startsWith(targetSiteRoot));
        }

        // URI without path (typically local link)
        return suffix;
    }
475606
public String findString(String uri) throws IOException {
        String fullUri = path + uri;

        URL resource = getResource(fullUri);
        if (resource == null) {
            throw new IOException("Could not find a resource in : " + fullUri);
        }

        return readContents(resource);
    }
36976
function ( uri ) {
    var ret = {
        folder: false,
        redirect: false
    };

    uri = uri.replace( rSlash, "" );

    for ( var i = serverConfig.siteData.siteLayout.layout.length; i--; ) {
        var layout = serverConfig.siteData.siteLayout.layout[ i ];

        // Break out if folder matched
        if ( ret.folder ) {
            break;
        }

        // Skip hidden navigations
        //if ( layout.identifier === "_hidden" ) {
        //    continue;
        //}

        for ( var j = layout.links.length; j--; ) {
            var link = layout.links[ j ];

            // Matched a root level folder uri request
            if ( rIndexFolder.test( link.typeName ) && link.urlId === uri ) {
                if ( rFolder && keyFiles.folderList ) {
                    break;

                } else if ( rIndex && keyFiles.indexList ) {
                    break;

                } else {
                    ret.folder = true;
                    ret.redirect = ("/" + link.children[ 0 ].urlId + "/");
                    break;
                }
            }
        }
    }

    return ret;
}