Gets an offline version of the cms object.<p>

@param cms initial CmsObject
@return CmsObject adjusted to offline project (cloned)
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;
    }
886796
public static CmsObject getCmsObject(ServletRequest req) {

        CmsFlexController controller = (CmsFlexController)req.getAttribute(ATTRIBUTE_NAME);
        if (controller != null) {
            return controller.getCmsObject();
        } else {
            return null;
        }
    }
1168054
protected CmsLink getXsdLink(CmsObject cms, CmsXmlContent xmlContent) {

        String schema = xmlContent.getContentDefinition().getSchemaLocation();
        if (schema.startsWith(CmsXmlEntityResolver.OPENCMS_SCHEME)) {
            if (CmsXmlEntityResolver.isInternalId(schema)) {
                return null;
            }
            schema = schema.substring(CmsXmlEntityResolver.OPENCMS_SCHEME.length() - 1);
        } else if (CmsXmlEntityResolver.isCachedSystemId(schema)) {
            // schema may not exist as a VFS file because it has just been cached (some test cases do this)
            return null;
        }
        try {
            CmsResource schemaRes = cms.readResource(cms.getRequestContext().removeSiteRoot(schema));
            CmsLink xsdLink = new CmsLink(
                null,
                CmsRelationType.XSD,
                schemaRes.getStructureId(),
                schemaRes.getRootPath(),
                true);
            return xsdLink;
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
        return null;
    }
1357717
private CmsADESessionCache getSessionCache(CmsObject cms) {

        return m_editableRequest
        ? CmsADESessionCache.getCache((HttpServletRequest)(pageContext.getRequest()), cms)
        : null;
    }
298681
public I_CmsResourceLoader getLoader(CmsResource resource) throws CmsLoaderException {

        return getLoader(getResourceType(resource.getTypeId()).getLoaderId());
    }
1001463
public CmsContainerPageBean getContainerPage(CmsObject cms) {

        Locale masterLocale = CmsLocaleManager.MASTER_LOCALE;
        Locale localeToLoad = null;
        // always use master locale if possible, otherwise use the first locale.
        // this is important for 'legacy' container pages which were created before container pages became locale independent
        if (m_cntPages.containsKey(masterLocale)) {
            localeToLoad = masterLocale;
        } else if (!m_cntPages.isEmpty()) {
            localeToLoad = m_cntPages.keySet().iterator().next();
        }
        if (localeToLoad == null) {
            return null;
        } else {
            CmsContainerPageBean result = m_cntPages.get(localeToLoad);
            return result;
        }
    }
924311
public List<String> getDetailPages(CmsObject cms, String type) {

        CmsConfigurationCache cache = isOnline(cms) ? m_onlineCache : m_offlineCache;
        return cache.getState().getDetailPages(type);
    }
431673
private CmsTemplateMapperConfiguration getConfiguration(final CmsObject cms) {

        if (!m_enabled) {
            return CmsTemplateMapperConfiguration.EMPTY_CONFIG;
        }

        if (m_configPath == null) {
            m_configPath = OpenCms.getSystemInfo().getConfigFilePath(cms, "template-mapping.xml");
        }

        return (CmsTemplateMapperConfiguration)(CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().loadVfsObject(
            cms,
            m_configPath,
            new Transformer() {

                @Override
                public Object transform(Object input) {

                    try {
                        CmsFile file = cms.readFile(m_configPath, CmsResourceFilter.IGNORE_EXPIRATION);
                        SAXReader saxBuilder = new SAXReader();
                        try (ByteArrayInputStream stream = new ByteArrayInputStream(file.getContents())) {
                            Document document = saxBuilder.read(stream);
                            CmsTemplateMapperConfiguration config = new CmsTemplateMapperConfiguration(cms, document);
                            return config;
                        }
                    } catch (Exception e) {
                        LOG.warn(e.getLocalizedMessage(), e);
                        return new CmsTemplateMapperConfiguration(); // empty configuration, does not do anything
                    }

                }
            }));
    }
978487
private CmsContainerPageBean getContainerPageBean(CmsResource resource) throws CmsException {

        CmsXmlContainerPage xmlCnt = CmsXmlContainerPageFactory.unmarshal(m_cms, m_cms.readFile(resource));
        return xmlCnt.getContainerPage(m_cms);
    }
473240
public static CmsResource readResource(CmsObject cms, CmsHistoryResourceBean bean) throws CmsException {

        CmsHistoryVersion versionBean = bean.getVersion();
        if (versionBean.getVersionNumber() != null) {
            return (CmsResource)(cms.readResource(bean.getStructureId(), versionBean.getVersionNumber().intValue()));
        } else {
            if (versionBean.isOnline()) {
                CmsObject onlineCms = OpenCms.initCmsObject(cms);
                onlineCms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
                return onlineCms.readResource(bean.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
            } else {
                return cms.readResource(bean.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
            }
        }
    }
1157690
public Map<String, String> getParameters(CmsObject cms) {

        Map<String, String> result = new LinkedHashMap<String, String>(m_parameters);
        if (cms != null) {
            String userParamsStr = (String)(cms.getRequestContext().getCurrentUser().getAdditionalInfo().get(
                "ADE_PARAMS"));
            if (userParamsStr != null) {
                Map<String, String> userParams = CmsStringUtil.splitAsMap(userParamsStr, "|", ":");
                result.putAll(userParams);
            }
        }
        return result;
    }
694499
public String getDescription(CmsObject cms) {

        if (m_description == null) {
            if (m_element.element(PARAM_DESCRIPTION) != null) {
                m_description = m_element.element(PARAM_DESCRIPTION).getText();
            }
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_description)) {
                m_description = getParameterValue(cms, PARAM_DESCRIPTION);
                m_description = CmsEncoder.unescape(m_description, CmsEncoder.ENCODING_UTF_8);
            }
        }
        return m_description;
    }
1168826
protected static I_CmsPreviewServiceAsync getService() {

        if (m_previewService == null) {
            m_previewService = GWT.create(I_CmsPreviewService.class);
            String serviceUrl = CmsCoreProvider.get().link("org.opencms.ade.galleries.CmsPreviewService.gwt");
            ((ServiceDefTarget)m_previewService).setServiceEntryPoint(serviceUrl);
        }
        return m_previewService;
    }
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;
    }
744531
public I_CmsEditHandler getEditHandler(CmsObject cms) {

        String schema = getSchema();

        try {
            CmsXmlContentDefinition contentDefinition = CmsXmlContentDefinition.unmarshal(cms, schema);
            // get the content handler for the resource type to create
            I_CmsXmlContentHandler handler = contentDefinition.getContentHandler();
            return handler.getEditHandler();

        } catch (CmsXmlException e) {
            LOG.error(e.getMessage(), e);
        }
        return null;
    }
194991
public static I_CmsXmlContentHandler getContentHandlerForResource(CmsObject cms, CmsResource resource)
    throws CmsException {

        return getContentDefinitionForResource(cms, resource).getContentHandler();
    }
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;
        }
    }