Class OpenCms

java.lang.Object
org.opencms.main.OpenCms

public final class OpenCms extends 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.

Since:
6.0.0
  • Field Details

  • Method Details

    • addCmsEventListener

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

      Parameters:
      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.

      Parameters:
      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.

      Parameters:
      event - a CmsEvent
    • fireCmsEvent

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

      The event will be given to all registered I_CmsEventListener objects.

      Parameters:
      type - event type
      data - event data
    • getADEManager

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

      Returns:
      the initialized ADE manager
    • getAliasManager

      Gets the alias manager.

      Returns:
      the alias manager
    • getApiAuthorization

      Gets the API authorization handler with the given name.

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

      Parameters:
      name - the name of the API authorization handler
      Returns:
      an API authorization handler
    • getAuthorizationHandler

      Returns the configured authorization handler.

      Returns:
      the configured authorization handler
    • getCredentialsResolver

      Gets the credentials resolver instance.

      Returns:
      the credentials resolver
    • getDbPoolNames

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

      Returns:
      the database pool names
    • getDefaultFiles

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

      Caution: This list can not be modified.

      Returns:
      the configured list of default directory file names
    • getDefaultTextEncryption

      Gets the default text encryption.
      Returns:
      the default text encryption
    • getDefaultUsers

      Returns the default user and group name configuration.

      Returns:
      the default user and group name configuration
    • getEventManager

      Returns the event manger that handles all OpenCms events.

      Returns:
      the event manger that handles all OpenCms events
    • getExecutor

      Gets the thread pool executor.

      Returns:
      the thread pool executor
    • getExportPoints

      Returns the configured export points, the returned set being an unmodifiable set.

      Returns:
      an unmodifiable set of the configured export points
    • getFlexCache

      public static CmsFlexCache getFlexCache()
      Returns the flex cache.

      Returns:
      the current CmsFlexCache object
    • getFlexCacheKeyDump

      public static String getFlexCacheKeyDump()
      Creates a string containing all current flex cache keys, for use in debugging.<p<
      Returns:
      a string containing all current flex cache keys
    • getImportExportManager

      Returns the initialized import/export manager, which contains information about how to handle imported resources.

      Returns:
      the initialized import/export manager
    • getLetsEncryptConfig

      Gets the LetsEncrypt configuration.

      Returns null if LetsEncrypt integration is not configured at all.

      Returns:
      the LetsEncrypt configuration
    • getLinkManager

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

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

      Returns the locale manager used for obtaining the current locale.

      Returns:
      the locale manager
    • getLog

      public static org.apache.commons.logging.Log getLog(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.

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

      Returns the login manager used to check if a login is possible.

      Returns:
      the login manager
    • getMemoryMonitor

      Returns the memory monitor.

      Returns:
      the memory monitor
    • getModuleManager

      Returns the module manager.

      Returns:
      the module manager
    • getOrgUnitManager

      Returns the organizational unit manager.

      Returns:
      the organizational unit manager
    • getPasswordHandler

      Returns the password handler.

      Returns:
      the password handler
    • getPublishManager

      Returns the core publish manager class.

      Returns:
      the publish manager instance
    • getRepositoryManager

      Returns the repository manager.

      Returns:
      the repository manager
    • getResourceManager

      Returns the resource manager.

      Returns:
      the resource manager
    • getRoleManager

      public static CmsRoleManager getRoleManager()
      Returns the role manager.

      Returns:
      the role 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.
      Runlevel RUNLEVEL_2_INITIALIZING:
      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.
      Runlevel RUNLEVEL_4_SERVLET_ACCESS:
      OpenCms fully initialized, servlet and database available. This is the "default" when OpenCms is in normal operation.
      Returns:
      the OpenCms run level
    • getRuntimeProperty

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

      Parameters:
      key - the key to look up in the runtime properties
      Returns:
      the value for the key, or null if the key was not found
    • getScheduleManager

      Returns the configured schedule manager.

      Returns:
      the configured schedule manager
    • getSearchManager

      Returns the initialized search manager, which provides indexing and searching operations.

      Returns:
      the initialized search manager
    • getSessionManager

      Returns the session manager that keeps track of the active users.

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

      Returns the initialized site manager, which contains information about all configured sites.

      Returns:
      the initialized site manager
    • getSqlManager

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

      Returns:
      an instance of the common sql manager
    • getStaticExportManager

      Returns the properties for the static export.

      Returns:
      the properties for the static export
    • getSubscriptionManager

      Returns the subscription manager.

      Returns:
      the subscription manager
    • getSystemInfo

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

      Returns:
      the system information storage
    • getSystemRoles

      public static List<CmsRole> getSystemRoles()
      Returns the list of system defined roles (instances of CmsRole).

      Caution: This list can not be modified.

      Returns:
      the list of system defined roles
    • getTemplateContextManager

      Gets the template context manager.

      Returns:
      the template context manager instance
    • getTextEncryptions

      Gets the map of text encryption methods, with their names as keys.
      Returns:
      the map of text encryption methods
    • getThreadStore

      public static CmsThreadStore getThreadStore()
      Returns the OpenCms Thread store.

      Returns:
      the OpenCms Thread store
    • getTwoFactorAuthenticationHandler

      Gets the two-factor authentication handler.
      Returns:
      the two-factor authentication handler
    • getUserDataRequestManager

      Gets the user data request manager.
      Returns:
      the user data request manager
    • getValidationHandler

      Returns the runtime validation handler.

      Returns:
      the validation handler
    • getVfsMemoryObjectCache

      Gets the default memory object cache instance.
      Returns:
      the memory object cache
    • getWorkflowManager

      Gets the initialized workflow manager.

      Returns:
      the initialized workflow manager
    • getWorkplaceAppManager

      Returns the workplace app manager.

      Returns:
      the app manager
    • getWorkplaceManager

      Returns the initialized workplace manager, which contains information about the global workplace settings.

      Returns:
      the initialized workplace manager
    • getXmlContentTypeManager

      Returns the XML content type manager.

      Returns:
      the XML content type manager
    • initCmsObject

      public static CmsObject initCmsObject(CmsObject cms) throws CmsException
      Returns an independent copy of the provided CmsObject.

      This can be useful in case a permanent reference to a CmsObject is stored. Changing the request context values (for example project, siteroot) in the new CmsObject will have no side effects to the CmsObject it was copied form.

      Parameters:
      cms - the CmsObject to create a copy of
      Returns:
      an independent copy of the provided CmsObject
      Throws:
      CmsException - in case the initialization failed
      See Also:
    • initCmsObject

      public static CmsObject initCmsObject(CmsObject adminCms, CmsContextInfo contextInfo) throws CmsException
      Returns an initialized CmsObject with the user and context initialized as provided.

      Note: Only if the provided adminCms CmsObject has admin permissions, this method allows the creation a CmsObject for any existing user. Otherwise only the default users 'Guest' and 'Export' can initialized with this method, all other user names will throw an Exception.

      Parameters:
      adminCms - must either be initialized with "Admin" permissions, or null
      contextInfo - the context info to create a CmsObject for
      Returns:
      an initialized CmsObject with the given users permissions
      Throws:
      CmsException - if an invalid user name was provided, or if something else goes wrong
      See Also:
    • initCmsObject

      public static CmsObject initCmsObject(String user) throws CmsException
      Returns an initialized CmsObject (OpenCms user context) with the user initialized as provided, with the "Online" project selected and "/" set as the current site root.

      Note: Only the default users 'Guest' and 'Export' can initialized with this method, all other user names will throw an Exception.

      In order to initialize another user (for example, the CmsDefaultUsers.getUserAdmin()), you need to get the 'Guest' user context first, then login the target user with his user name and password, using CmsObject.loginUser(String, String). There is no way to obtain a user context other then the 'Guest' or 'Export' user without the users password. This is a security feature.

      Parameters:
      user - the user name to initialize, can only be CmsDefaultUsers.getUserGuest() or CmsDefaultUsers.getUserExport()
      Returns:
      an initialized CmsObject with the given users permissions
      Throws:
      CmsException - if an invalid user name was provided, or if something else goes wrong
      See Also:
    • initResource

      public static CmsResource initResource(CmsObject cms, 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.

      Parameters:
      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
      Returns:
      the requested resource read from the VFS
      Throws:
      CmsException - in case the requested file does not exist or the user has insufficient access permissions
    • removeCmsEventListener

      public static void removeCmsEventListener(I_CmsEventListener listener)
      Removes a cms event listener.

      Parameters:
      listener - the listener to remove
    • setRuntimeProperty

      public static void setRuntimeProperty(Object key, 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.

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

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

      Parameters:
      clazz - the configuration class to write the XML for