Class OpenCms
- java.lang.Object
-
- org.opencms.main.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
class in your application, useCmsObject
. The argument String should be the name of the guest user, usually "Guest" and more formally obtained byinitCmsObject(String)
. This will give you an initialized context with guest user permissions. Then useCmsDefaultUsers.getUserGuest()
to log in the user you want. Obviously you need the password for the new user.CmsObject.loginUser(String, String)
Using
you can obtain the initializedgetSiteManager()
which provides information about the sites configured in the running OpenCms instance.CmsSiteManagerImpl
The
instance returned byCmsDefaultUsers
provides information about the names of the OpenCms default users.getDefaultUsers()
Other objects of note that can be obtained by this class include the
or theCmsModuleManager
.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 Summary
Fields Modifier and Type Field Description static int
RUNLEVEL_0_OFFLINE
Runlevel 0: System is offline.static int
RUNLEVEL_1_CORE_OBJECT
Runlevel 1: Core object created, no database (some test cases run in this level).static int
RUNLEVEL_2_INITIALIZING
Runlevel 2: Initializing the system, required since this may take some seconds because of database connections.static int
RUNLEVEL_3_SHELL_ACCESS
Runlevel 3: Shell access to the database possible, but no servlet context available.static int
RUNLEVEL_4_SERVLET_ACCESS
Runlevel 4: Final runlevel where database and servlet are initialized.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addCmsEventListener(I_CmsEventListener listener)
Add a cms event listener that listens to all events.static void
addCmsEventListener(I_CmsEventListener listener, int[] eventTypes)
Add a cms event listener that listens only to particular events.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.static void
fireCmsEvent(CmsEvent event)
Notify all event listeners that a particular event has occurred.static CmsADEManager
getADEManager()
Gets the initialized ADE manager.static CmsAliasManager
getAliasManager()
Gets the alias manager.static I_CmsApiAuthorizationHandler
getApiAuthorization(java.lang.String name)
Gets the API authorization handler with the given name.static I_CmsAuthorizationHandler
getAuthorizationHandler()
Returns the configured authorization handler.static I_CmsCredentialsResolver
getCredentialsResolver()
Gets the credentials resolver instance.static java.util.List<java.lang.String>
getDbPoolNames()
Gets the database pool names.static java.util.List<java.lang.String>
getDefaultFiles()
Returns the configured list of default directory file names (instances of
).String
static I_CmsTextEncryption
getDefaultTextEncryption()
Gets the default text encryption.static CmsDefaultUsers
getDefaultUsers()
Returns the default user and group name configuration.static CmsEventManager
getEventManager()
Returns the event manger that handles all OpenCms events.static java.util.concurrent.ScheduledThreadPoolExecutor
getExecutor()
Gets the thread pool executor.static java.util.Set<CmsExportPoint>
getExportPoints()
Returns the configured export points, the returned set being an unmodifiable set.static CmsFlexCache
getFlexCache()
Returns the flex cache.static java.lang.String
getFlexCacheKeyDump()
Creates a string containing all current flex cache keys, for use in debugging.static CmsImportExportManager
getImportExportManager()
Returns the initialized import/export manager, which contains information about how to handle imported resources.static CmsLetsEncryptConfiguration
getLetsEncryptConfig()
Gets the LetsEncrypt configuration.static CmsLinkManager
getLinkManager()
Returns the link manager to resolve links in <link> tags.static CmsLocaleManager
getLocaleManager()
Returns the locale manager used for obtaining the current locale.static org.apache.commons.logging.Log
getLog(java.lang.Object obj)
Returns the log for the selected object.static CmsLoginManager
getLoginManager()
Returns the login manager used to check if a login is possible.static CmsMemoryMonitor
getMemoryMonitor()
Returns the memory monitor.static CmsModuleManager
getModuleManager()
Returns the module manager.static CmsOrgUnitManager
getOrgUnitManager()
Returns the organizational unit manager.static I_CmsPasswordHandler
getPasswordHandler()
Returns the password handler.static CmsPublishManager
getPublishManager()
Returns the core publish manager class.static CmsRepositoryManager
getRepositoryManager()
Returns the repository manager.static CmsResourceManager
getResourceManager()
Returns the resource manager.static CmsRoleManager
getRoleManager()
Returns the role manager.static int
getRunLevel()
Returns the current OpenCms run level.static java.lang.Object
getRuntimeProperty(java.lang.Object key)
Looks up a value in the runtime property Map.static CmsScheduleManager
getScheduleManager()
Returns the configured schedule manager.static CmsSearchManager
getSearchManager()
Returns the initialized search manager, which provides indexing and searching operations.static CmsSessionManager
getSessionManager()
Returns the session manager that keeps track of the active users.static CmsSiteManagerImpl
getSiteManager()
Returns the initialized site manager, which contains information about all configured sites.static CmsSqlManager
getSqlManager()
Returns an instance of the common sql manager.static CmsStaticExportManager
getStaticExportManager()
Returns the properties for the static export.static CmsSubscriptionManager
getSubscriptionManager()
Returns the subscription manager.static CmsSystemInfo
getSystemInfo()
Returns the system information storage.static java.util.List<CmsRole>
getSystemRoles()
Returns the list of system defined roles (instances of
).CmsRole
static CmsTemplateContextManager
getTemplateContextManager()
Gets the template context manager.static java.util.Map<java.lang.String,I_CmsTextEncryption>
getTextEncryptions()
Gets the map of text encryption methods, with their names as keys.static CmsThreadStore
getThreadStore()
Returns the OpenCms Thread store.static CmsUserDataRequestManager
getUserDataRequestManager()
static I_CmsValidationHandler
getValidationHandler()
Returns the runtime validation handler.static I_CmsWorkflowManager
getWorkflowManager()
Gets the initialized workflow manager.static CmsWorkplaceAppManager
getWorkplaceAppManager()
Returns the workplace app manager.static CmsWorkplaceManager
getWorkplaceManager()
Returns the initialized workplace manager, which contains information about the global workplace settings.static CmsXmlContentTypeManager
getXmlContentTypeManager()
Returns the XML content type manager.static CmsObject
initCmsObject(java.lang.String user)
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.static CmsObject
initCmsObject(CmsObject cms)
Returns an independent copy of the provided CmsObject.static CmsObject
initCmsObject(CmsObject adminCms, CmsContextInfo contextInfo)
Returns an initialized CmsObject with the user and context initialized as provided.static CmsResource
initResource(CmsObject cms, java.lang.String resourceName, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
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.static void
removeCmsEventListener(I_CmsEventListener listener)
Removes a cms event listener.static void
setRuntimeProperty(java.lang.Object key, java.lang.Object value)
This method adds an Object to the OpenCms runtime properties.static void
writeConfiguration(java.lang.Class<?> clazz)
Writes the XML configuration for the provided configuration class.
-
-
-
Field Detail
-
RUNLEVEL_0_OFFLINE
public static final int RUNLEVEL_0_OFFLINE
Runlevel 0: System is offline.- See Also:
- Constant Field Values
-
RUNLEVEL_1_CORE_OBJECT
public static final int RUNLEVEL_1_CORE_OBJECT
Runlevel 1: Core object created, no database (some test cases run in this level).- See Also:
- Constant Field Values
-
RUNLEVEL_2_INITIALIZING
public static final int RUNLEVEL_2_INITIALIZING
Runlevel 2: Initializing the system, required since this may take some seconds because of database connections.- See Also:
- Constant Field Values
-
RUNLEVEL_3_SHELL_ACCESS
public static final int RUNLEVEL_3_SHELL_ACCESS
Runlevel 3: Shell access to the database possible, but no servlet context available.- See Also:
- Constant Field Values
-
RUNLEVEL_4_SERVLET_ACCESS
public static final int RUNLEVEL_4_SERVLET_ACCESS
Runlevel 4: Final runlevel where database and servlet are initialized.- See Also:
- Constant Field Values
-
-
Method Detail
-
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 addeventTypes
- 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, 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
objects.I_CmsEventListener
- Parameters:
type
- event typedata
- event data
-
getADEManager
public static CmsADEManager getADEManager()
Gets the initialized ADE manager.- Returns:
- the initialized ADE manager
-
getAliasManager
public static CmsAliasManager getAliasManager()
Gets the alias manager.- Returns:
- the alias 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.
- Parameters:
name
- the name of the API authorization handler- Returns:
- an API authorization handler
-
getAuthorizationHandler
public static I_CmsAuthorizationHandler getAuthorizationHandler()
Returns the configured authorization handler.- Returns:
- the configured authorization handler
-
getCredentialsResolver
public static I_CmsCredentialsResolver getCredentialsResolver()
Gets the credentials resolver instance.- Returns:
- the credentials resolver
-
getDbPoolNames
public static java.util.List<java.lang.String> getDbPoolNames()
Gets the database pool names.- Returns:
- 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.
- Returns:
- the configured list of default directory file names
-
getDefaultTextEncryption
public static I_CmsTextEncryption getDefaultTextEncryption()
Gets the default text encryption.- Returns:
- the default text encryption
-
getDefaultUsers
public static CmsDefaultUsers getDefaultUsers()
Returns the default user and group name configuration.- Returns:
- the default user and group name configuration
-
getEventManager
public static CmsEventManager getEventManager()
Returns the event manger that handles all OpenCms events.- Returns:
- the event manger that handles all OpenCms events
-
getExecutor
public static java.util.concurrent.ScheduledThreadPoolExecutor getExecutor()
Gets the thread pool executor.- Returns:
- the thread pool executor
-
getExportPoints
public static java.util.Set<CmsExportPoint> 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 java.lang.String getFlexCacheKeyDump()
Creates a string containing all current flex cache keys, for use in debugging.- Returns:
- 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.- Returns:
- the initialized import/export manager
-
getLetsEncryptConfig
public static CmsLetsEncryptConfiguration 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
public static CmsLocaleManager getLocaleManager()
Returns the locale manager used for obtaining the current locale.- Returns:
- 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.
- Parameters:
obj
- the object channel to use- Returns:
- the log for the selected object channel
-
getLoginManager
public static CmsLoginManager getLoginManager()
Returns the login manager used to check if a login is possible.- Returns:
- the login manager
-
getMemoryMonitor
public static CmsMemoryMonitor getMemoryMonitor()
Returns the memory monitor.- Returns:
- the memory monitor
-
getModuleManager
public static CmsModuleManager getModuleManager()
Returns the module manager.- Returns:
- the module manager
-
getOrgUnitManager
public static CmsOrgUnitManager getOrgUnitManager()
Returns the organizational unit manager.- Returns:
- the organizational unit manager
-
getPasswordHandler
public static I_CmsPasswordHandler getPasswordHandler()
Returns the password handler.- Returns:
- the password handler
-
getPublishManager
public static CmsPublishManager getPublishManager()
Returns the core publish manager class.- Returns:
- the publish manager instance
-
getRepositoryManager
public static CmsRepositoryManager getRepositoryManager()
Returns the repository manager.- Returns:
- the repository manager
-
getResourceManager
public static CmsResourceManager 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
- Runlevel
-
getRuntimeProperty
public static java.lang.Object getRuntimeProperty(java.lang.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
public static CmsScheduleManager getScheduleManager()
Returns the configured schedule manager.- Returns:
- the configured schedule manager
-
getSearchManager
public static CmsSearchManager getSearchManager()
Returns the initialized search manager, which provides indexing and searching operations.- Returns:
- the initialized search manager
-
getSessionManager
public static CmsSessionManager getSessionManager()
Returns the session manager that keeps track of the active users.- Returns:
- 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.- 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
public static CmsStaticExportManager getStaticExportManager()
Returns the properties for the static export.- Returns:
- the properties for the static export
-
getSubscriptionManager
public static CmsSubscriptionManager 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 java.util.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
public static CmsTemplateContextManager getTemplateContextManager()
Gets the template context manager.- Returns:
- the template context manager instance
-
getTextEncryptions
public static java.util.Map<java.lang.String,I_CmsTextEncryption> 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
-
getUserDataRequestManager
public static CmsUserDataRequestManager getUserDataRequestManager()
-
getValidationHandler
public static I_CmsValidationHandler getValidationHandler()
Returns the runtime validation handler.- Returns:
- the validation handler
-
getWorkflowManager
public static I_CmsWorkflowManager getWorkflowManager()
Gets the initialized workflow manager.- Returns:
- the initialized workflow manager
-
getWorkplaceAppManager
public static CmsWorkplaceAppManager getWorkplaceAppManager()
Returns the workplace app manager.- Returns:
- the app manager
-
getWorkplaceManager
public static CmsWorkplaceManager getWorkplaceManager()
Returns the initialized workplace manager, which contains information about the global workplace settings.- Returns:
- the initialized workplace manager
-
getXmlContentTypeManager
public static CmsXmlContentTypeManager 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(CmsObject)
,initCmsObject(CmsObject, CmsContextInfo)
,initCmsObject(String)
-
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 nullcontextInfo
- 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:
CmsDefaultUsers.getUserGuest()
,CmsDefaultUsers.getUserExport()
,initCmsObject(CmsObject)
,initCmsObject(CmsObject, CmsContextInfo)
,initCmsObject(String)
-
initCmsObject
public static CmsObject initCmsObject(java.lang.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, usingCmsObject.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 beCmsDefaultUsers.getUserGuest()
orCmsDefaultUsers.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:
CmsDefaultUsers.getUserGuest()
,CmsDefaultUsers.getUserExport()
,initCmsObject(CmsObject)
,initCmsObject(CmsObject, CmsContextInfo)
,initCmsObject(String)
-
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
, 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.CmsFile
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
handler allows to customize the process of default resource selection.I_CmsResourceInit
- Parameters:
cms
- the current users OpenCms contextresourceName
- the path of the requested resource in the OpenCms VFSreq
- the current http requestres
- 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(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.- Parameters:
key
- the key to add the Object withvalue
- 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.- Parameters:
clazz
- the configuration class to write the XML for
-
-