Class OpenCms
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,
use CmsObject
. The argument String should be
the name of the guest user, usually "Guest" and more formally obtained by initCmsObject(String)
.
This will give you an initialized context with guest user permissions.
Then use CmsDefaultUsers.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 initialized getSiteManager()
which provides information about the sites configured in the running OpenCms instance.CmsSiteManagerImpl
The
instance returned by CmsDefaultUsers
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 the CmsModuleManager
.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
Modifier and TypeFieldDescriptionstatic final int
Runlevel 0: System is offline.static final int
Runlevel 1: Core object created, no database (some test cases run in this level).static final int
Runlevel 2: Initializing the system, required since this may take some seconds because of database connections.static final int
Runlevel 3: Shell access to the database possible, but no servlet context available.static final int
Runlevel 4: Final runlevel where database and servlet are initialized. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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, Map<String, 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
Gets the initialized ADE manager.static CmsAliasManager
Gets the alias manager.static I_CmsApiAuthorizationHandler
getApiAuthorization
(String name) Gets the API authorization handler with the given name.static I_CmsAuthorizationHandler
Returns the configured authorization handler.static I_CmsCredentialsResolver
Gets the credentials resolver instance.Gets the database pool names.Returns the configured list of default directory file names (instances of
).String
static I_CmsTextEncryption
Gets the default text encryption.static CmsDefaultUsers
Returns the default user and group name configuration.static CmsEventManager
Returns the event manger that handles all OpenCms events.static ScheduledThreadPoolExecutor
Gets the thread pool executor.static Set<CmsExportPoint>
Returns the configured export points, the returned set being an unmodifiable set.static CmsFlexCache
Returns the flex cache.static String
Creates a string containing all current flex cache keys, for use in debugging.<p<static CmsImportExportManager
Returns the initialized import/export manager, which contains information about how to handle imported resources.static CmsLetsEncryptConfiguration
Gets the LetsEncrypt configuration.static CmsLinkManager
Returns the link manager to resolve links in <link> tags.static CmsLocaleManager
Returns the locale manager used for obtaining the current locale.static org.apache.commons.logging.Log
Returns the log for the selected object.static CmsLoginManager
Returns the login manager used to check if a login is possible.static CmsMemoryMonitor
Returns the memory monitor.static CmsModuleManager
Returns the module manager.static CmsOrgUnitManager
Returns the organizational unit manager.static I_CmsPasswordHandler
Returns the password handler.static CmsPublishManager
Returns the core publish manager class.static CmsRepositoryManager
Returns the repository manager.static CmsResourceManager
Returns the resource manager.static CmsRoleManager
Returns the role manager.static int
Returns the current OpenCms run level.static Object
getRuntimeProperty
(Object key) Looks up a value in the runtime property Map.static CmsScheduleManager
Returns the configured schedule manager.static CmsSearchManager
Returns the initialized search manager, which provides indexing and searching operations.static CmsSessionManager
Returns the session manager that keeps track of the active users.static CmsSiteManagerImpl
Returns the initialized site manager, which contains information about all configured sites.static CmsSqlManager
Returns an instance of the common sql manager.static CmsStaticExportManager
Returns the properties for the static export.static CmsSubscriptionManager
Returns the subscription manager.static CmsSystemInfo
Returns the system information storage.Returns the list of system defined roles (instances of
).CmsRole
static CmsTemplateContextManager
Gets the template context manager.static Map<String,
I_CmsTextEncryption> Gets the map of text encryption methods, with their names as keys.static CmsThreadStore
Returns the OpenCms Thread store.Gets the two-factor authentication handler.static CmsUserDataRequestManager
Gets the user data request manager.static I_CmsValidationHandler
Returns the runtime validation handler.static CmsVfsMemoryObjectCache
Gets the default memory object cache instance.static I_CmsWorkflowManager
Gets the initialized workflow manager.static CmsWorkplaceAppManager
Returns the workplace app manager.static CmsWorkplaceManager
Returns the initialized workplace manager, which contains information about the global workplace settings.static CmsXmlContentTypeManager
Returns the XML content type manager.static CmsObject
initCmsObject
(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, 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
(Object key, Object value) This method adds an Object to the OpenCms runtime properties.static void
writeConfiguration
(Class<?> clazz) Writes the XML configuration for the provided configuration class.
-
Field Details
-
RUNLEVEL_0_OFFLINE
Runlevel 0: System is offline.- See Also:
-
RUNLEVEL_1_CORE_OBJECT
Runlevel 1: Core object created, no database (some test cases run in this level).- See Also:
-
RUNLEVEL_2_INITIALIZING
Runlevel 2: Initializing the system, required since this may take some seconds because of database connections.- See Also:
-
RUNLEVEL_3_SHELL_ACCESS
Runlevel 3: Shell access to the database possible, but no servlet context available.- See Also:
-
RUNLEVEL_4_SERVLET_ACCESS
Runlevel 4: Final runlevel where database and servlet are initialized.- See Also:
-
-
Method Details
-
addCmsEventListener
Add a cms event listener that listens to all events.- Parameters:
listener
- the listener to add
-
addCmsEventListener
Add a cms event listener that listens only to particular events.- Parameters:
listener
- the listener to addeventTypes
- the events to listen for
-
fireCmsEvent
Notify all event listeners that a particular event has occurred.- Parameters:
event
- a CmsEvent
-
fireCmsEvent
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
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
Gets the database pool names.- Returns:
- the database pool names
-
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
Returns the flex cache.- Returns:
- the current CmsFlexCache object
-
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
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
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
Returns the role manager.- Returns:
- the role manager
-
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
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
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
Returns the system information storage.- Returns:
- the system information storage
-
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
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
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 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:
-
initCmsObject
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:
-
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
, 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
Removes a cms event listener.- Parameters:
listener
- the listener to remove
-
setRuntimeProperty
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
Writes the XML configuration for the provided configuration class.- Parameters:
clazz
- the configuration class to write the XML for
-