001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.main;
029
030import org.opencms.ade.configuration.CmsADEManager;
031import org.opencms.cache.CmsVfsMemoryObjectCache;
032import org.opencms.crypto.I_CmsTextEncryption;
033import org.opencms.db.CmsAliasManager;
034import org.opencms.db.CmsDefaultUsers;
035import org.opencms.db.CmsExportPoint;
036import org.opencms.db.CmsLoginManager;
037import org.opencms.db.CmsSqlManager;
038import org.opencms.db.CmsSubscriptionManager;
039import org.opencms.file.CmsObject;
040import org.opencms.file.CmsResource;
041import org.opencms.file.quota.CmsFolderSizeTracker;
042import org.opencms.flex.CmsFlexCache;
043import org.opencms.i18n.CmsLocaleManager;
044import org.opencms.importexport.CmsImportExportManager;
045import org.opencms.jsp.userdata.CmsUserDataRequestManager;
046import org.opencms.letsencrypt.CmsLetsEncryptConfiguration;
047import org.opencms.loader.CmsResourceManager;
048import org.opencms.loader.CmsTemplateContextManager;
049import org.opencms.module.CmsModuleManager;
050import org.opencms.monitor.CmsMemoryMonitor;
051import org.opencms.publish.CmsPublishManager;
052import org.opencms.repository.CmsRepositoryManager;
053import org.opencms.scheduler.CmsScheduleManager;
054import org.opencms.search.CmsSearchManager;
055import org.opencms.security.CmsOrgUnitManager;
056import org.opencms.security.CmsRole;
057import org.opencms.security.CmsRoleManager;
058import org.opencms.security.I_CmsAuthorizationHandler;
059import org.opencms.security.I_CmsCredentialsResolver;
060import org.opencms.security.I_CmsPasswordHandler;
061import org.opencms.security.I_CmsValidationHandler;
062import org.opencms.security.twofactor.CmsTwoFactorAuthenticationHandler;
063import org.opencms.site.CmsSiteManagerImpl;
064import org.opencms.staticexport.CmsLinkManager;
065import org.opencms.staticexport.CmsStaticExportManager;
066import org.opencms.ui.apps.CmsWorkplaceAppManager;
067import org.opencms.workflow.I_CmsWorkflowManager;
068import org.opencms.workplace.CmsWorkplaceManager;
069import org.opencms.xml.CmsXmlContentTypeManager;
070import org.opencms.xml.xml2json.I_CmsApiAuthorizationHandler;
071
072import java.util.List;
073import java.util.Map;
074import java.util.Set;
075import java.util.concurrent.ScheduledThreadPoolExecutor;
076
077import javax.servlet.http.HttpServletRequest;
078import javax.servlet.http.HttpServletResponse;
079
080import org.apache.commons.logging.Log;
081
082/**
083 * The OpenCms "operating system" that provides
084 * public static methods which can be used by other classes to access
085 * basic system features of OpenCms like logging etc.<p>
086 *
087 * This Object provides singleton access to the initialized OpenCms runtime system.
088 * Some methods are for internal or advanced use only, but others are of also of interest
089 * for general OpenCms development.<p>
090 *
091 * For example, to generate a new instance of <code>{@link org.opencms.file.CmsObject}</code> class in your application,
092 * use <code>{@link org.opencms.main.OpenCms#initCmsObject(String)}</code>. The argument String should be
093 * the name of the guest user, usually "Guest" and more formally obtained by <code>{@link org.opencms.db.CmsDefaultUsers#getUserGuest()}</code>.
094 * This will give you an initialized context with guest user permissions.
095 * Then use <code>{@link CmsObject#loginUser(String, String)}</code> to log in the user you want.
096 * Obviously you need the password for the new user.<p>
097 *
098 * Using <code>{@link #getSiteManager()}</code> you can obtain the initialized <code>{@link org.opencms.site.CmsSiteManagerImpl}</code>
099 * which provides information about the sites configured in the running OpenCms instance.<p>
100 *
101 * The <code>{@link org.opencms.db.CmsDefaultUsers}</code> instance returned by <code>{@link #getDefaultUsers()}</code>
102 * provides information about the names of the OpenCms default users.<p>
103 *
104 * Other objects of note that can be obtained by this class include the <code>{@link org.opencms.module.CmsModuleManager}</code>
105 * or the <code>{@link org.opencms.scheduler.CmsScheduleManager}</code>.<p>
106 *
107 * When using the instances returned by this object, keep in mind that applying changes to these may alter the basic OpenCms
108 * system configuration, which in turn may affect the systems performance or stability.<p>
109 *
110 * @since 6.0.0
111 */
112public final class OpenCms {
113
114    /** Runlevel 0: System is offline. */
115    public static final int RUNLEVEL_0_OFFLINE = 0;
116
117    /** Runlevel 1: Core object created, no database (some test cases run in this level). */
118    public static final int RUNLEVEL_1_CORE_OBJECT = 1;
119
120    /** Runlevel 2: Initializing the system, required since this may take some seconds because of database connections. */
121    public static final int RUNLEVEL_2_INITIALIZING = 2;
122
123    /** Runlevel 3: Shell access to the database possible, but no servlet context available. */
124    public static final int RUNLEVEL_3_SHELL_ACCESS = 3;
125
126    /** Runlevel 4: Final runlevel where database and servlet are initialized. */
127    public static final int RUNLEVEL_4_SERVLET_ACCESS = 4;
128
129    /**
130     * The public contructor is hidden to prevent generation of instances of this class.<p>
131     */
132    private OpenCms() {
133
134        // empty
135    }
136
137    /**
138     * Add a cms event listener that listens to all events.<p>
139     *
140     * @param listener the listener to add
141     */
142    public static void addCmsEventListener(I_CmsEventListener listener) {
143
144        OpenCmsCore.getInstance().getEventManager().addCmsEventListener(listener);
145    }
146
147    /**
148     * Add a cms event listener that listens only to particular events.<p>
149     *
150     * @param listener the listener to add
151     * @param eventTypes the events to listen for
152     */
153    public static void addCmsEventListener(I_CmsEventListener listener, int[] eventTypes) {
154
155        OpenCmsCore.getInstance().getEventManager().addCmsEventListener(listener, eventTypes);
156    }
157
158    /**
159     * Notify all event listeners that a particular event has occurred.<p>
160     *
161     * @param event a CmsEvent
162     */
163    public static void fireCmsEvent(CmsEvent event) {
164
165        OpenCmsCore.getInstance().getEventManager().fireEvent(event);
166    }
167
168    /**
169     * Notify all event listeners that a particular event has occurred.<p>
170     *
171     * The event will be given to all registered <code>{@link I_CmsEventListener}</code> objects.<p>
172     *
173     * @param type event type
174     * @param data event data
175     */
176    public static void fireCmsEvent(int type, Map<String, Object> data) {
177
178        OpenCmsCore.getInstance().getEventManager().fireEvent(type, data);
179    }
180
181    /**
182     * Gets the initialized ADE manager.<p>
183     *
184     * @return the initialized ADE manager
185     */
186    public static CmsADEManager getADEManager() {
187
188        return OpenCmsCore.getInstance().getADEManager();
189    }
190
191    /**
192     * Gets the alias manager.<p>
193     *
194     * @return the alias manager
195     */
196    public static CmsAliasManager getAliasManager() {
197
198        return OpenCmsCore.getInstance().getAliasManager();
199    }
200
201    /**
202     * Gets the API authorization handler with the given name.
203     *
204     * <p>Returns null if there is no API authorization handler with that name.
205     *
206     * @param name the name of the API authorization handler
207     *
208     * @return an API authorization handler
209     */
210    public static I_CmsApiAuthorizationHandler getApiAuthorization(String name) {
211
212        return OpenCmsCore.getInstance().getApiAuthorization(name);
213    }
214
215    /**
216     * Returns the configured authorization handler.<p>
217     *
218     * @return the configured authorization handler
219     */
220    public static I_CmsAuthorizationHandler getAuthorizationHandler() {
221
222        return OpenCmsCore.getInstance().getAuthorizationHandler();
223    }
224
225    /**
226     * Gets the credentials resolver instance.<p>
227     *
228     * @return the credentials resolver
229     */
230    public static I_CmsCredentialsResolver getCredentialsResolver() {
231
232        return OpenCmsCore.getInstance().getCredentialsResolver();
233    }
234
235    /**
236     * Gets the database pool names.<p>
237     *
238     * @return the database pool names
239     */
240    public static List<String> getDbPoolNames() {
241
242        return OpenCmsCore.getInstance().getDbPoolNames();
243    }
244
245    /**
246     * Returns the configured list of default directory file names (instances of <code>{@link String}</code>).<p>
247     *
248     * Caution: This list can not be modified.<p>
249     *
250     * @return the configured list of default directory file names
251     */
252    public static List<String> getDefaultFiles() {
253
254        return OpenCmsCore.getInstance().getDefaultFiles();
255    }
256
257    /**
258     * Gets the default text encryption.
259     *
260     * @return the default text encryption
261     */
262    public static I_CmsTextEncryption getDefaultTextEncryption() {
263
264        return getTextEncryptions().get("default");
265    }
266
267    /**
268     * Returns the default user and group name configuration.<p>
269     *
270     * @return the default user and group name configuration
271     */
272    public static CmsDefaultUsers getDefaultUsers() {
273
274        return OpenCmsCore.getInstance().getDefaultUsers();
275    }
276
277    /**
278     * Returns the event manger that handles all OpenCms events.<p>
279     *
280     * @return the event manger that handles all OpenCms events
281     */
282    public static CmsEventManager getEventManager() {
283
284        return OpenCmsCore.getInstance().getEventManager();
285    }
286
287    /**
288     * Gets the thread pool executor.<p>
289     *
290     * @return the thread pool executor
291     */
292    public static ScheduledThreadPoolExecutor getExecutor() {
293
294        return OpenCmsCore.getInstance().getExecutor();
295    }
296
297    /**
298     * Returns the configured export points,
299     * the returned set being an unmodifiable set.<p>
300     *
301     * @return an unmodifiable set of the configured export points
302     */
303    public static Set<CmsExportPoint> getExportPoints() {
304
305        return OpenCmsCore.getInstance().getExportPoints();
306    }
307
308    /**
309     * Returns the flex cache.<p>
310     * @return the current CmsFlexCache object
311     */
312
313    public static CmsFlexCache getFlexCache() {
314
315        return OpenCmsCore.getInstance().getFlexCache();
316    }
317
318    /**
319     * Creates a string containing all current flex cache keys, for use in debugging.<p<
320     *
321     * @return a string containing all current flex cache keys
322     */
323    public static String getFlexCacheKeyDump() {
324
325        return OpenCmsCore.getInstance().getFlexCacheKeyDump();
326    }
327
328    /**
329     * Gets the folder size tracker for the Offline or Online project.
330     *
331     * @param true if we want the Online folder size tracker, false for the Offline project one
332     * @return the folder size tracker
333     */
334    public static CmsFolderSizeTracker getFolderSizeTracker(boolean online) {
335
336        return OpenCmsCore.getInstance().getFolderSizeTracker(online);
337    }
338
339    /**
340     * Returns the initialized import/export manager,
341     * which contains information about how to handle imported resources.<p>
342     *
343     * @return the initialized import/export manager
344     */
345    public static CmsImportExportManager getImportExportManager() {
346
347        return OpenCmsCore.getInstance().getImportExportManager();
348    }
349
350    /**
351     * Gets the LetsEncrypt configuration.<p>
352     *
353     * Returns null if LetsEncrypt integration is not configured at all.
354     *
355     * @return the LetsEncrypt configuration
356     */
357    public static CmsLetsEncryptConfiguration getLetsEncryptConfig() {
358
359        return OpenCmsCore.getInstance().getLetsEncryptConfig();
360
361    }
362
363    /**
364     * Returns the link manager to resolve links in &lt;link&gt; tags.<p>
365     *
366     * @return  the link manager to resolve links in &lt;link&gt; tags
367     */
368    public static CmsLinkManager getLinkManager() {
369
370        return OpenCmsCore.getInstance().getLinkManager();
371    }
372
373    /**
374     * Returns the locale manager used for obtaining the current locale.<p>
375     *
376     * @return the locale manager
377     */
378    public static CmsLocaleManager getLocaleManager() {
379
380        return OpenCmsCore.getInstance().getLocaleManager();
381    }
382
383    /**
384     * Returns the log for the selected object.<p>
385     *
386     * If the provided object is a String, this String will
387     * be used as channel name. Otherwise the objects
388     * class name will be used as channel name.<p>
389     *
390     * @param obj the object channel to use
391     * @return the log for the selected object channel
392     */
393    public static Log getLog(Object obj) {
394
395        return CmsLog.getLog(obj);
396    }
397
398    /**
399     * Returns the login manager used to check if a login is possible.<p>
400     *
401     * @return the login manager
402     */
403    public static CmsLoginManager getLoginManager() {
404
405        return OpenCmsCore.getInstance().getLoginManager();
406    }
407
408    /**
409     * Returns the memory monitor.<p>
410     *
411     * @return the memory monitor
412     */
413    public static CmsMemoryMonitor getMemoryMonitor() {
414
415        return OpenCmsCore.getInstance().getMemoryMonitor();
416    }
417
418    /**
419     * Returns the module manager.<p>
420     *
421     * @return the module manager
422     */
423    public static CmsModuleManager getModuleManager() {
424
425        return OpenCmsCore.getInstance().getModuleManager();
426    }
427
428    /**
429     * Returns the organizational unit manager.<p>
430     *
431     * @return the organizational unit manager
432     */
433    public static CmsOrgUnitManager getOrgUnitManager() {
434
435        return OpenCmsCore.getInstance().getOrgUnitManager();
436    }
437
438    /**
439     * Returns the password handler.<p>
440     *
441     * @return the password handler
442     */
443    public static I_CmsPasswordHandler getPasswordHandler() {
444
445        return OpenCmsCore.getInstance().getPasswordHandler();
446    }
447
448    /**
449     * Returns the core publish manager class.<p>
450     *
451     * @return the publish manager instance
452     */
453    public static CmsPublishManager getPublishManager() {
454
455        return OpenCmsCore.getInstance().getPublishManager();
456    }
457
458    /**
459     * Returns the repository manager.<p>
460     *
461     * @return the repository manager
462     */
463    public static CmsRepositoryManager getRepositoryManager() {
464
465        return OpenCmsCore.getInstance().getRepositoryManager();
466    }
467
468    /**
469     * Returns the resource manager.<p>
470     *
471     * @return the resource manager
472     */
473    public static CmsResourceManager getResourceManager() {
474
475        return OpenCmsCore.getInstance().getResourceManager();
476    }
477
478    /**
479     * Returns the role manager.<p>
480     *
481     * @return the role manager
482     */
483    public static CmsRoleManager getRoleManager() {
484
485        return OpenCmsCore.getInstance().getRoleManager();
486    }
487
488    /**
489     * Returns the current OpenCms run level.<p>
490     *
491     * The following runlevels are defined:
492     * <dl>
493     * <dt>Runlevel {@link OpenCms#RUNLEVEL_0_OFFLINE}:</dt><dd>
494     * OpenCms is in the process of being shut down, the system is offline.</dd>
495     *
496     * <dt>Runlevel {@link OpenCms#RUNLEVEL_1_CORE_OBJECT}:</dt><dd>
497     * OpenCms instance available, but configuration has not been processed.
498     * No database or VFS available.</dd>
499     *
500     * <dt>Runlevel {@link OpenCms#RUNLEVEL_2_INITIALIZING}:</dt><dd>
501     * OpenCms is initializing, but the process is not finished.
502     * The database with the VFS is currently being connected but can't be accessed.</dd>
503     *
504     * <dt>Runlevel {@link OpenCms#RUNLEVEL_3_SHELL_ACCESS}:</dt><dd>
505     * OpenCms database and VFS available, but http processing (i.e. servlet) not initialized.
506     * This is the runlevel the OpenCms shell operates in.</dd>
507     *
508     * <dt>Runlevel {@link OpenCms#RUNLEVEL_4_SERVLET_ACCESS}:</dt><dd>
509     * OpenCms fully initialized, servlet and database available.
510     * This is the "default" when OpenCms is in normal operation.</dd>
511     * </dl>
512     *
513     * @return the OpenCms run level
514     */
515    public static int getRunLevel() {
516
517        return OpenCmsCore.getInstance().getRunLevel();
518    }
519
520    /**
521     * Looks up a value in the runtime property Map.<p>
522     *
523     * @param key the key to look up in the runtime properties
524     * @return the value for the key, or null if the key was not found
525     */
526    public static Object getRuntimeProperty(Object key) {
527
528        return OpenCmsCore.getInstance().getRuntimeProperty(key);
529    }
530
531    /**
532     * Returns the configured schedule manager.<p>
533     *
534     * @return the configured schedule manager
535     */
536    public static CmsScheduleManager getScheduleManager() {
537
538        return OpenCmsCore.getInstance().getScheduleManager();
539    }
540
541    /**
542     * Returns the initialized search manager,
543     * which provides indexing and searching operations.<p>
544     *
545     * @return the initialized search manager
546     */
547    public static CmsSearchManager getSearchManager() {
548
549        return OpenCmsCore.getInstance().getSearchManager();
550    }
551
552    /**
553     * Returns the session manager that keeps track of the active users.<p>
554     *
555     * @return the session manager that keeps track of the active users
556     */
557    public static CmsSessionManager getSessionManager() {
558
559        return OpenCmsCore.getInstance().getSessionManager();
560    }
561
562    /**
563     * Returns the initialized site manager,
564     * which contains information about all configured sites.<p>
565     *
566     * @return the initialized site manager
567     */
568    public static CmsSiteManagerImpl getSiteManager() {
569
570        return OpenCmsCore.getInstance().getSiteManager();
571    }
572
573    /**
574     * Returns an instance of the common sql manager.<p>
575     *
576     * @return an instance of the common sql manager
577     */
578    public static CmsSqlManager getSqlManager() {
579
580        return OpenCmsCore.getInstance().getSqlManager();
581    }
582
583    /**
584     * Returns the properties for the static export.<p>
585     *
586     * @return the properties for the static export
587     */
588    public static CmsStaticExportManager getStaticExportManager() {
589
590        return OpenCmsCore.getInstance().getStaticExportManager();
591    }
592
593    /**
594     * Returns the subscription manager.<p>
595     *
596     * @return the subscription manager
597     */
598    public static CmsSubscriptionManager getSubscriptionManager() {
599
600        return OpenCmsCore.getInstance().getSubscriptionManager();
601    }
602
603    /**
604     * Returns the system information storage.<p>
605     *
606     * @return the system information storage
607     */
608    public static CmsSystemInfo getSystemInfo() {
609
610        return OpenCmsCore.getInstance().getSystemInfo();
611    }
612
613    /**
614     * Returns the list of system defined roles (instances of <code>{@link CmsRole}</code>).<p>
615     *
616     * Caution: This list can not be modified.<p>
617     *
618     * @return the list of system defined roles
619     */
620    public static List<CmsRole> getSystemRoles() {
621
622        return CmsRole.getSystemRoles();
623    }
624
625    /**
626     * Gets the template context manager.<p>
627     *
628     * @return the template context manager instance
629     */
630    public static CmsTemplateContextManager getTemplateContextManager() {
631
632        return OpenCmsCore.getInstance().getTemplateContextManager();
633    }
634
635    /**
636     * Gets the map of text encryption methods, with their names as keys.
637     *
638     * @return the map of text encryption methods
639     */
640    public static Map<String, I_CmsTextEncryption> getTextEncryptions() {
641
642        return OpenCmsCore.getInstance().getTextEncryptions();
643    }
644
645    /**
646     * Returns the OpenCms Thread store.<p>
647     *
648     * @return the OpenCms Thread store
649     */
650    public static CmsThreadStore getThreadStore() {
651
652        return OpenCmsCore.getInstance().getThreadStore();
653    }
654
655    /**
656     * Gets the two-factor authentication handler.
657     *
658     * @return the two-factor authentication handler
659     */
660    public static CmsTwoFactorAuthenticationHandler getTwoFactorAuthenticationHandler() {
661
662        return OpenCmsCore.getInstance().getTwoFactorAuthenticationHandler();
663    }
664
665    /**
666     * Gets the user data request manager.
667     *
668     * @return the user data request manager
669     */
670    public static CmsUserDataRequestManager getUserDataRequestManager() {
671
672        return OpenCmsCore.getInstance().getUserDataRequestManager();
673    }
674
675    /**
676     * Returns the runtime validation handler.<p>
677     *
678     * @return the validation handler
679     */
680    public static I_CmsValidationHandler getValidationHandler() {
681
682        return OpenCmsCore.getInstance().getValidationHandler();
683    }
684
685    /**
686     * Gets the default memory object cache instance.
687     *
688     * @return the memory object cache
689     */
690    public static CmsVfsMemoryObjectCache getVfsMemoryObjectCache() {
691
692        return OpenCmsCore.getInstance().getVfsMemoryObjectCache();
693    }
694
695    /**
696     * Gets the initialized workflow manager.<p>
697     *
698     * @return the initialized workflow manager
699     */
700    public static I_CmsWorkflowManager getWorkflowManager() {
701
702        return OpenCmsCore.getInstance().getWorkflowManager();
703    }
704
705    /**
706     * Returns the workplace app manager.<p>
707     *
708     * @return the app manager
709     */
710    public static CmsWorkplaceAppManager getWorkplaceAppManager() {
711
712        return OpenCmsCore.getInstance().getWorkplaceAppManager();
713    }
714
715    /**
716     * Returns the initialized workplace manager,
717     * which contains information about the global workplace settings.<p>
718     *
719     * @return the initialized workplace manager
720     */
721    public static CmsWorkplaceManager getWorkplaceManager() {
722
723        return OpenCmsCore.getInstance().getWorkplaceManager();
724    }
725
726    /**
727     * Returns the XML content type manager.<p>
728     *
729     * @return the XML content type manager
730     */
731    public static CmsXmlContentTypeManager getXmlContentTypeManager() {
732
733        return OpenCmsCore.getInstance().getXmlContentTypeManager();
734    }
735
736    /**
737     * Returns an independent copy of the provided CmsObject.<p>
738     *
739     * This can be useful in case a permanent reference to a CmsObject is stored.
740     * Changing the request context values (for example project, siteroot) in the new CmsObject
741     * will have no side effects to the CmsObject it was copied form.<p>
742     *
743     * @param cms the CmsObject to create a copy of
744     *
745     * @return an independent copy of the provided CmsObject
746     *
747     * @throws CmsException in case the initialization failed
748     *
749     * @see OpenCms#initCmsObject(CmsObject)
750     * @see OpenCms#initCmsObject(CmsObject, CmsContextInfo)
751     * @see OpenCms#initCmsObject(String)
752     */
753    public static CmsObject initCmsObject(CmsObject cms) throws CmsException {
754
755        return OpenCmsCore.getInstance().initCmsObject(cms);
756    }
757
758    /**
759     * Returns an initialized CmsObject with the user and context initialized as provided.<p>
760     *
761     * Note: Only if the provided <code>adminCms</code> CmsObject has admin permissions,
762     * this method allows the creation a CmsObject for any existing user. Otherwise
763     * only the default users 'Guest' and 'Export' can initialized with
764     * this method, all other user names will throw an Exception.<p>
765     *
766     * @param adminCms must either be initialized with "Admin" permissions, or null
767     * @param contextInfo the context info to create a CmsObject for
768     *
769     * @return an initialized CmsObject with the given users permissions
770     *
771     * @throws CmsException if an invalid user name was provided, or if something else goes wrong
772     *
773     * @see org.opencms.db.CmsDefaultUsers#getUserGuest()
774     * @see org.opencms.db.CmsDefaultUsers#getUserExport()
775     * @see OpenCms#initCmsObject(CmsObject)
776     * @see OpenCms#initCmsObject(CmsObject, CmsContextInfo)
777     * @see OpenCms#initCmsObject(String)
778     */
779    public static CmsObject initCmsObject(CmsObject adminCms, CmsContextInfo contextInfo) throws CmsException {
780
781        return OpenCmsCore.getInstance().initCmsObject(adminCms, contextInfo);
782    }
783
784    /**
785     * Returns an initialized CmsObject (OpenCms user context) with the user initialized as provided,
786     * with the "Online" project selected and "/" set as the current site root.<p>
787     *
788     * Note: Only the default users 'Guest' and 'Export' can initialized with
789     * this method, all other user names will throw an Exception.<p>
790     *
791     * In order to initialize another user (for example, the {@link CmsDefaultUsers#getUserAdmin()}),
792     * you need to get the 'Guest' user context first, then login the target user with
793     * his user name and password, using {@link CmsObject#loginUser(String, String)}.
794     * There is no way to obtain a user context other then the 'Guest' or 'Export' user
795     * without the users password. This is a security feature.<p>
796     *
797     * @param user the user name to initialize, can only be
798     *        {@link org.opencms.db.CmsDefaultUsers#getUserGuest()} or
799     *        {@link org.opencms.db.CmsDefaultUsers#getUserExport()}
800     *
801     * @return an initialized CmsObject with the given users permissions
802     *
803     * @throws CmsException if an invalid user name was provided, or if something else goes wrong
804     *
805     * @see org.opencms.db.CmsDefaultUsers#getUserGuest()
806     * @see org.opencms.db.CmsDefaultUsers#getUserExport()
807     * @see OpenCms#initCmsObject(CmsObject)
808     * @see OpenCms#initCmsObject(CmsObject, CmsContextInfo)
809     * @see OpenCms#initCmsObject(String)
810     */
811    public static CmsObject initCmsObject(String user) throws CmsException {
812
813        return OpenCmsCore.getInstance().initCmsObject(user);
814    }
815
816    /**
817     * Reads the requested resource from the OpenCms VFS,
818     * and in case a directory name is requested, the default files of the
819     * directory will be looked up and the first match is returned.<p>
820     *
821     * The resource that is returned is always a <code>{@link org.opencms.file.CmsFile}</code>,
822     * even though the content will usually not be loaded in the result. Folders are never returned since
823     * the point of this method is really to load the default file if just a folder name is requested.<p>
824     *
825     * The URI stored in the given OpenCms user context will be changed to the URI of the resource
826     * that was found and returned.<p>
827     *
828     * Implementing and configuring an <code>{@link I_CmsResourceInit}</code> handler
829     * allows to customize the process of default resource selection.<p>
830     *
831     * @param cms the current users OpenCms context
832     * @param resourceName the path of the requested resource in the OpenCms VFS
833     * @param req the current http request
834     * @param res the current http response
835     * @return the requested resource read from the VFS
836     *
837     * @throws CmsException in case the requested file does not exist or the user has insufficient access permissions
838     */
839    public static CmsResource initResource(
840        CmsObject cms,
841        String resourceName,
842        HttpServletRequest req,
843        HttpServletResponse res)
844    throws CmsException {
845
846        return OpenCmsCore.getInstance().initResource(cms, resourceName, req, res);
847    }
848
849    /**
850     * Removes a cms event listener.<p>
851     *
852     * @param listener the listener to remove
853     */
854    public static void removeCmsEventListener(I_CmsEventListener listener) {
855
856        OpenCmsCore.getInstance().getEventManager().removeCmsEventListener(listener);
857    }
858
859    /**
860     * This method adds an Object to the OpenCms runtime properties.
861     * The runtime properties can be used to store Objects that are shared
862     * in the whole system.<p>
863     *
864     * @param key the key to add the Object with
865     * @param value the value of the Object to add
866     */
867    public static void setRuntimeProperty(Object key, Object value) {
868
869        OpenCmsCore.getInstance().setRuntimeProperty(key, value);
870    }
871
872    /**
873     * Writes the XML configuration for the provided configuration class.<p>
874     *
875     * @param clazz the configuration class to write the XML for
876     */
877    public static void writeConfiguration(Class<?> clazz) {
878
879        OpenCmsCore.getInstance().writeConfiguration(clazz);
880    }
881}