Loads the configuration file, using  CmsVfsMemoryObjectCache for caching.

@param cms the CMS context
@return the template mapper configuration
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
                    }

                }
            }));
    }
857961
public CmsResource createFolder(CmsObject cms) throws CmsException {

        if (m_folder != null) {
            return m_folder;
        }
        return cms.createResource(
            m_path,
            OpenCms.getResourceManager().getResourceType(CmsResourceTypeFolder.RESOURCE_TYPE_NAME).getTypeId());
    }
719960
protected CmsResource getResource(CmsObject cms, I_CmsWidgetParameter param) {

        I_CmsXmlContentValue value = (I_CmsXmlContentValue)param;
        CmsFile file = value.getDocument().getFile();
        String resourceName = cms.getSitePath(file);
        if (CmsWorkplace.isTemporaryFile(file)) {
            StringBuffer result = new StringBuffer(resourceName.length() + 2);
            result.append(CmsResource.getFolderPath(resourceName));
            result.append(CmsResource.getName(resourceName).substring(1));
            resourceName = result.toString();
        }
        try {
            List<CmsResource> listsib = cms.readSiblings(resourceName, CmsResourceFilter.ALL);
            for (int i = 0; i < listsib.size(); i++) {
                CmsResource resource = listsib.get(i);
                // get the default locale of the resource
                Locale locale = getDefaultLocale(cms, cms.getSitePath(resource));
                if (locale.equals(value.getLocale())) {
                    // get the property for the right locale
                    return resource;
                }
            }
        } catch (CmsVfsResourceNotFoundException e) {
            // may hapen if editing a new resource
            if (LOG.isDebugEnabled()) {
                LOG.debug(e.getLocalizedMessage(), e);
            }
        } catch (CmsException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return file;
    }
1023995
private Map<String, CmsDecorationObject> fillMap(CmsObject cms, CmsResource res) throws CmsException {

        if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get().getBundle().key(Messages.LOG_DECORATION_MAP_FILL_MAP_2, m_name, m_decoratorDefinition));
        }

        Map<String, CmsDecorationObject> decMap = new HashMap<String, CmsDecorationObject>();
        // upgrade the resource to get the file content
        CmsFile file = cms.readFile(res);
        // get all the entries
        String unparsedContent = new String(file.getContents());

        String delimiter = "\r\n";
        if (unparsedContent.indexOf(delimiter) == -1) {
            // there was no \r\n delimiter in the csv file, so check if the lines are seperated by
            // \n only
            if (unparsedContent.indexOf("\n") > -1) {
                delimiter = "\n";
            }
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get().getBundle().key(
                    Messages.LOG_DECORATION_MAP_FILL_MAP_DELIMITER_2,
                    res.getName(),
                    CmsStringUtil.escapeJavaScript(delimiter)));
        }

        List<String> entries = CmsStringUtil.splitAsList(unparsedContent, delimiter);

        if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get().getBundle().key(
                    Messages.LOG_DECORATION_MAP_FILL_MAP_SPLIT_LIST_2,
                    res.getName(),
                    entries));
        }
        Iterator<String> i = entries.iterator();
        while (i.hasNext()) {
            try {
                String entry = i.next();
                // extract key and value
                if (CmsStringUtil.isNotEmpty(entry)) {
                    int speratator = entry.indexOf(CSV_SEPERATOR);
                    if (speratator > -1) {
                        String key = entry.substring(0, speratator).trim();
                        String value = entry.substring(speratator + 1).trim();
                        if (CmsStringUtil.isNotEmpty(key) && CmsStringUtil.isNotEmpty(value)) {
                            CmsDecorationObject decObj = new CmsDecorationObject(
                                key,
                                value,
                                m_decoratorDefinition,
                                m_locale);
                            decMap.put(key, decObj);
                            if (LOG.isDebugEnabled()) {
                                LOG.debug(
                                    Messages.get().getBundle().key(
                                        Messages.LOG_DECORATION_MAP_ADD_DECORATION_OBJECT_2,
                                        decObj,
                                        key));
                            }
                        }
                    }
                }
            } catch (Exception e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(Messages.get().getBundle().key(Messages.LOG_DECORATION_MAP_FILL_2, m_name, e));
                }
            }
        }

        return decMap;
    }
1113595
public static CmsFlexBucketConfiguration loadFromVfsFile(CmsObject cms, String path) throws CmsException {

        if (!cms.existsResource(path)) {
            return null;
        }
        CmsResource configRes = cms.readResource(path);
        if (configRes.isFolder()) {
            return null;
        }
        CmsFile configFile = cms.readFile(configRes);
        String encoding = CmsFileUtil.getEncoding(cms, configRes);
        Properties props = new Properties();
        try {
            props.load(new InputStreamReader(new ByteArrayInputStream(configFile.getContents()), encoding));
            return loadFromProperties(props);
        } catch (IOException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
        return null;
    }
1155616
private static void setCache(CmsObject cms, CmsXmlContainerPage xmlCntPage, boolean keepEncoding) {

        if (xmlCntPage.getFile() instanceof I_CmsHistoryResource) {
            return;
        }
        boolean online = cms.getRequestContext().getCurrentProject().isOnlineProject();
        getCache().setCacheContainerPage(
            getCache().getCacheKey(xmlCntPage.getFile().getStructureId(), keepEncoding),
            xmlCntPage,
            online);
    }
346768
public CmsGroupContainerBean getGroupContainer(CmsObject cms) {

        if (m_groupContainers.containsKey(CmsLocaleManager.MASTER_LOCALE)) {
            return m_groupContainers.get(CmsLocaleManager.MASTER_LOCALE);
        } else if (!m_groupContainers.isEmpty()) {
            return m_groupContainers.get(m_groupContainers.keySet().iterator().next());
        } else {
            return null;
        }
    }
1034561
protected CmsFormatterConfiguration getFormatters(
        CmsObject cms,
        I_CmsResourceType resType,
        CmsFormatterConfiguration schemaFormatters) {

        String typeName = resType.getTypeName();
        CmsFormatterConfigurationCacheState formatterCacheState = getCachedFormatters();
        List<I_CmsFormatterBean> formatters = new ArrayList<I_CmsFormatterBean>();
        Set<String> types = new HashSet<String>();
        types.add(typeName);
        for (CmsFormatterChangeSet changeSet : getFormatterChangeSets()) {
            if (changeSet != null) {
                changeSet.applyToTypes(types);
            }
        }
        if ((schemaFormatters != null) && types.contains(typeName)) {
            for (I_CmsFormatterBean formatter : schemaFormatters.getAllFormatters()) {
                formatters.add(formatter);
            }

        }
        Map<CmsUUID, I_CmsFormatterBean> externalFormattersById = Maps.newHashMap();
        for (I_CmsFormatterBean formatter : formatterCacheState.getFormattersForType(typeName, true)) {
            externalFormattersById.put(new CmsUUID(formatter.getId()), formatter);
        }
        applyAllFormatterChanges(externalFormattersById, formatterCacheState);
        for (I_CmsFormatterBean formatter : externalFormattersById.values()) {
            if (formatter.getResourceTypeNames().contains(typeName)) {
                formatters.add(formatter);
            }
        }
        return CmsFormatterConfiguration.create(cms, formatters);
    }
30078
public static CmsADESessionCache getCache(HttpServletRequest request, CmsObject cms) {

        CmsADESessionCache cache = (CmsADESessionCache)request.getSession().getAttribute(
            CmsADESessionCache.SESSION_ATTR_ADE_CACHE);
        if (cache == null) {
            cache = new CmsADESessionCache(cms, request);
            request.getSession().setAttribute(CmsADESessionCache.SESSION_ATTR_ADE_CACHE, cache);
        }
        return cache;
    }
485265
public void initializeCms(CmsObject cms) {

        List<String> toRemove = new ArrayList<String>();
        // Repositories which can't be fully initialized need to be removed.
        for (I_CmsRepository repository : m_repositoryMap.values()) {
            String repoName = repository.getName();
            try {
                repository.initializeCms(cms);
            } catch (CmsException e) {
                LOG.warn("Could not fully initialize repository " + repoName, e);
                toRemove.add(repoName);
            }
        }
        for (String removeRepo : toRemove) {
            m_repositoryMap.remove(removeRepo);
        }
        m_hasJlan = !getRepositories(CmsJlanRepository.class).isEmpty();
        if (!CmsShell.isJlanDisabled() && m_hasJlan) {
            CmsJlanUsers.setAdminCms(cms);
            m_jlanThreadManager = new CmsJlanThreadManager();
            m_jlanThreadManager.start();
        }

    }
898031
public CmsResource getOrCreateFolder(CmsObject cms) throws CmsException {

        CmsResource result = getFolder(cms);
        if (result != null) {
            return result;
        }
        return createFolder(cms);
    }
1274597
public CmsXmlContainerPage getCacheContainerPage(String key, boolean online) {

        try {
            m_lock.readLock().lock();
            CmsXmlContainerPage retValue;
            if (online) {
                retValue = m_containerPagesOnline.get(key);
                if (LOG.isDebugEnabled()) {
                    if (retValue == null) {
                        LOG.debug(
                            Messages.get().getBundle().key(
                                Messages.LOG_DEBUG_CACHE_MISSED_ONLINE_1,
                                new Object[] {key}));

                    } else {
                        LOG.debug(
                            Messages.get().getBundle().key(
                                Messages.LOG_DEBUG_CACHE_MATCHED_ONLINE_2,
                                new Object[] {key, retValue}));
                    }
                }
            } else {
                retValue = m_containerPagesOffline.get(key);
                if (LOG.isDebugEnabled()) {
                    if (retValue == null) {
                        LOG.debug(
                            Messages.get().getBundle().key(
                                Messages.LOG_DEBUG_CACHE_MISSED_OFFLINE_1,
                                new Object[] {key}));

                    } else {
                        LOG.debug(
                            Messages.get().getBundle().key(
                                Messages.LOG_DEBUG_CACHE_MATCHED_OFFLINE_2,
                                new Object[] {key, retValue}));
                    }
                }
            }
            if (retValue != null) {
                //System.out.println("got cached page: " + retValue.getFile().getRootPath());
            }
            return retValue;
        } finally {
            m_lock.readLock().unlock();
        }
    }
132678
private List<CmsResource> getDecorationMapFiles(CmsObject cms) throws CmsException {

        List<CmsResource> files = new ArrayList<CmsResource>();

        // calcualte the basename for the decoration map files
        // the basename is the filename without the fileextension and any "_locale" postfixes
        // e.g. decoration_en.csv will generate "decoration" as basename
        StringBuffer baseFilename = new StringBuffer();
        baseFilename.append(CmsResource.getParentFolder(m_configurationFile));
        String filename = cms.readResource(m_configurationFile).getName();
        // get rid of the fileextension if there is one
        if (filename.lastIndexOf(".") > -1) {
            filename = filename.substring(0, filename.lastIndexOf("."));
        }
        // extract the basename
        if (filename.lastIndexOf("_") > -1) {
            filename = filename.substring(0, filename.lastIndexOf("_"));
        }
        baseFilename.append(filename);
        String basename = baseFilename.toString();

        // get all config files which belong to this basename
        int plainId;
        try {
            plainId = OpenCms.getResourceManager().getResourceType(
                CmsResourceTypePlain.getStaticTypeName()).getTypeId();
        } catch (CmsLoaderException e) {
            // this should really never happen
            plainId = CmsResourceTypePlain.getStaticTypeId();
        }
        List<CmsResource> resources = cms.readResources(
            CmsResource.getParentFolder(m_configurationFile),
            CmsResourceFilter.DEFAULT);
        Iterator<CmsResource> i = resources.iterator();
        while (i.hasNext()) {
            CmsResource res = i.next();
            if (cms.getSitePath(res).startsWith(basename) && (res.getTypeId() == plainId)) {
                files.add(res);
            }
        }

        return files;
    }
826582
protected void initLocalizationContent(String configurationFileName) {

        CmsObject cms = null;
        try {
            // this will always be in the root site
            cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
        } catch (CmsException e) {
            // error initializing cms object, log error
            if (LOG.isErrorEnabled()) {
                LOG.error(
                    Messages.get().getBundle().key(
                        Messages.ERR_INVALID_INIT_USER_1,
                        OpenCms.getDefaultUsers().getUserGuest()));
            }
        }
        if ((cms != null) && CmsStringUtil.isNotEmptyOrWhitespaceOnly(configurationFileName)) {
            // try to get XML content from cache
            Object o = CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().getCachedObject(cms, configurationFileName);
            if (o != null) {
                // found the cached XML content, use it
                m_localizationContent = (CmsXmlContent)o;
                return;
            }
            try {
                CmsFile configFile = cms.readFile(configurationFileName);
                m_localizationContent = CmsXmlContentFactory.unmarshal(cms, configFile);
                // store unmarshaled content in cache
                CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().putCachedObject(
                    cms,
                    configurationFileName,
                    m_localizationContent);
            } catch (CmsException e) {
                // ignore, no configuration file found
            }
        }
    }
1024646
public static CmsRemoteShellServer initialize(CmsSystemConfiguration systemConfiguration) {

        CmsRemoteShellServer result = null;

        if ((systemConfiguration.getShellServerOptions() != null)
            && systemConfiguration.getShellServerOptions().isEnabled()) {

            result = new CmsRemoteShellServer(systemConfiguration.getShellServerOptions().getPort());

            if (CmsLog.INIT.isInfoEnabled()) {
                CmsLog.INIT.info(
                    Messages.get().getBundle().key(Messages.INIT_REMOTESHELL_ENABLED_1, new Integer(result.m_port)));
            }

            result.initServer();
        } else {
            if (CmsLog.INIT.isInfoEnabled()) {
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_REMOTESHELL_DISABLED_0));
            }
        }

        return result;
    }
390618
public CmsPropertiesBean loadPropertyData(CmsUUID id) throws CmsException {

        CmsObject cms = m_cms;
        String originalSiteRoot = cms.getRequestContext().getSiteRoot();
        CmsPropertiesBean result = new CmsPropertiesBean();
        CmsResource resource = cms.readResource(id, CmsResourceFilter.IGNORE_EXPIRATION);
        result.setReadOnly(!isWritable(cms, resource));
        result.setFolder(resource.isFolder());
        result.setContainerPage(CmsResourceTypeXmlContainerPage.isContainerPage(resource));
        String sitePath = cms.getSitePath(resource);
        Map<String, CmsXmlContentProperty> propertyConfig = OpenCms.getADEManager().lookupConfiguration(
            cms,
            resource.getRootPath()).getPropertyConfigurationAsMap();
        Map<String, CmsXmlContentProperty> defaultProperties = getDefaultProperties(

            Collections.singletonList(resource.getStructureId())).get(resource.getStructureId());
        Map<String, CmsXmlContentProperty> mergedConfig = new LinkedHashMap<String, CmsXmlContentProperty>();
        mergedConfig.putAll(defaultProperties);
        mergedConfig.putAll(propertyConfig);
        propertyConfig = mergedConfig;

        // Resolve macros in the property configuration
        propertyConfig = CmsXmlContentPropertyHelper.resolveMacrosInProperties(
            propertyConfig,
            CmsMacroResolver.newWorkplaceLocaleResolver(cms));
        updateWysiwygConfig(propertyConfig, cms, resource);

        result.setPropertyDefinitions(new LinkedHashMap<String, CmsXmlContentProperty>(propertyConfig));
        try {
            cms.getRequestContext().setSiteRoot("");
            String parentPath = CmsResource.getParentFolder(resource.getRootPath());
            CmsResource parent = cms.readResource(parentPath, CmsResourceFilter.IGNORE_EXPIRATION);
            List<CmsProperty> parentProperties = cms.readPropertyObjects(parent, true);
            List<CmsProperty> ownProperties = cms.readPropertyObjects(resource, false);
            result.setOwnProperties(convertProperties(ownProperties));
            result.setInheritedProperties(convertProperties(parentProperties));
            result.setPageInfo(CmsVfsService.getPageInfo(cms, resource));
            List<CmsPropertyDefinition> propDefs = cms.readAllPropertyDefinitions();
            List<String> propNames = new ArrayList<String>();
            for (CmsPropertyDefinition propDef : propDefs) {
                propNames.add(propDef.getName());
            }
            CmsTemplateFinder templateFinder = new CmsTemplateFinder(cms);
            result.setTemplates(templateFinder.getTemplates());
            result.setAllProperties(propNames);
            result.setStructureId(id);
            result.setSitePath(sitePath);
            return result;
        } finally {
            cms.getRequestContext().setSiteRoot(originalSiteRoot);
        }
    }
692062
protected JSONObject getJSONConfiguration(CmsObject cms, CmsResource resource, Locale contentLocale) {

        return getJSONConfiguration(getHtmlWidgetOption(), cms, resource, contentLocale);
    }