Class OpenCms

  • public final class OpenCms
    extends java.lang.Object
    The OpenCms "operating system" that provides public static methods which can be used by other classes to access basic system features of OpenCms like logging etc.

    This Object provides singleton access to the initialized OpenCms runtime system. Some methods are for internal or advanced use only, but others are of also of interest for general OpenCms development.

    For example, to generate a new instance of CmsObject class in your application, use initCmsObject(String). The argument String should be the name of the guest user, usually "Guest" and more formally obtained by CmsDefaultUsers.getUserGuest(). This will give you an initialized context with guest user permissions. Then use CmsObject.loginUser(String, String) to log in the user you want. Obviously you need the password for the new user.

    Using getSiteManager() you can obtain the initialized CmsSiteManagerImpl which provides information about the sites configured in the running OpenCms instance.

    The CmsDefaultUsers instance returned by getDefaultUsers() provides information about the names of the OpenCms default users.

    Other objects of note that can be obtained by this class include the CmsModuleManager or the CmsScheduleManager.

    When using the instances returned by this object, keep in mind that applying changes to these may alter the basic OpenCms system configuration, which in turn may affect the systems performance or stability.

    • Method Detail

      • addCmsEventListener

        public static void addCmsEventListener​(I_CmsEventListener listener)
        Add a cms event listener that listens to all events.

        listener - the listener to add
      • addCmsEventListener

        public static void addCmsEventListener​(I_CmsEventListener listener,
                                               int[] eventTypes)
        Add a cms event listener that listens only to particular events.

        listener - the listener to add
        eventTypes - the events to listen for
      • fireCmsEvent

        public static void fireCmsEvent​(CmsEvent event)
        Notify all event listeners that a particular event has occurred.

        event - a CmsEvent
      • fireCmsEvent

        public static void fireCmsEvent​(int type,
                                        java.util.Map<java.lang.String,​java.lang.Object> data)
        Notify all event listeners that a particular event has occurred.

        The event will be given to all registered I_CmsEventListener objects.

        type - event type
        data - event data
      • getADEManager

        public static CmsADEManager getADEManager()
        Gets the initialized ADE manager.

        the initialized ADE manager
      • getApiAuthorization

        public static I_CmsApiAuthorizationHandler getApiAuthorization​(java.lang.String name)
        Gets the API authorization handler with the given name.

        Returns null if there is no API authorization handler with that name.

        name - the name of the API authorization handler
        an API authorization handler
      • getDbPoolNames

        public static java.util.List<java.lang.String> getDbPoolNames()
        Gets the database pool names.

        the database pool names
      • getDefaultFiles

        public static java.util.List<java.lang.String> getDefaultFiles()
        Returns the configured list of default directory file names (instances of String).

        Caution: This list can not be modified.

        the configured list of default directory file names
      • getDefaultUsers

        public static CmsDefaultUsers getDefaultUsers()
        Returns the default user and group name configuration.

        the default user and group name configuration
      • getEventManager

        public static CmsEventManager getEventManager()
        Returns the event manger that handles all OpenCms events.

        the event manger that handles all OpenCms events
      • getExecutor

        public static java.util.concurrent.ScheduledThreadPoolExecutor getExecutor()
        Gets the thread pool executor.

        the thread pool executor
      • getExportPoints

        public static java.util.Set<CmsExportPointgetExportPoints()
        Returns the configured export points, the returned set being an unmodifiable set.

        an unmodifiable set of the configured export points
      • getFlexCache

        public static CmsFlexCache getFlexCache()
        Returns the flex cache.

        the current CmsFlexCache object
      • getFlexCacheKeyDump

        public static java.lang.String getFlexCacheKeyDump()
        Creates a string containing all current flex cache keys, for use in debugging.
        a string containing all current flex cache keys
      • getImportExportManager

        public static CmsImportExportManager getImportExportManager()
        Returns the initialized import/export manager, which contains information about how to handle imported resources.

        the initialized import/export manager
      • getLinkManager

        public static CmsLinkManager getLinkManager()
        Returns the link manager to resolve links in <link> tags.

        the link manager to resolve links in <link> tags
      • getLocaleManager

        public static CmsLocaleManager getLocaleManager()
        Returns the locale manager used for obtaining the current locale.

        the locale manager
      • getLog

        public static org.apache.commons.logging.Log getLog​(java.lang.Object obj)
        Returns the log for the selected object.

        If the provided object is a String, this String will be used as channel name. Otherwise the objects class name will be used as channel name.

        obj - the object channel to use
        the log for the selected object channel
      • getLoginManager

        public static CmsLoginManager getLoginManager()
        Returns the login manager used to check if a login is possible.

        the login manager
      • getRunLevel

        public static int getRunLevel()
        Returns the current OpenCms run level.

        The following runlevels are defined:

        Runlevel RUNLEVEL_0_OFFLINE:
        OpenCms is in the process of being shut down, the system is offline.
        Runlevel RUNLEVEL_1_CORE_OBJECT:
        OpenCms instance available, but configuration has not been processed. No database or VFS available.
        OpenCms is initializing, but the process is not finished. The database with the VFS is currently being connected but can't be accessed.
        Runlevel RUNLEVEL_3_SHELL_ACCESS:
        OpenCms database and VFS available, but http processing (i.e. servlet) not initialized. This is the runlevel the OpenCms shell operates in.
        OpenCms fully initialized, servlet and database available. This is the "default" when OpenCms is in normal operation.
        the OpenCms run level
      • getRuntimeProperty

        public static java.lang.Object getRuntimeProperty​(java.lang.Object key)
        Looks up a value in the runtime property Map.

        key - the key to look up in the runtime properties
        the value for the key, or null if the key was not found
      • getSearchManager

        public static CmsSearchManager getSearchManager()
        Returns the initialized search manager, which provides indexing and searching operations.

        the initialized search manager
      • getSessionManager

        public static CmsSessionManager getSessionManager()
        Returns the session manager that keeps track of the active users.

        the session manager that keeps track of the active users
      • getSiteManager

        public static CmsSiteManagerImpl getSiteManager()
        Returns the initialized site manager, which contains information about all configured sites.

        the initialized site manager
      • getSqlManager

        public static CmsSqlManager getSqlManager()
        Returns an instance of the common sql manager.

        an instance of the common sql manager
      • getSystemInfo

        public static CmsSystemInfo getSystemInfo()
        Returns the system information storage.

        the system information storage
      • getSystemRoles

        public static java.util.List<CmsRolegetSystemRoles()
        Returns the list of system defined roles (instances of CmsRole).

        Caution: This list can not be modified.

        the list of system defined roles
      • getTextEncryptions

        public static java.util.Map<java.lang.String,​I_CmsTextEncryptiongetTextEncryptions()
        Gets the map of text encryption methods, with their names as keys.
        the map of text encryption methods
      • getWorkplaceManager

        public static CmsWorkplaceManager getWorkplaceManager()
        Returns the initialized workplace manager, which contains information about the global workplace settings.

        the initialized workplace manager
      • initResource

        public static CmsResource initResource​(CmsObject cms,
                                               java.lang.String resourceName,
                                               javax.servlet.http.HttpServletRequest req,
                                               javax.servlet.http.HttpServletResponse res)
                                        throws CmsException
        Reads the requested resource from the OpenCms VFS, and in case a directory name is requested, the default files of the directory will be looked up and the first match is returned.

        The resource that is returned is always a CmsFile, even though the content will usually not be loaded in the result. Folders are never returned since the point of this method is really to load the default file if just a folder name is requested.

        The URI stored in the given OpenCms user context will be changed to the URI of the resource that was found and returned.

        Implementing and configuring an I_CmsResourceInit handler allows to customize the process of default resource selection.

        cms - the current users OpenCms context
        resourceName - the path of the requested resource in the OpenCms VFS
        req - the current http request
        res - the current http response
        the requested resource read from the VFS
        CmsException - in case the requested file does not exist or the user has insufficient access permissions
      • setRuntimeProperty

        public static void setRuntimeProperty​(java.lang.Object key,
                                              java.lang.Object value)
        This method adds an Object to the OpenCms runtime properties. The runtime properties can be used to store Objects that are shared in the whole system.

        key - the key to add the Object with
        value - the value of the Object to add
      • writeConfiguration

        public static void writeConfiguration​(java.lang.Class<?> clazz)
        Writes the XML configuration for the provided configuration class.

        clazz - the configuration class to write the XML for