Initializes the OpenCms scheduler.<p>

@param adminCms an OpenCms context object that must have been initialized with "Admin" permissions

@throws CmsRoleViolationException if the user has insufficient role permissions
162105
public synchronized void initialize(CmsObject adminCms) throws CmsRoleViolationException {

        if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_1_CORE_OBJECT) {
            // simple unit tests will have runlevel 1 and no CmsObject
            OpenCms.getRoleManager().checkRole(adminCms, CmsRole.WORKPLACE_MANAGER);
        }

        // the list of job entries
        m_jobs = new ArrayList<CmsScheduledJobInfo>();

        // save the admin cms
        m_adminCms = adminCms;

        // Quartz scheduler settings
        Properties properties = new Properties();
        properties.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "OpenCmsScheduler");
        properties.put(StdSchedulerFactory.PROP_SCHED_THREAD_NAME, "OpenCms: Scheduler");
        properties.put(StdSchedulerFactory.PROP_SCHED_RMI_EXPORT, CmsStringUtil.FALSE);
        properties.put(StdSchedulerFactory.PROP_SCHED_RMI_PROXY, CmsStringUtil.FALSE);
        properties.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, CmsSchedulerThreadPool.class.getName());
        properties.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, "org.quartz.simpl.RAMJobStore");
        // this will be required in quartz versions from 1.6, but constants are not supported in earlier versions
        properties.put("org.quartz.scheduler.jmx.export", CmsStringUtil.FALSE);
        properties.put("org.quartz.scheduler.jmx.proxy", CmsStringUtil.FALSE);

        try {
            // initialize the Quartz scheduler
            SchedulerFactory schedulerFactory = new StdSchedulerFactory(properties);
            m_scheduler = schedulerFactory.getScheduler();
        } catch (Exception e) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_NO_SCHEDULER_0), e);
            // can not continue
            m_scheduler = null;
            return;
        }

        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SCHEDULER_INITIALIZED_0));
        }

        if (m_configuredJobs != null) {
            // add all jobs from the system configuration
            for (int i = 0; i < m_configuredJobs.size(); i++) {
                try {
                    CmsScheduledJobInfo job = m_configuredJobs.get(i);
                    scheduleJob(adminCms, job);
                } catch (CmsSchedulerException e) {
                    // ignore this job, but keep scheduling the other jobs
                    // note: the log is has already been written
                }
            }
        }

        try {
            // start the scheduler
            m_scheduler.start();
        } catch (Exception e) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_CANNOT_START_SCHEDULER_0), e);
            // can not continue
            m_scheduler = null;
            return;
        }

        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SCHEDULER_STARTED_0));
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SCHEDULER_CONFIG_FINISHED_0));
        }
    }
357036
public synchronized void initialize() {

        // no need to try initialization in case the 'org.opencms.base' is not present and the contained resource types missing
        if ((m_initStatus == Status.notInitialized) && OpenCms.getModuleManager().hasModule(MODULE_NAME_ADE_CONFIG)) {
            try {
                CmsLog.INIT.info(". Initializing the ADE configuration, this may take a while...");
                m_initStatus = Status.initializing;
                m_configType = OpenCms.getResourceManager().getResourceType(CONFIG_TYPE);
                m_moduleConfigType = OpenCms.getResourceManager().getResourceType(MODULE_CONFIG_TYPE);
                m_elementViewType = OpenCms.getResourceManager().getResourceType(ELEMENT_VIEW_TYPE);
                CmsProject temp = getTempfileProject(m_onlineCms);
                m_offlineCms = OpenCms.initCmsObject(m_onlineCms);
                m_offlineCms.getRequestContext().setCurrentProject(temp);
                m_onlineCache = new CmsConfigurationCache(
                    m_onlineCms,
                    m_configType,
                    m_moduleConfigType,
                    m_elementViewType);
                m_offlineCache = new CmsConfigurationCache(
                    m_offlineCms,
                    m_configType,
                    m_moduleConfigType,
                    m_elementViewType);
                CmsLog.INIT.info(". Reading online configuration...");
                m_onlineCache.initialize();
                CmsLog.INIT.info(". Reading offline configuration...");
                m_offlineCache.initialize();
                m_onlineContainerConfigurationCache = new CmsContainerConfigurationCache(
                    m_onlineCms,
                    "online inheritance groups");
                m_offlineContainerConfigurationCache = new CmsContainerConfigurationCache(
                    m_offlineCms,
                    "offline inheritance groups");
                CmsLog.INIT.info(". Reading online inherited container configurations...");
                m_onlineContainerConfigurationCache.initialize();
                CmsLog.INIT.info(". Reading offline inherited container configurations...");
                m_offlineContainerConfigurationCache.initialize();
                m_offlineFormatterCache = new CmsFormatterConfigurationCache(m_offlineCms, "offline formatters");
                m_onlineFormatterCache = new CmsFormatterConfigurationCache(m_onlineCms, "online formatters");
                CmsLog.INIT.info(". Reading online formatter configurations...");
                m_onlineFormatterCache.initialize();
                CmsLog.INIT.info(". Reading offline formatter configurations...");
                m_offlineFormatterCache.initialize();

                m_offlineDetailIdCache = new CmsDetailNameCache(m_offlineCms);
                m_onlineDetailIdCache = new CmsDetailNameCache(m_onlineCms);
                CmsLog.INIT.info(". Initializing online detail name cache...");
                m_onlineDetailIdCache.initialize();
                CmsLog.INIT.info(". Initializing offline detail name cache...");
                m_offlineDetailIdCache.initialize();

                CmsGlobalConfigurationCacheEventHandler handler = new CmsGlobalConfigurationCacheEventHandler(
                    m_onlineCms);
                handler.addCache(m_offlineCache, m_onlineCache, "ADE configuration cache");
                handler.addCache(
                    m_offlineContainerConfigurationCache,
                    m_onlineContainerConfigurationCache,
                    "Inherited container cache");
                handler.addCache(m_offlineFormatterCache, m_onlineFormatterCache, "formatter configuration cache");
                handler.addCache(m_offlineDetailIdCache, m_onlineDetailIdCache, "Detail ID cache");
                OpenCms.getEventManager().addCmsEventListener(handler);
                CmsLog.INIT.info(". Done initializing the ADE configuration.");
                m_initStatus = Status.initialized;
            } catch (CmsException e) {
                m_initStatus = Status.notInitialized;
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
    }
373881
public void initialize(CmsObject cms) {

        m_adminCms = cms;
        // initialize static export RFS path (relative to web application)
        m_staticExportPath = normalizeExportPath(m_staticExportPathConfigured);
        m_staticExportWorkPath = normalizeExportPath(getExportWorkPathForConfiguration());
        if (m_staticExportPath.equals(OpenCms.getSystemInfo().getWebApplicationRfsPath())) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_INVALID_EXPORT_PATH_0));
        }
        // initialize prefix variables
        m_rfsPrefix = normalizeRfsPrefix(m_rfsPrefixConfigured);
        Iterator<CmsStaticExportRfsRule> itRfsRules = m_rfsRules.iterator();
        while (itRfsRules.hasNext()) {
            CmsStaticExportRfsRule rule = itRfsRules.next();
            try {
                rule.setExportPath(normalizeExportPath(rule.getExportPathConfigured()));
            } catch (CmsIllegalArgumentException e) {
                CmsLog.INIT.warn(e.getMessageContainer());
                rule.setExportPath(m_staticExportPath);
            }
            try {
                rule.setExportWorkPath(normalizeExportPath(rule.getExportWorkPathConfigured()));
            } catch (CmsIllegalArgumentException e) {
                CmsLog.INIT.warn(e.getMessageContainer());
                rule.setExportWorkPath(m_staticExportWorkPath);
            }
            rule.setRfsPrefix(normalizeRfsPrefix(rule.getRfsPrefixConfigured()));
        }
        m_vfsPrefix = insertContextStrings(m_vfsPrefixConfigured);
        m_vfsPrefix = CmsFileUtil.normalizePath(m_vfsPrefix, '/');
        if (CmsResource.isFolder(m_vfsPrefix)) {
            // ensure prefix does NOT end with a folder '/'
            m_vfsPrefix = m_vfsPrefix.substring(0, m_vfsPrefix.length() - 1);
        }
        if (CmsLog.INIT.isDebugEnabled()) {
            if (cms != null) {
                CmsLog.INIT.debug(Messages.get().getBundle().key(Messages.INIT_SE_MANAGER_CREATED_1, cms));
            } else {
                CmsLog.INIT.debug(Messages.get().getBundle().key(Messages.INIT_SE_MANAGER_CREATED_0));
            }
        }

        m_cacheOnlineLinks = CmsMemoryMonitor.createLRUCacheMap(2048);
        OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_cacheOnlineLinks", m_cacheOnlineLinks);

        m_cacheExportUris = CmsMemoryMonitor.createLRUCacheMap(2048);
        OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_cacheExportUris", m_cacheExportUris);

        m_cacheSecureLinks = CmsMemoryMonitor.createLRUCacheMap(2048);
        OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_cacheSecureLinks", m_cacheSecureLinks);

        m_cacheExportLinks = CmsMemoryMonitor.createLRUCacheMap(2048);
        OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_cacheExportLinks", m_cacheExportLinks);

        // register this object as event listener
        OpenCms.addCmsEventListener(
            this,
            new int[] {
                I_CmsEventListener.EVENT_PUBLISH_PROJECT,
                I_CmsEventListener.EVENT_CLEAR_CACHES,
                I_CmsEventListener.EVENT_UPDATE_EXPORTS});

        m_exportFolderMatcher = new CmsExportFolderMatcher(m_exportFolders, m_testResource);

        // get the default accept-language header value
        m_defaultAcceptLanguageHeader = CmsAcceptLanguageHeaderParser.createLanguageHeader();

        // get the default accept-charset header value
        m_defaultAcceptCharsetHeader = OpenCms.getSystemInfo().getDefaultEncoding();

        // get the export url prefix
        int pos = m_exportUrl.indexOf("://");
        if (pos > 0) {
            // absolute link, remove http://servername
            int pos2 = m_exportUrl.indexOf('/', pos + 3);
            if (pos2 > 0) {
                m_exportUrlPrefix = m_exportUrl.substring(pos2);
            } else {
                // should never happen
                m_exportUrlPrefix = "";
            }
        } else {
            m_exportUrlPrefix = m_exportUrl;
        }
        if (CmsLog.INIT.isInfoEnabled()) {
            if (isStaticExportEnabled()) {
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_STATIC_EXPORT_ENABLED_0));
                CmsLog.INIT.info(
                    Messages.get().getBundle().key(
                        Messages.INIT_EXPORT_DEFAULT_1,
                        Boolean.valueOf(getExportPropertyDefault())));
                itRfsRules = m_rfsRules.iterator();
                while (itRfsRules.hasNext()) {
                    CmsStaticExportRfsRule rfsRule = itRfsRules.next();
                    CmsLog.INIT.info(
                        Messages.get().getBundle().key(
                            Messages.INIT_EXPORT_RFS_RULE_EXPORT_PATH_2,
                            rfsRule.getSource(),
                            rfsRule.getExportPath()));
                    CmsLog.INIT.info(
                        Messages.get().getBundle().key(
                            Messages.INIT_EXPORT_RFS_RULE_RFS_PREFIX_2,
                            rfsRule.getSource(),
                            rfsRule.getRfsPrefix()));
                    if (rfsRule.getUseRelativeLinks() != null) {
                        if (rfsRule.getUseRelativeLinks().booleanValue()) {
                            CmsLog.INIT.info(
                                Messages.get().getBundle().key(
                                    Messages.INIT_EXPORT_RFS_RULE_RELATIVE_LINKS_1,
                                    rfsRule.getSource()));
                        } else {
                            CmsLog.INIT.info(
                                Messages.get().getBundle().key(
                                    Messages.INIT_EXPORT_RFS_RULE_ABSOLUTE_LINKS_1,
                                    rfsRule.getSource()));
                        }
                    }
                }
                // default rule
                CmsLog.INIT.info(
                    Messages.get().getBundle().key(
                        Messages.INIT_EXPORT_RFS_RULE_EXPORT_PATH_2,
                        "/",
                        m_staticExportPath));
                CmsLog.INIT.info(
                    Messages.get().getBundle().key(Messages.INIT_EXPORT_RFS_RULE_RFS_PREFIX_2, "/", m_rfsPrefix));
                if (m_exportRelativeLinks) {
                    CmsLog.INIT.info(
                        Messages.get().getBundle().key(Messages.INIT_EXPORT_RFS_RULE_RELATIVE_LINKS_1, "/"));
                } else {
                    CmsLog.INIT.info(
                        Messages.get().getBundle().key(Messages.INIT_EXPORT_RFS_RULE_ABSOLUTE_LINKS_1, "/"));
                }
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_EXPORT_VFS_PREFIX_1, getVfsPrefix()));
                CmsLog.INIT.info(
                    Messages.get().getBundle().key(
                        Messages.INIT_EXPORT_EXPORT_HANDLER_1,
                        getHandler().getClass().getName()));
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_EXPORT_URL_1, getExportUrl()));
                CmsLog.INIT.info(
                    Messages.get().getBundle().key(Messages.INIT_EXPORT_OPTIMIZATION_1, getPlainExportOptimization()));
                CmsLog.INIT.info(
                    Messages.get().getBundle().key(Messages.INIT_EXPORT_TESTRESOURCE_1, getTestResource()));
                CmsLog.INIT.info(
                    Messages.get().getBundle().key(
                        Messages.INIT_LINKSUBSTITUTION_HANDLER_1,
                        getLinkSubstitutionHandler().getClass().getName()));
            } else {
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_STATIC_EXPORT_DISABLED_0));
            }
        }
    }
91915
protected void initializeForm() {

        String target = CmsSitemapView.getInstance().getController().getData().getAliasImportUrl();
        m_formPanel.setAction(target);
        m_formPanel.setMethod(FormPanel.METHOD_POST);
        m_formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
        Hidden siteRootField = new Hidden(I_CmsAliasConstants.PARAM_SITEROOT);
        siteRootField.setValue(CmsCoreProvider.get().getSiteRoot());
        m_formPanelContents.add(siteRootField);
        m_formPanelContents.add(m_separatorField);
        m_formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

            public void onSubmitComplete(SubmitCompleteEvent event) {

                final String formPostResults = event.getResults();
                final I_CmsSitemapServiceAsync service = CmsSitemapView.getInstance().getController().getService();
                CmsRpcAction<List<CmsAliasImportResult>> action = new CmsRpcAction<List<CmsAliasImportResult>>() {

                    @Override
                    public void execute() {

                        start(200, false);
                        service.getAliasImportResult(formPostResults.trim(), this);
                    }

                    @Override
                    public void onResponse(List<CmsAliasImportResult> result) {

                        stop(false);
                        handleImportResults(result);
                        Timer resizeTimer = new Timer() {

                            @Override
                            public void run() {

                                m_scrollPanel.onResizeDescendant();
                            }
                        };
                        resizeTimer.schedule(100);
                    }
                };
                action.execute();
            }
        });
    }
221606
public static void initialize(CmsObject cms) throws CmsException {

        OpenCms.getRoleManager().checkRole(cms, CmsRole.ADMINISTRATOR);
        try {
            // store the Admin cms to index Cms resources
            m_adminCms = OpenCms.initCmsObject(cms);
            m_adminCms.getRequestContext().setSiteRoot("");
        } catch (CmsException e) {
            // this should never happen
        }
    }
1033573
@Override
    public void actionCommit() {

        List<Throwable> errors = new ArrayList<Throwable>();

        try {
            // set the edited settings
            OpenCms.getWorkplaceManager().setFileViewSettings(getCms(), m_logView);
            // write the configuration
            OpenCms.writeConfiguration(CmsWorkplaceConfiguration.class);
            setDialogObject(null);
        } catch (Throwable t) {
            errors.add(t);
        }

        // set the list of errors to display when saving failed
        setCommitErrors(errors);
    }
1338235
protected void initMembers() {

        synchronized (LOCK) {
            m_resourceInitHandlers = new ArrayList<I_CmsResourceInit>();
            m_requestHandlers = new HashMap<String, I_CmsRequestHandler>();
            m_systemInfo = new CmsSystemInfo();
            m_exportPoints = Collections.emptySet();
            m_defaultUsers = new CmsDefaultUsers();
            m_localeManager = new CmsLocaleManager(Locale.ENGLISH);
            m_sessionManager = new CmsSessionManager();
            m_runtimeProperties = new Hashtable<Object, Object>();
            // the default event manager must be available because the configuration already registers events
            m_eventManager = new CmsEventManager();
            // default link manager is required for test cases
            m_linkManager = new CmsLinkManager(new CmsDefaultLinkSubstitutionHandler());
        }
    }
936772
public void init(CmsObject cms, Locale locale, I_CmsXmlDocument content, CmsResource resource) {

        m_cms = cms;
        m_requestedLocale = locale;
        m_content = content;
        m_resource = resource;
    }
818082
public void setLoginMessage(String messageText, boolean loginDisabled) throws CmsRoleViolationException {

        CmsLoginMessage message = new CmsLoginMessage(0, 0, messageText, loginDisabled);
        OpenCms.getLoginManager().setLoginMessage(m_cms, message);
        OpenCms.writeConfiguration(CmsVariablesConfiguration.class);
    }
785677
private void initPropertyBundle() throws CmsLoaderException, CmsException, IOException {

        for (Locale l : m_locales) {
            String filePath = m_sitepath + m_basename + "_" + l.toString();
            CmsResource resource = null;
            if (m_cms.existsResource(
                filePath,
                CmsResourceFilter.requireType(
                    OpenCms.getResourceManager().getResourceType(BundleType.PROPERTY.toString())))) {
                resource = m_cms.readResource(filePath);
                SortedProperties props = new SortedProperties();
                CmsFile file = m_cms.readFile(resource);
                props.load(
                    new InputStreamReader(
                        new ByteArrayInputStream(file.getContents()),
                        CmsFileUtil.getEncoding(m_cms, file)));
                m_keyset.updateKeySet(null, props.keySet());
                m_bundleFiles.put(l, resource);
            }
        }

    }
640875
public void submit(CmsUser user, CmsObject cms, Runnable afterWrite, boolean force) {

        try {
            if (isValid() | force) {
                if (force) {
                    removeValidators();
                }
                m_binder.commit();
                PropertyUtilsBean propUtils = new PropertyUtilsBean();
                for (CmsAccountInfo info : OpenCms.getWorkplaceManager().getAccountInfos()) {
                    boolean editable = (m_editLevel == EditLevel.all)
                        || ((m_editLevel == EditLevel.configured) && info.isEditable());
                    if (editable) {
                        if (info.isAdditionalInfo()) {
                            user.setAdditionalInfo(info.getAddInfoKey(), m_infos.getItemProperty(info).getValue());
                        } else {
                            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(
                                (String)m_infos.getItemProperty(info).getValue())) {
                                propUtils.setProperty(
                                    user,
                                    info.getField().name(),
                                    m_infos.getItemProperty(info).getValue());
                            }
                        }
                    }
                }
                cms.writeUser(user);
                afterWrite.run();
            }
        } catch (CmsException | CommitException | IllegalAccessException | InvocationTargetException
        | NoSuchMethodException e) {
            LOG.error("Unable to commit changes to user..", e);
        }
    }
842103
private String createConfiguration() {

        CmsResourceManager resManager = OpenCms.getResourceManager();
        if (resManager == null) {
            // can happen during the OpenCms startup
            return "";
        }
        List<I_CmsResourceType> resTypes = resManager.getResourceTypes();
        List<String> options = new ArrayList<String>();
        for (I_CmsResourceType resType : resTypes) {
            if (resType.isDirectEditable()) {
                options.add(resType.getTypeName());
            }
        }
        Collections.sort(options);
        return Joiner.on("|").join(options);
    }
1351674
public void start() {

        if (m_writeHtml) {
            try {
                m_printStream.println(
                    CmsWorkplace.generatePageStartExtended(
                        OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()),
                        OpenCms.getSystemInfo().getDefaultEncoding()));
            } catch (CmsException e) {
                // ignore
            }
        }
    }
901454
@Override
    public void init(String webAppRfsPath, String servletMapping, String defaultWebApplication) {

        try {
            super.init(webAppRfsPath, servletMapping, defaultWebApplication);
            CmsUpdateInfo.INSTANCE.setAdeModuleVersion(getInstalledModules().get("org.opencms.ade.containerpage"));

            if (m_workplaceUpdateThread != null) {
                if (m_workplaceUpdateThread.isAlive()) {
                    m_workplaceUpdateThread.kill();
                }
                m_workplaceUpdateThread = null;
            }
            if (m_dbUpdateThread != null) {
                if (m_dbUpdateThread.isAlive()) {
                    m_dbUpdateThread.kill();
                }
                m_dbUpdateThread = null;
                m_newLoggingOffset = 0;
                m_oldLoggingOffset = 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
85310
public void setEditorModeInSession(final EditorMode editorMode) {

        CmsRpcAction<Void> action = new CmsRpcAction<Void>() {

            @Override
            public void execute() {

                getService().setEditorMode(editorMode, this);
            }

            @Override
            protected void onResponse(Void result) {

                // nothing to do

            }
        };
        action.execute();
    }
1337510
private CmsObject initCms(CmsObject cms) {

        try {
            cms = OpenCms.initCmsObject(cms);
        } catch (CmsException e) {
            LOG.error("Unable to init CmsObject");
        }
        cms.getRequestContext().setSiteRoot("");
        return cms;
    }
1228613
protected void setupCms(CmsObject cms) {

        cms.getRequestContext().setUri("/");
        cms.getRequestContext().setSiteRoot((String)m_site.getValue());
        try {
            cms.getRequestContext().setCurrentProject(cms.readProject((CmsUUID)m_project.getValue()));
        } catch (CmsException e) {
            LOG.error("Unable to read Project", e);
        }
    }