Returns a bean representing the given template resource.<p>

@param cms the cms context to use for VFS operations
@param resource the template resource

@return bean representing the given template resource

@throws CmsException if something goes wrong
515542
private CmsClientTemplateBean getTemplateBean(CmsObject cms, CmsResource resource) throws CmsException {

        CmsProperty titleProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, false);
        CmsProperty descProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
        CmsProperty imageProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TEMPLATE_IMAGE, false);
        CmsProperty selectValueProp = cms.readPropertyObject(
            resource,
            CmsPropertyDefinition.PROPERTY_TEMPLATE_PROVIDER,
            false);
        String sitePath = cms.getSitePath(resource);
        String templateValue = sitePath;
        if (!selectValueProp.isNullProperty() && !CmsStringUtil.isEmptyOrWhitespaceOnly(selectValueProp.getValue())) {
            String selectValue = selectValueProp.getValue();
            CmsMacroResolver resolver = new CmsMacroResolver();
            resolver.addMacro(MACRO_TEMPLATEPATH, sitePath);
            templateValue = resolver.resolveMacros(selectValue);
        }
        return new CmsClientTemplateBean(
            titleProp.getValue(),
            descProp.getValue(),
            templateValue,
            imageProp.getValue());
    }
1465
protected CmsObject getCmsObject(CmsCmisCallContext context) {

        try {
            if (context.getUsername() == null) {
                // user name can be null
                CmsObject cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
                cms.getRequestContext().setCurrentProject(m_adminCms.getRequestContext().getCurrentProject());
                return cms;
            } else {
                CmsObject cms = OpenCms.initCmsObject(m_adminCms);
                CmsProject projectBeforeLogin = cms.getRequestContext().getCurrentProject();
                cms.loginUser(context.getUsername(), context.getPassword());
                cms.getRequestContext().setCurrentProject(projectBeforeLogin);
                return cms;
            }
        } catch (CmsException e) {
            throw new CmisPermissionDeniedException(e.getLocalizedMessage(), e);

        }
    }
941995
public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsIndexException, CmsException {

        logContentExtraction(resource, index);
        CmsFile file = readFile(cms, resource);
        try {
            return CmsExtractorPdf.getExtractor().extractText(file.getContents());
        } catch (Exception e) {
            if (e.getClass().getSimpleName().equals("EncryptedDocumentException")) {
                throw new CmsIndexException(
                    Messages.get().container(Messages.ERR_DECRYPTING_RESOURCE_1, resource.getRootPath()),
                    e);
            }
            if (e instanceof InvalidPasswordException) {
                // default password "" was wrong.
                throw new CmsIndexException(
                    Messages.get().container(Messages.ERR_PWD_PROTECTED_1, resource.getRootPath()),
                    e);
            }
            throw new CmsIndexException(
                Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()),
                e);
        }
    }
934058
public String renderSitemap() throws CmsException {

        StringBuffer buffer = new StringBuffer();
        List<CmsXmlSitemapUrlBean> urlBeans = generateSitemapBeans();
        buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        buffer.append(getUrlSetOpenTag() + "\n");
        for (CmsXmlSitemapUrlBean bean : urlBeans) {
            buffer.append(getXmlForEntry(bean));
            buffer.append("\n");
        }
        buffer.append("</urlset>");
        return buffer.toString();
    }
580437
public static List<CmsContainerElementBean> loadInheritContainerElements(CmsObject cms, CmsResource resource) {

        CmsInheritanceReferenceParser parser = new CmsInheritanceReferenceParser(cms);
        try {
            parser.parse(resource);
            CmsInheritanceReference ref = parser.getReference(cms.getRequestContext().getLocale());
            if (ref != null) {
                String name = ref.getName();
                CmsADEManager adeManager = OpenCms.getADEManager();
                CmsInheritedContainerState result = adeManager.getInheritedContainerState(
                    cms,
                    cms.getRequestContext().getRootUri(),
                    name);
                return result.getElements(false);
            }
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
        return Collections.emptyList();
    }
742694
public CmsLock getLock(CmsDbContext dbc, CmsResource resource) throws CmsException {

        return m_lockManager.getLock(dbc, resource);
    }
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
                    }

                }
            }));
    }
837386
private CmsResource readResource(String resourceName) throws CmsException {

        CmsResource resource = null;
        try {
            resource = getCms().readResource(resourceName, CmsResourceFilter.ALL);
        } catch (CmsVfsResourceNotFoundException e) {
            throw new CmsVfsResourceNotFoundException(
                Messages.get().container(
                    Messages.ERR_RESOURCE_DOES_NOT_EXIST_3,
                    resourceName,
                    getCms().getRequestContext().getCurrentProject().getName(),
                    getCms().getRequestContext().getSiteRoot()),
                e);
        }
        return resource;
    }
635366
public static boolean isXmlContent(CmsResource resource) {

        boolean result = false;
        if (resource != null) {
            // avoid array index out of bound exception:
            if (!resource.isFolder()) {
                result = OpenCms.getResourceManager().getResourceType(resource) instanceof CmsResourceTypeXmlContent;
            }
        }
        return result;
    }
940822
protected Locale getDefaultLocale(CmsObject cms, String resource) {

        Locale locale = OpenCms.getLocaleManager().getDefaultLocale(cms, resource);
        if (locale == null) {
            List<Locale> locales = OpenCms.getLocaleManager().getAvailableLocales();
            if (locales.size() > 0) {
                locale = locales.get(0);
            } else {
                locale = Locale.ENGLISH;
            }
        }
        return locale;
    }
1374368
protected CmsObject getSearchCms(CmsGallerySearchBean searchObj) throws CmsException {

        CmsObject searchCms = getCmsObject();
        if (searchObj.isIncludeExpired()) {
            searchCms = OpenCms.initCmsObject(getCmsObject());
            searchCms.getRequestContext().setRequestTime(CmsResource.DATE_RELEASED_EXPIRED_IGNORE);
        }
        return searchCms;
    }
437291
public void parse(CmsResource resource) throws CmsException {

        CmsFile file = m_cms.readFile(resource);
        m_resource = resource;
        CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file);
        parse(content);
    }
889936
public CmsRelationFilter filterResource(CmsResource resource) {

        CmsRelationFilter filter = filterStructureId(resource.getStructureId());
        filter = filterPath(resource.getRootPath());
        return filter;
    }
1093813
public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsIndexException, CmsException {

        logContentExtraction(resource, index);
        CmsFile file = readFile(cms, resource);
        try {
            return CmsExtractorMsOfficeOLE2.getExtractor().extractText(file.getContents());
        } catch (Throwable e) {
            throw new CmsIndexException(
                Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()),
                e);
        }
    }
125276
protected CmsBrokenLinkBean createSitemapBrokenLinkBean(CmsResource resource) throws CmsException {

        CmsProperty titleProp = m_cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, true);
        String typeName = OpenCms.getResourceManager().getResourceType(resource).getTypeName();
        String defaultTitle = CmsResource.getName(resource.getRootPath());
        String title = titleProp.getValue(defaultTitle);
        String path = m_cms.getSitePath(resource);
        String subtitle = path;
        return new CmsBrokenLinkBean(resource.getStructureId(), title, subtitle, typeName);
    }
749135
protected CmsPublishResource createPublishResource(CmsResource resource) throws CmsException {

        CmsResourceUtil resUtil = new CmsResourceUtil(m_cms, resource);
        CmsPermissionInfo permissionInfo = OpenCms.getADEManager().getPermissionInfo(m_cms, resource, null);

        String typeName = CmsIconUtil.getDisplayType(m_cms, resource);
        String detailTypeName = CmsResourceIcon.getDefaultFileOrDetailType(m_cms, resource);
        CmsPublishResource pubResource = new CmsPublishResource(
            resource.getStructureId(),
            resUtil.getFullPath(),
            resUtil.getTitle(),
            typeName,
            resource.getState(),
            permissionInfo,
            resource.getDateLastModified(),
            resUtil.getUserLastModified(),
            CmsVfsService.formatDateTime(m_cms, resource.getDateLastModified()),
            false,
            null,
            new ArrayList<CmsPublishResource>());
        pubResource.setBigIconClasses(CmsIconUtil.getIconClasses(typeName, resource.getName(), false));
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(detailTypeName)) {
            pubResource.setSmallIconClasses(CmsIconUtil.getIconClasses(detailTypeName, null, true));
        }
        return pubResource;
    }
681008
private static List<CmsCategory> getCategories(CmsObject cms, CmsResource resource) {

        if ((null != resource) && (null != cms)) {
            try {
                return CmsCategoryService.getInstance().readResourceCategories(cms, resource);
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return new ArrayList<CmsCategory>(0);
    }