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