Returns the base URI.<p>

@param req the servlet request
@param cms the CmsObject

@return the base URI
552817
private String getBaseUri(HttpServletRequest req, CmsObject cms) {

        String baseUri = req.getParameter(PARAM_BASE_URI);
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(baseUri)) {
            String referer = req.getHeader(HEADER_REFERER_KEY);
            CmsSite site = OpenCms.getSiteManager().getSiteForSiteRoot(cms.getRequestContext().getSiteRoot());
            if (site != null) {
                String prefix = site.getServerPrefix(cms, "/") + OpenCms.getStaticExportManager().getVfsPrefix();
                if ((referer != null) && referer.startsWith(prefix)) {
                    baseUri = referer.substring(prefix.length());
                }
            }
        }
        return baseUri;
    }
871472
protected String getBaseURL(HttpServletRequest request) {
//        if (forcedBaseAddress != null) {
//            return forcedBaseAddress;
//        }

        String reqPrefix = request.getRequestURL().toString();
        String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
        //fix for CXF-898
        if (!"/".equals(pathInfo) || reqPrefix.endsWith("/")) {
            StringBuilder sb = new StringBuilder();
            // request.getScheme(), request.getLocalName() and request.getLocalPort()
            // should be marginally cheaper - provided request.getLocalName() does
            // return the actual name used in request URI as opposed to localhost
            // consistently across the Servlet stacks

            URI uri = URI.create(reqPrefix);
            sb.append(uri.getScheme()).append("://").append(uri.getRawAuthority());

            //No servletPath will be appended, as in Liberty, each endpoint will be served by one servlet instance
            sb.append(request.getContextPath());

            reqPrefix = sb.toString();
        }
        return reqPrefix;
    }
587301
public static String getVaadinWorkplaceLink(CmsObject cms, String resourceRootFolder) {

        CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(resourceRootFolder);
        String siteRoot = site != null
        ? site.getSiteRoot()
        : OpenCms.getSiteManager().startsWithShared(resourceRootFolder)
        ? OpenCms.getSiteManager().getSharedFolder()
        : "";
        String sitePath = resourceRootFolder.substring(siteRoot.length());
        String link = getFileExplorerLink(cms, siteRoot) + sitePath;
        return link;
    }
340063
public static URI getUri(UriInfo uriInfo,
                             HttpServletRequest req,
                             String path) {
        String suffix = "";
        if (req.getRequestURI().endsWith(".json")) {
            suffix = ".json";
        } else if (req.getRequestURI().endsWith(".xml")) {
            suffix = ".xml";
        }
        return URI.create(uriInfo.getBaseUri() + "/" + path + suffix);
    }
887813
private static CmsXmlContainerPage getCache(CmsObject cms, CmsResource resource, boolean keepEncoding) {

        if (resource instanceof I_CmsHistoryResource) {
            return null;
        }
        return getCache().getCacheContainerPage(
            getCache().getCacheKey(resource.getStructureId(), keepEncoding),
            cms.getRequestContext().getCurrentProject().isOnlineProject());
    }
431792
public CmsObject getOfflineCmsObject(CmsObject cms) {

        CmsObject res = null;
        try {
            if (!cms.getRequestContext().getCurrentProject().isOnlineProject()) {
                return OpenCms.initCmsObject(cms);
            }
            res = OpenCms.initCmsObject(cms);
            List<CmsProject> projects = OpenCms.getOrgUnitManager().getAllAccessibleProjects(res, "/", true);
            Iterator<CmsProject> projIterator = projects.iterator();
            boolean offFound = false;
            while (projIterator.hasNext() & !offFound) {
                CmsProject offP = projIterator.next();
                if (!offP.isOnlineProject()) {
                    res.getRequestContext().setCurrentProject(offP);
                    offFound = true;
                }
            }
        } catch (CmsException e) {
            return cms;
        }
        return res;
    }
1218351
private CmsSpellcheckingRequest parseHttpRequest(final ServletRequest req, final CmsObject cms) {

        if ((null != cms) && OpenCms.getRoleManager().hasRole(cms, CmsRole.ROOT_ADMIN)) {
            try {
                if (null != req.getParameter(HTTP_PARAMETER_CHECKREBUILD)) {
                    if (CmsSpellcheckDictionaryIndexer.updatingIndexNecessesary(cms)) {

                        parseAndAddDictionaries(cms);

                    }
                }

                if (null != req.getParameter(HTTP_PARAMTER_REBUILD)) {
                    parseAndAddDictionaries(cms);
                }
            } catch (CmsRoleViolationException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }

        final String q = req.getParameter(HTTP_PARAMETER_WORDS);

        if (null == q) {
            LOG.debug("Invalid HTTP request: No parameter \"" + HTTP_PARAMETER_WORDS + "\" defined. ");
            return null;
        }

        final StringTokenizer st = new StringTokenizer(q);
        final List<String> wordsToCheck = new ArrayList<String>();
        while (st.hasMoreTokens()) {
            final String word = st.nextToken();
            wordsToCheck.add(word);

            if (Character.isUpperCase(word.codePointAt(0))) {
                wordsToCheck.add(word.toLowerCase());
            }
        }

        final String[] w = wordsToCheck.toArray(new String[wordsToCheck.size()]);
        final String dict = req.getParameter(HTTP_PARAMETER_LANG) == null
        ? LANG_DEFAULT
        : req.getParameter(HTTP_PARAMETER_LANG);

        return new CmsSpellcheckingRequest(w, dict);
    }
392030
public static String getFormLink(CmsObject cms) {

        return OpenCms.getLinkManager().substituteLinkForUnknownTarget(
            cms,
            CmsWorkplaceLoginHandler.LOGIN_HANDLER,
            false);
    }
939283
public CmsTemplateContextInfo getContextInfoBean(CmsObject cms, HttpServletRequest request) {

        CmsTemplateContextInfo result = new CmsTemplateContextInfo();
        CmsTemplateContext context = (CmsTemplateContext)request.getAttribute(ATTR_TEMPLATE_CONTEXT);
        if (context != null) {
            result.setCurrentContext(context.getKey());

            I_CmsTemplateContextProvider provider = context.getProvider();
            Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
            CmsXmlContentProperty settingDefinition = createTemplateContextsPropertyDefinition(provider, locale);
            result.setSettingDefinition(settingDefinition);
            String cookieName = context.getProvider().getOverrideCookieName();
            if (cookieName != null) {
                String cookieValue = CmsRequestUtil.getCookieValue(request.getCookies(), cookieName);
                result.setSelectedContext(cookieValue);
            }
            result.setCookieName(cookieName);
            Map<String, String> niceNames = new LinkedHashMap<String, String>();
            for (Map.Entry<String, CmsTemplateContext> entry : provider.getAllContexts().entrySet()) {
                CmsTemplateContext otherContext = entry.getValue();
                String niceName = otherContext.getLocalizedName(locale);
                niceNames.put(otherContext.getKey(), niceName);
                for (CmsClientVariant variant : otherContext.getClientVariants().values()) {
                    CmsClientVariantInfo info = new CmsClientVariantInfo(
                        variant.getName(),
                        variant.getNiceName(locale),
                        variant.getScreenWidth(),
                        variant.getScreenHeight(),
                        variant.getParameters());
                    result.setClientVariant(otherContext.getKey(), variant.getName(), info);
                }
            }
            result.setContextLabels(niceNames);
            result.setContextProvider(provider.getClass().getName());
        }
        Map<String, CmsDefaultSet<String>> allowedContextMap = safeGetAllowedContextMap();
        result.setAllowedContexts(allowedContextMap);
        return result;
    }
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;

    }
177245
public String getRepositoryBaseFolderName(CmsObject cms) {

        String value = "";
        try {
            value = cms.readPropertyObject(
                CmsCategoryService.CENTRALIZED_REPOSITORY,
                CmsPropertyDefinition.PROPERTY_DEFAULT_FILE,
                false).getValue();
        } catch (CmsException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(value)) {
            value = OpenCms.getWorkplaceManager().getCategoryFolder();
        }
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(value)) {
            value = REPOSITORY_BASE_FOLDER;
        }
        if (!value.endsWith("/")) {
            value += "/";
        }
        if (!value.startsWith("/")) {
            value = "/" + value;
        }
        return value;
    }
782369
protected String getUriStyleSheet(CmsObject cms, CmsResource res) {

        String result = "";
        try {
            String currentTemplate = getUriTemplate(cms, res);
            if (!"".equals(currentTemplate)) {
                // read the stylesheet from the template file
                result = cms.readPropertyObject(
                    currentTemplate,
                    CmsPropertyDefinition.PROPERTY_TEMPLATE,
                    false).getValue("");
            }
        } catch (CmsException e) {
            // noop
        }
        return result;
    }
407004
public static final String getType(CmsObject cms, String rootPath) {

        String type = null;
        CmsSolrIndex index = CmsSearchManager.getIndexSolr(cms, null);
        if (index != null) {
            I_CmsSearchDocument doc = index.getDocument(CmsSearchField.FIELD_PATH, rootPath);
            if (doc != null) {
                type = doc.getFieldValueAsString(CmsSearchField.FIELD_TYPE);
            }
        }
        return type;
    }
1113364
protected CmsObject getCms() {

        if (m_cms == null) {
            try {
                m_cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
                m_cms.getRequestContext().setSiteRoot("");
            } catch (CmsException e) {
                return null;
            }
        }
        return m_cms;
    }
715753
private CmsObject getRootCms() {

        if (m_cms == null) {
            m_cms = A_CmsUI.getCmsObject();
            m_cms.getRequestContext().setSiteRoot("");
        }
        return m_cms;
    }
410764
public CmsSite matchRequest(HttpServletRequest req) {

        CmsSiteMatcher matcher = getRequestMatcher(req);
        if (matcher.getTimeOffset() != 0) {
            HttpSession session = req.getSession();
            if (session != null) {
                session.setAttribute(
                    CmsContextInfo.ATTRIBUTE_REQUEST_TIME,
                    new Long(System.currentTimeMillis() + matcher.getTimeOffset()));
            }
        }
        CmsSite site = matchSite(matcher);

        if (LOG.isDebugEnabled()) {
            String requestServer = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
            LOG.debug(
                Messages.get().getBundle().key(
                    Messages.LOG_MATCHING_REQUEST_TO_SITE_2,
                    requestServer,
                    site.toString()));
        }
        return site;
    }
1246661
protected void showResource(HttpServletRequest req, HttpServletResponse res) {

        CmsObject cms = null;
        try {
            cms = initCmsObject(req, res);

            if (cms.getRequestContext().getCurrentProject().isOnlineProject()) {
                String uri = cms.getRequestContext().getUri();
                if (uri.startsWith(CmsWorkplace.VFS_PATH_SITES)) {
                    // resources within the sites folder may only be called with their site relative path
                    // this should prevent showing pages from other sites with their root path
                    throw new CmsVfsResourceNotFoundException(
                        org.opencms.main.Messages.get().container(org.opencms.main.Messages.ERR_PATH_NOT_FOUND_1, uri));
                }
                if (OpenCms.getStaticExportManager().isExportLink(cms, uri)) {
                    // if we used the request's query string for getRfsName, clients could cause an unlimited number
                    // of files to be exported just by varying the request parameters!
                    String url = m_linkManager.getOnlineLink(cms, uri);
                    res.sendRedirect(url);
                    return;
                }
            }
            List<CmsSiteMatcher> currentSiteAliase = m_siteManager.getCurrentSite(cms).getAliases();
            CmsSiteMatcher currentSiteMatcher = cms.getRequestContext().getRequestMatcher();
            if (currentSiteAliase.contains(currentSiteMatcher.forDifferentScheme("http"))
                || currentSiteAliase.contains(currentSiteMatcher.forDifferentScheme("https"))) {
                int pos = currentSiteAliase.indexOf(currentSiteMatcher.forDifferentScheme("http"));
                if (pos == -1) {
                    pos = currentSiteAliase.indexOf(currentSiteMatcher.forDifferentScheme("https"));
                }
                if (currentSiteAliase.get(pos).isRedirect()) {
                    res.sendRedirect(
                        m_siteManager.getCurrentSite(cms).getUrl() + req.getContextPath() + req.getPathInfo());
                    return;
                }
            }

            // user is initialized, now deliver the requested resource
            CmsResource resource = initResource(cms, cms.getRequestContext().getUri(), req, res);
            if (resource != null) {
                // a file was read, go on process it
                m_resourceManager.loadResource(cms, resource, req, res);
                m_sessionManager.updateSessionInfo(cms, req);
            }

        } catch (Throwable t) {
            errorHandling(cms, req, res, t);
        }
    }