org.opencms.main
Class OpenCms

java.lang.Object
  extended by 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 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
Version:
$Revision: 1.69 $
Author:
Alexander Kandzior

Field Summary
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
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(CmsEvent event)
          Notify all event listeners that a particular event has occurred.
static void fireCmsEvent(int type, java.util.Map data)
          Notify all event listeners that a particular event has occurred.
static I_CmsAuthorizationHandler getAuthorizationHandler()
          Returns the configured authorization handler.
static java.util.List getDefaultFiles()
          Returns the configured list of default directory file names (instances of String).
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.Set getExportPoints()
          Returns the configured export points, the returned set being an unmodifiable set.
static CmsImportExportManager getImportExportManager()
          Returns the initialized import/export manager, which contains information about how to handle imported resources.
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 CmsSystemInfo getSystemInfo()
          Returns the system information storage.
static java.util.List getSystemRoles()
          Returns the list of system defined roles (instances of CmsRole).
static CmsThreadStore getThreadStore()
          Returns the OpenCms Thread store.
static I_CmsValidationHandler getValidationHandler()
          Returns the runtime validation handler.
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(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 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 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,
                                java.util.Map 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

getAuthorizationHandler

public static I_CmsAuthorizationHandler getAuthorizationHandler()
Returns the configured authorization handler.

Returns:
the configured authorization handler

getDefaultFiles

public static java.util.List 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

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

getExportPoints

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

Returns:
an unmodifiable set of the configured export points

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

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

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

getSystemInfo

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

Returns:
the system information storage

getSystemRoles

public static java.util.List 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

getThreadStore

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

Returns:
the OpenCms Thread store

getValidationHandler

public static I_CmsValidationHandler getValidationHandler()
Returns the runtime validation handler.

Returns:
the validation handler

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 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:
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, 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:
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 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(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 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.

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