org.opencms.main.OpenCms Maven / Gradle / Ivy
Show all versions of opencms-core Show documentation
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH & Co. KG, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.main;
import org.opencms.ade.configuration.CmsADEManager;
import org.opencms.crypto.I_CmsTextEncryption;
import org.opencms.db.CmsAliasManager;
import org.opencms.db.CmsDefaultUsers;
import org.opencms.db.CmsExportPoint;
import org.opencms.db.CmsLoginManager;
import org.opencms.db.CmsSqlManager;
import org.opencms.db.CmsSubscriptionManager;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.flex.CmsFlexCache;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.importexport.CmsImportExportManager;
import org.opencms.jsp.userdata.CmsUserDataRequestManager;
import org.opencms.letsencrypt.CmsLetsEncryptConfiguration;
import org.opencms.loader.CmsResourceManager;
import org.opencms.loader.CmsTemplateContextManager;
import org.opencms.module.CmsModuleManager;
import org.opencms.monitor.CmsMemoryMonitor;
import org.opencms.publish.CmsPublishManager;
import org.opencms.repository.CmsRepositoryManager;
import org.opencms.scheduler.CmsScheduleManager;
import org.opencms.search.CmsSearchManager;
import org.opencms.security.CmsOrgUnitManager;
import org.opencms.security.CmsRole;
import org.opencms.security.CmsRoleManager;
import org.opencms.security.I_CmsAuthorizationHandler;
import org.opencms.security.I_CmsCredentialsResolver;
import org.opencms.security.I_CmsPasswordHandler;
import org.opencms.security.I_CmsValidationHandler;
import org.opencms.site.CmsSiteManagerImpl;
import org.opencms.staticexport.CmsLinkManager;
import org.opencms.staticexport.CmsStaticExportManager;
import org.opencms.ui.apps.CmsWorkplaceAppManager;
import org.opencms.workflow.I_CmsWorkflowManager;
import org.opencms.workplace.CmsWorkplaceManager;
import org.opencms.xml.CmsXmlContentTypeManager;
import org.opencms.xml.xml2json.I_CmsApiAuthorizationHandler;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
/**
* 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 {@link org.opencms.file.CmsObject}
class in your application,
* use {@link org.opencms.main.OpenCms#initCmsObject(String)}
. The argument String should be
* the name of the guest user, usually "Guest" and more formally obtained by {@link org.opencms.db.CmsDefaultUsers#getUserGuest()}
.
* This will give you an initialized context with guest user permissions.
* Then use {@link CmsObject#loginUser(String, String)}
to log in the user you want.
* Obviously you need the password for the new user.
*
* Using {@link #getSiteManager()}
you can obtain the initialized {@link org.opencms.site.CmsSiteManagerImpl}
* which provides information about the sites configured in the running OpenCms instance.
*
* The {@link org.opencms.db.CmsDefaultUsers}
instance returned by {@link #getDefaultUsers()}
* provides information about the names of the OpenCms default users.
*
* Other objects of note that can be obtained by this class include the {@link org.opencms.module.CmsModuleManager}
* or the {@link org.opencms.scheduler.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
*/
public final class OpenCms {
/** Runlevel 0: System is offline. */
public static final int RUNLEVEL_0_OFFLINE = 0;
/** Runlevel 1: Core object created, no database (some test cases run in this level). */
public static final int RUNLEVEL_1_CORE_OBJECT = 1;
/** Runlevel 2: Initializing the system, required since this may take some seconds because of database connections. */
public static final int RUNLEVEL_2_INITIALIZING = 2;
/** Runlevel 3: Shell access to the database possible, but no servlet context available. */
public static final int RUNLEVEL_3_SHELL_ACCESS = 3;
/** Runlevel 4: Final runlevel where database and servlet are initialized. */
public static final int RUNLEVEL_4_SERVLET_ACCESS = 4;
/**
* The public contructor is hidden to prevent generation of instances of this class.
*/
private OpenCms() {
// empty
}
/**
* Add a cms event listener that listens to all events.
*
* @param listener the listener to add
*/
public static void addCmsEventListener(I_CmsEventListener listener) {
OpenCmsCore.getInstance().getEventManager().addCmsEventListener(listener);
}
/**
* Add a cms event listener that listens only to particular events.
*
* @param listener the listener to add
* @param eventTypes the events to listen for
*/
public static void addCmsEventListener(I_CmsEventListener listener, int[] eventTypes) {
OpenCmsCore.getInstance().getEventManager().addCmsEventListener(listener, eventTypes);
}
/**
* Notify all event listeners that a particular event has occurred.
*
* @param event a CmsEvent
*/
public static void fireCmsEvent(CmsEvent event) {
OpenCmsCore.getInstance().getEventManager().fireEvent(event);
}
/**
* Notify all event listeners that a particular event has occurred.
*
* The event will be given to all registered {@link I_CmsEventListener}
objects.
*
* @param type event type
* @param data event data
*/
public static void fireCmsEvent(int type, Map data) {
OpenCmsCore.getInstance().getEventManager().fireEvent(type, data);
}
/**
* Gets the initialized ADE manager.
*
* @return the initialized ADE manager
*/
public static CmsADEManager getADEManager() {
return OpenCmsCore.getInstance().getADEManager();
}
/**
* Gets the alias manager.
*
* @return the alias manager
*/
public static CmsAliasManager getAliasManager() {
return OpenCmsCore.getInstance().getAliasManager();
}
/**
* Gets the API authorization handler with the given name.
*
*
Returns null if there is no API authorization handler with that name.
*
* @param name the name of the API authorization handler
*
* @return an API authorization handler
*/
public static I_CmsApiAuthorizationHandler getApiAuthorization(String name) {
return OpenCmsCore.getInstance().getApiAuthorization(name);
}
/**
* Returns the configured authorization handler.
*
* @return the configured authorization handler
*/
public static I_CmsAuthorizationHandler getAuthorizationHandler() {
return OpenCmsCore.getInstance().getAuthorizationHandler();
}
/**
* Gets the credentials resolver instance.
*
* @return the credentials resolver
*/
public static I_CmsCredentialsResolver getCredentialsResolver() {
return OpenCmsCore.getInstance().getCredentialsResolver();
}
/**
* Gets the database pool names.
*
* @return the database pool names
*/
public static List getDbPoolNames() {
return OpenCmsCore.getInstance().getDbPoolNames();
}
/**
* Returns the configured list of default directory file names (instances of {@link String}
).
*
* Caution: This list can not be modified.
*
* @return the configured list of default directory file names
*/
public static List getDefaultFiles() {
return OpenCmsCore.getInstance().getDefaultFiles();
}
/**
* Gets the default text encryption.
*
* @return the default text encryption
*/
public static I_CmsTextEncryption getDefaultTextEncryption() {
return getTextEncryptions().get("default");
}
/**
* Returns the default user and group name configuration.
*
* @return the default user and group name configuration
*/
public static CmsDefaultUsers getDefaultUsers() {
return OpenCmsCore.getInstance().getDefaultUsers();
}
/**
* Returns the event manger that handles all OpenCms events.
*
* @return the event manger that handles all OpenCms events
*/
public static CmsEventManager getEventManager() {
return OpenCmsCore.getInstance().getEventManager();
}
/**
* Gets the thread pool executor.
*
* @return the thread pool executor
*/
public static ScheduledThreadPoolExecutor getExecutor() {
return OpenCmsCore.getInstance().getExecutor();
}
/**
* Returns the configured export points,
* the returned set being an unmodifiable set.
*
* @return an unmodifiable set of the configured export points
*/
public static Set getExportPoints() {
return OpenCmsCore.getInstance().getExportPoints();
}
/**
* Returns the flex cache.
* @return the current CmsFlexCache object
*/
public static CmsFlexCache getFlexCache() {
return OpenCmsCore.getInstance().getFlexCache();
}
/**
* Creates a string containing all current flex cache keys, for use in debugging.
*
* @return the initialized import/export manager
*/
public static CmsImportExportManager getImportExportManager() {
return OpenCmsCore.getInstance().getImportExportManager();
}
/**
* Gets the LetsEncrypt configuration.
*
* Returns null if LetsEncrypt integration is not configured at all.
*
* @return the LetsEncrypt configuration
*/
public static CmsLetsEncryptConfiguration getLetsEncryptConfig() {
return OpenCmsCore.getInstance().getLetsEncryptConfig();
}
/**
* Returns the link manager to resolve links in <link> tags.
*
* @return the link manager to resolve links in <link> tags
*/
public static CmsLinkManager getLinkManager() {
return OpenCmsCore.getInstance().getLinkManager();
}
/**
* Returns the locale manager used for obtaining the current locale.
*
* @return the locale manager
*/
public static CmsLocaleManager getLocaleManager() {
return OpenCmsCore.getInstance().getLocaleManager();
}
/**
* 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.
*
* @param obj the object channel to use
* @return the log for the selected object channel
*/
public static Log getLog(Object obj) {
return CmsLog.getLog(obj);
}
/**
* Returns the login manager used to check if a login is possible.
*
* @return the login manager
*/
public static CmsLoginManager getLoginManager() {
return OpenCmsCore.getInstance().getLoginManager();
}
/**
* Returns the memory monitor.
*
* @return the memory monitor
*/
public static CmsMemoryMonitor getMemoryMonitor() {
return OpenCmsCore.getInstance().getMemoryMonitor();
}
/**
* Returns the module manager.
*
* @return the module manager
*/
public static CmsModuleManager getModuleManager() {
return OpenCmsCore.getInstance().getModuleManager();
}
/**
* Returns the organizational unit manager.
*
* @return the organizational unit manager
*/
public static CmsOrgUnitManager getOrgUnitManager() {
return OpenCmsCore.getInstance().getOrgUnitManager();
}
/**
* Returns the password handler.
*
* @return the password handler
*/
public static I_CmsPasswordHandler getPasswordHandler() {
return OpenCmsCore.getInstance().getPasswordHandler();
}
/**
* Returns the core publish manager class.
*
* @return the publish manager instance
*/
public static CmsPublishManager getPublishManager() {
return OpenCmsCore.getInstance().getPublishManager();
}
/**
* Returns the repository manager.
*
* @return the repository manager
*/
public static CmsRepositoryManager getRepositoryManager() {
return OpenCmsCore.getInstance().getRepositoryManager();
}
/**
* Returns the resource manager.
*
* @return the resource manager
*/
public static CmsResourceManager getResourceManager() {
return OpenCmsCore.getInstance().getResourceManager();
}
/**
* Returns the role manager.
*
* @return the role manager
*/
public static CmsRoleManager getRoleManager() {
return OpenCmsCore.getInstance().getRoleManager();
}
/**
* Returns the current OpenCms run level.
*
* The following runlevels are defined:
*
* - Runlevel {@link OpenCms#RUNLEVEL_0_OFFLINE}:
-
* OpenCms is in the process of being shut down, the system is offline.
*
* - Runlevel {@link OpenCms#RUNLEVEL_1_CORE_OBJECT}:
-
* OpenCms instance available, but configuration has not been processed.
* No database or VFS available.
*
* - Runlevel {@link OpenCms#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 {@link OpenCms#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 {@link OpenCms#RUNLEVEL_4_SERVLET_ACCESS}:
-
* OpenCms fully initialized, servlet and database available.
* This is the "default" when OpenCms is in normal operation.
*
*
* @return the OpenCms run level
*/
public static int getRunLevel() {
return OpenCmsCore.getInstance().getRunLevel();
}
/**
* Looks up a value in the runtime property Map.
*
* @param key the key to look up in the runtime properties
* @return the value for the key, or null if the key was not found
*/
public static Object getRuntimeProperty(Object key) {
return OpenCmsCore.getInstance().getRuntimeProperty(key);
}
/**
* Returns the configured schedule manager.
*
* @return the configured schedule manager
*/
public static CmsScheduleManager getScheduleManager() {
return OpenCmsCore.getInstance().getScheduleManager();
}
/**
* Returns the initialized search manager,
* which provides indexing and searching operations.
*
* @return the initialized search manager
*/
public static CmsSearchManager getSearchManager() {
return OpenCmsCore.getInstance().getSearchManager();
}
/**
* Returns the session manager that keeps track of the active users.
*
* @return the session manager that keeps track of the active users
*/
public static CmsSessionManager getSessionManager() {
return OpenCmsCore.getInstance().getSessionManager();
}
/**
* Returns the initialized site manager,
* which contains information about all configured sites.
*
* @return the initialized site manager
*/
public static CmsSiteManagerImpl getSiteManager() {
return OpenCmsCore.getInstance().getSiteManager();
}
/**
* Returns an instance of the common sql manager.
*
* @return an instance of the common sql manager
*/
public static CmsSqlManager getSqlManager() {
return OpenCmsCore.getInstance().getSqlManager();
}
/**
* Returns the properties for the static export.
*
* @return the properties for the static export
*/
public static CmsStaticExportManager getStaticExportManager() {
return OpenCmsCore.getInstance().getStaticExportManager();
}
/**
* Returns the subscription manager.
*
* @return the subscription manager
*/
public static CmsSubscriptionManager getSubscriptionManager() {
return OpenCmsCore.getInstance().getSubscriptionManager();
}
/**
* Returns the system information storage.
*
* @return the system information storage
*/
public static CmsSystemInfo getSystemInfo() {
return OpenCmsCore.getInstance().getSystemInfo();
}
/**
* Returns the list of system defined roles (instances of {@link CmsRole}
).
*
* Caution: This list can not be modified.
*
* @return the list of system defined roles
*/
public static List getSystemRoles() {
return CmsRole.getSystemRoles();
}
/**
* Gets the template context manager.
*
* @return the template context manager instance
*/
public static CmsTemplateContextManager getTemplateContextManager() {
return OpenCmsCore.getInstance().getTemplateContextManager();
}
/**
* Gets the map of text encryption methods, with their names as keys.
*
* @return the map of text encryption methods
*/
public static Map getTextEncryptions() {
return OpenCmsCore.getInstance().getTextEncryptions();
}
/**
* Returns the OpenCms Thread store.
*
* @return the OpenCms Thread store
*/
public static CmsThreadStore getThreadStore() {
return OpenCmsCore.getInstance().getThreadStore();
}
public static CmsUserDataRequestManager getUserDataRequestManager() {
return OpenCmsCore.getInstance().getUserDataRequestManager();
}
/**
* Returns the runtime validation handler.
*
* @return the validation handler
*/
public static I_CmsValidationHandler getValidationHandler() {
return OpenCmsCore.getInstance().getValidationHandler();
}
/**
* Gets the initialized workflow manager.
*
* @return the initialized workflow manager
*/
public static I_CmsWorkflowManager getWorkflowManager() {
return OpenCmsCore.getInstance().getWorkflowManager();
}
/**
* Returns the workplace app manager.
*
* @return the app manager
*/
public static CmsWorkplaceAppManager getWorkplaceAppManager() {
return OpenCmsCore.getInstance().getWorkplaceAppManager();
}
/**
* Returns the initialized workplace manager,
* which contains information about the global workplace settings.
*
* @return the initialized workplace manager
*/
public static CmsWorkplaceManager getWorkplaceManager() {
return OpenCmsCore.getInstance().getWorkplaceManager();
}
/**
* Returns the XML content type manager.
*
* @return the XML content type manager
*/
public static CmsXmlContentTypeManager getXmlContentTypeManager() {
return OpenCmsCore.getInstance().getXmlContentTypeManager();
}
/**
* 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.
*
* @param cms the CmsObject to create a copy of
*
* @return an independent copy of the provided CmsObject
*
* @throws CmsException in case the initialization failed
*
* @see OpenCms#initCmsObject(CmsObject)
* @see OpenCms#initCmsObject(CmsObject, CmsContextInfo)
* @see OpenCms#initCmsObject(String)
*/
public static CmsObject initCmsObject(CmsObject cms) throws CmsException {
return OpenCmsCore.getInstance().initCmsObject(cms);
}
/**
* 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.
*
* @param adminCms must either be initialized with "Admin" permissions, or null
* @param contextInfo the context info to create a CmsObject for
*
* @return an initialized CmsObject with the given users permissions
*
* @throws CmsException if an invalid user name was provided, or if something else goes wrong
*
* @see org.opencms.db.CmsDefaultUsers#getUserGuest()
* @see org.opencms.db.CmsDefaultUsers#getUserExport()
* @see OpenCms#initCmsObject(CmsObject)
* @see OpenCms#initCmsObject(CmsObject, CmsContextInfo)
* @see OpenCms#initCmsObject(String)
*/
public static CmsObject initCmsObject(CmsObject adminCms, CmsContextInfo contextInfo) throws CmsException {
return OpenCmsCore.getInstance().initCmsObject(adminCms, contextInfo);
}
/**
* 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 {@link CmsDefaultUsers#getUserAdmin()}),
* you need to get the 'Guest' user context first, then login the target user with
* his user name and password, using {@link 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.
*
* @param user the user name to initialize, can only be
* {@link org.opencms.db.CmsDefaultUsers#getUserGuest()} or
* {@link org.opencms.db.CmsDefaultUsers#getUserExport()}
*
* @return an initialized CmsObject with the given users permissions
*
* @throws CmsException if an invalid user name was provided, or if something else goes wrong
*
* @see org.opencms.db.CmsDefaultUsers#getUserGuest()
* @see org.opencms.db.CmsDefaultUsers#getUserExport()
* @see OpenCms#initCmsObject(CmsObject)
* @see OpenCms#initCmsObject(CmsObject, CmsContextInfo)
* @see OpenCms#initCmsObject(String)
*/
public static CmsObject initCmsObject(String user) throws CmsException {
return OpenCmsCore.getInstance().initCmsObject(user);
}
/**
* 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 {@link org.opencms.file.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 {@link I_CmsResourceInit}
handler
* allows to customize the process of default resource selection.
*
* @param cms the current users OpenCms context
* @param resourceName the path of the requested resource in the OpenCms VFS
* @param req the current http request
* @param res the current http response
* @return the requested resource read from the VFS
*
* @throws CmsException in case the requested file does not exist or the user has insufficient access permissions
*/
public static CmsResource initResource(
CmsObject cms,
String resourceName,
HttpServletRequest req,
HttpServletResponse res)
throws CmsException {
return OpenCmsCore.getInstance().initResource(cms, resourceName, req, res);
}
/**
* Removes a cms event listener.
*
* @param listener the listener to remove
*/
public static void removeCmsEventListener(I_CmsEventListener listener) {
OpenCmsCore.getInstance().getEventManager().removeCmsEventListener(listener);
}
/**
* 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.
*
* @param key the key to add the Object with
* @param value the value of the Object to add
*/
public static void setRuntimeProperty(Object key, Object value) {
OpenCmsCore.getInstance().setRuntimeProperty(key, value);
}
/**
* Writes the XML configuration for the provided configuration class.
*
* @param clazz the configuration class to write the XML for
*/
public static void writeConfiguration(Class> clazz) {
OpenCmsCore.getInstance().writeConfiguration(clazz);
}
}