Tries to get the subsite root for a given resource root path.<p>

@param cms the current CMS context
@param rootPath the root path for which the subsite root should be found

@return the subsite root
976117
public String getSubSiteRoot(CmsObject cms, String rootPath) {

        CmsADEConfigData configData = lookupConfiguration(cms, rootPath);
        String basePath = configData.getBasePath();
        String siteRoot = OpenCms.getSiteManager().getSiteRoot(rootPath);
        if (siteRoot == null) {
            siteRoot = "";
        }
        if ((basePath == null) || !basePath.startsWith(siteRoot)) {
            // the subsite root should always be below the site root
            return siteRoot;
        } else {
            return basePath;
        }
    }
156589
public String addSiteRoot(String sitePath) {

        if (sitePath == null) {
            return null;
        }
        String siteRoot = getAdjustedSiteRoot(getSiteRoot(), sitePath);
        StringBuffer result = new StringBuffer(128);
        result.append(siteRoot);
        if (((siteRoot.length() == 0) || (siteRoot.charAt(siteRoot.length() - 1) != '/'))
            && ((sitePath.length() == 0) || (sitePath.charAt(0) != '/'))) {
            // add slash between site root and resource if required
            result.append('/');
        }
        result.append(sitePath);
        return result.toString();
    }
89436
public String getLink(CmsObject cms) {

        if (m_internal) {
            // if we have a local link, leave it unchanged
            // cms may be null for unit tests
            if ((cms == null) || (m_uri.length() == 0) || (m_uri.charAt(0) == '#')) {
                return m_uri;
            }

            checkConsistency(cms);
            //String target = replaceTargetWithDetailPageIfNecessary(cms, m_resource, m_target);
            String target = m_target;
            String uri = computeUri(target, m_query, m_anchor);

            CmsObjectWrapper wrapper = (CmsObjectWrapper)cms.getRequestContext().getAttribute(
                CmsObjectWrapper.ATTRIBUTE_NAME);
            if (wrapper != null) {
                // if an object wrapper is used, rewrite the URI
                m_uri = wrapper.rewriteLink(m_uri);
                uri = wrapper.rewriteLink(uri);
            }

            if ((cms.getRequestContext().getSiteRoot().length() == 0)
                && (cms.getRequestContext().getAttribute(CmsRequestContext.ATTRIBUTE_EDITOR) == null)) {
                // Explanation why this check is required:
                // If the site root name length is 0, this means that a user has switched
                // the site root to the root site "/" in the Workplace.
                // In this case the workplace site must also be the active site.
                // If the editor is opened in the root site, because of this code the links are
                // always generated _with_ server name / port so that the source code looks identical to code
                // that would normally be created when running in a regular site.
                // If normal link processing would be used, the site information in the link
                // would be lost.
                return OpenCms.getLinkManager().substituteLink(cms, uri);
            }

            // get the site root for this URI / link
            // if there is no site root, we either have a /system link, or the site was deleted,
            // return the full URI prefixed with the opencms context
            String siteRoot = getSiteRoot();
            if (siteRoot == null) {
                return OpenCms.getLinkManager().substituteLink(cms, uri);
            }

            if (cms.getRequestContext().getAttribute(CmsRequestContext.ATTRIBUTE_FULLLINKS) != null) {
                // full links should be generated even if we are in the same site
                return OpenCms.getLinkManager().getServerLink(cms, uri);
            }

            // return the link with the server prefix, if necessary
            return OpenCms.getLinkManager().substituteLink(cms, getSitePath(uri), siteRoot);
        } else {

            // don't touch external links
            return m_uri;
        }
    }
1213763
public static String getBasePath(String siteConfigFile) {

        if (siteConfigFile.endsWith(CmsADEManager.CONFIG_SUFFIX)) {
            return CmsResource.getParentFolder(CmsResource.getParentFolder(siteConfigFile));
        }
        return null;
    }
1246831
private String getRootPath(String path, int rootLevel, ResourceResolver resourceResolver) {
    String rootPath = Path.getAbsoluteParent(path, rootLevel, resourceResolver);

    // strip off everything after first "." - root path may be passed with selectors/extension which is not relevant
    if (StringUtils.contains(rootPath, ".")) {
      rootPath = StringUtils.substringBefore(rootPath, ".");
    }

    return rootPath;
  }
1011215
CmsObject getRootCms() {

        try {
            if (m_rootCms == null) {

                m_rootCms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
                m_rootCms.getRequestContext().setSiteRoot("");
            }
        } catch (CmsException e) {
            //
        }
        return m_rootCms;

    }
913029
public List<CmsAlias> getAliasesForSite(CmsObject cms, String siteRoot) throws CmsException {

        return m_securityManager.getAliasesForSite(cms.getRequestContext(), siteRoot);
    }
1047755
public static String getFileExplorerLink(CmsObject cms, String siteRoot) {

        return CmsVaadinUtils.getWorkplaceLink()
            + "#!"
            + CmsFileExplorerConfiguration.APP_ID
            + "/"
            + cms.getRequestContext().getCurrentProject().getUuid()
            + "!!"
            + siteRoot
            + "!!";
    }
538784
private static CmsResource getDefaultResource(CmsObject cms, String path) {

        CmsResource resource = (CmsResource)CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().getCachedObject(
            cms,
            path);
        if (resource == null) {
            try {
                resource = cms.readResource(path);
                CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().putCachedObject(cms, path, resource);
            } catch (CmsException e) {
                LOG.warn(e.getLocalizedMessage(), e);
            }
        }
        return resource;
    }
663364
private String getCommonAncestorPath(String rootPath1, String rootPath2) {

        if (rootPath1 == null) {
            return rootPath2;
        }
        if (rootPath2 == null) {
            return rootPath1;
        }
        rootPath1 = CmsStringUtil.joinPaths("/", rootPath1, "/");
        rootPath2 = CmsStringUtil.joinPaths("/", rootPath2, "/");
        int minLength = Math.min(rootPath1.length(), rootPath2.length());
        int i;
        for (i = 0; i < minLength; i++) {
            char char1 = rootPath1.charAt(i);
            char char2 = rootPath2.charAt(i);
            if (char1 != char2) {
                break;
            }
        }
        String result = rootPath1.substring(0, i);
        if ("/".equals(result)) {
            return result;
        }
        int slashIndex = result.lastIndexOf('/');
        result = result.substring(0, slashIndex);
        return result;
    }
474943
public CmsResource getResource() {

        return new CmsResource(
            m_base.getStructureId(),
            m_base.getResourceId(),
            m_rootPath,
            m_typeId,
            m_isFolder,
            m_base.getFlags(),
            m_base.getProjectLastModified(),
            m_base.getState(),
            m_base.getDateCreated(),
            m_base.getUserCreated(),
            m_base.getDateLastModified(),
            m_base.getUserLastModified(),
            m_base.getDateReleased(),
            m_base.getDateExpired(),
            m_base.getSiblingCount(),
            m_length,
            m_base.getDateContent(),
            m_base.getVersion());
    }
884438
public String getDetailPage(CmsObject cms, String pageRootPath, String originPath) {

        return getDetailPage(cms, pageRootPath, originPath, null);
    }
280364
CmsObject getCmsObjectWithSite(String siteRoot) {

        if (siteRoot == null) {
            siteRoot = "/";
        }
        try {
            CmsObject res = OpenCms.initCmsObject(m_cms);
            res.getRequestContext().setSiteRoot(siteRoot);
            return res;
        } catch (CmsException e) {
            LOG.error("Unable to initialize CmsObject", e);
            return m_cms;
        }
    }
423009
public static URL getStaticResourceURL(String resourcePath) {

        URL resourceURL = null;
        if (isStaticResourceUri(resourcePath)) {
            String path = removeStaticResourcePrefix(resourcePath);
            path = CmsStringUtil.joinPaths(OPENCMS_PATH_PREFIX, path);
            resourceURL = OpenCms.getSystemInfo().getClass().getClassLoader().getResource(path);
        }
        return resourceURL;
    }
373739
private static Set<URL> getResourcesFromRoot(final String rootPath) {

        final Set<URL> rets = new LinkedHashSet<URL>();

        String path = rootPath;

        if (path.startsWith("/")) {
            path = path.substring(1);
        }

        try {
            final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(path);
            URL url = null;

            while (resources.hasMoreElements()) {
                url = (URL) resources.nextElement();

                rets.add(url);
            }
        } catch (final IOException e) {
            LOGGER.log(Level.ERROR, "get the ROOT Rescources error", e);
        }
        return rets;
    }
1304832
protected String getRelativePath(String ancestor, String rootPath) {

        String result = rootPath.substring(ancestor.length());
        result = CmsStringUtil.joinPaths("/", result, "/");
        return result;
    }
808415
private String getCommonAncestorPath(Collection<CmsResource> resources) {

        if (resources.isEmpty()) {
            return "/";
        }
        String commonPath = null;
        for (CmsResource resource : resources) {
            commonPath = getCommonAncestorPath(commonPath, resource.getRootPath());
        }
        return commonPath;
    }