Class OpenCmsCore


  • public final class OpenCmsCore
    extends java.lang.Object
    The internal implementation of the core OpenCms "operating system" functions.

    All access to this class must be done through the public static methods of the OpenCms object. Under no circumstances should you ever try to access this class directly.

    This class is so OpenCms internal you should not even be reading this documentation ;-)

    Any request to the OpenCmsServlet will be forwarded to this core class. The core will then try to map the request to a VFS (Virtual File System) URI, that is a CmsResource in the OpenCms database. If a resource is found, it will be read and forwarded to to the corresponding I_CmsResourceLoader, which will then generate the output for the requested resource and return it to the requesting client.

    There will be only one singleton instance of this object created for this core class. This means that in the default configuration, where OpenCms is accessed through a servlet context, there will be only one instance of the core in that servlet context.

    Since:
    6.0.0
    • Method Detail

      • getPathInfo

        public static java.lang.String getPathInfo​(javax.servlet.http.HttpServletRequest req)
        Returns the path for the request.

        First checks the HttpServletRequest.getPathInfo(), then the configured request error page attribute (if set), and then if still undefined the / is returned as path info.

        This is only needed when the HttpServletRequest.getPathInfo() is not really working as expected like in BEA WLS 9.x, where we have to use the 'weblogic.servlet.errorPage' request attribute.

        Parameters:
        req - the http request context
        Returns:
        the path for the request
      • getInstance

        protected static OpenCmsCore getInstance()
        Returns the initialized OpenCms singleton instance.

        Returns:
        the initialized OpenCms singleton instance
      • setErrorCondition

        protected static void setErrorCondition​(CmsMessageContainer errorCondition)
        Sets the error condition.

        Parameters:
        errorCondition - the error condition to set
      • addRequestHandler

        protected void addRequestHandler​(I_CmsRequestHandler handler)
        Adds the specified request handler to the Map of OpenCms request handlers.

        Parameters:
        handler - the handler to add
      • getADEManager

        protected CmsADEManager getADEManager()
        Gets the ADE manager, and makes sure it is initialized.

        Returns:
        the initialized ADE manager
      • getApiAuthorization

        protected I_CmsApiAuthorizationHandler getApiAuthorization​(java.lang.String name)
        Gets the API authorization handler with the given name, or null if it doesn't exist.
        Parameters:
        name - the name of the API authorization handler
        Returns:
        the API authorization handler, or null if it wasn't found
      • getDbPoolNames

        protected java.util.List<java.lang.String> getDbPoolNames()
        Gets the database pool names.

        Returns:
        the configured database pool names
      • getDefaultFiles

        protected java.util.List<java.lang.String> getDefaultFiles()
        Returns the configured list of default directory file names.

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

        protected CmsDefaultUsers getDefaultUsers()
        Returns the default user and group name configuration.

        Returns:
        the default user and group name configuration
      • getExecutor

        protected java.util.concurrent.ScheduledThreadPoolExecutor getExecutor()
        Gets the thread pool executor.

        Returns:
        the thread pool executor
      • getExportPoints

        protected java.util.Set<CmsExportPointgetExportPoints()
        Returns the configured export points, the returned set being an unmodifiable set.

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

        protected java.lang.String getFlexCacheKeyDump()
        Gets a string containing all keys and variations currently in the flex cache, for debug purposes.

        Returns:
        a debug information string with the flex cache data
      • getImportExportManager

        protected CmsImportExportManager getImportExportManager()
        Returns the initialized import/export manager, which contains information about the Cms import/export.

        Returns:
        the initialized import/export manager
      • getLinkManager

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

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

        protected CmsLocaleManager getLocaleManager()
        Returns the locale manager used for obtaining the current locale.

        Returns:
        the locale manager
      • getLockManager

        protected CmsLockManager getLockManager()
        Returns the lock manager used for the locking mechanism.

        Returns:
        the lock manager used for the locking mechanism
      • getLoginManager

        protected CmsLoginManager getLoginManager()
        Returns the login manager used to check the validity of a login.

        Returns:
        the login manager
      • getRequestHandler

        protected I_CmsRequestHandler getRequestHandler​(java.lang.String name)
        Returns the handler instance for the specified name, or null if the name does not match any handler name.

        Parameters:
        name - the name of the handler instance to return
        Returns:
        the handler instance for the specified name
      • getRunLevel

        protected int getRunLevel()
        Returns the runlevel of this OpenCmsCore object instance.

        For a detailed description about the possible run levels, please see OpenCms.getRunLevel().

        Returns:
        the runlevel of this OpenCmsCore object instance
        See Also:
        OpenCms.getRunLevel()
      • getRuntimeProperty

        protected 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
      • getSearchManager

        protected CmsSearchManager getSearchManager()
        Returns the initialized search manager, which provides indexing and searching operations.

        Returns:
        the initialized search manager
      • getSiteManager

        protected CmsSiteManagerImpl getSiteManager()
        Returns the initialized site manager, which contains information about all configured sites.

        Returns:
        the initialized site manager
      • getSqlManager

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

        Returns:
        an instance of the common sql manager
      • getSystemInfo

        protected CmsSystemInfo getSystemInfo()
        Returns the system information storage.

        Returns:
        the system information storage
      • getWorkplaceManager

        protected CmsWorkplaceManager getWorkplaceManager()
        Returns the initialized workplace manager, which contains information about the global workplace settings.

        Returns:
        the initialized workplace manager
      • initCmsContextForUI

        protected void initCmsContextForUI​(javax.servlet.http.HttpServletRequest req,
                                           javax.servlet.http.HttpServletResponse res,
                                           CmsUIServlet servlet)
                                    throws java.io.IOException,
                                           CmsException
        Initializes the OpenCms context for Vaadin UI servlet.

        Parameters:
        req - the request
        res - the response
        servlet - the UI servlet
        Throws:
        java.io.IOException - if user authentication fails
        CmsException - if something goes wrong
      • initCmsObject

        protected CmsObject initCmsObject​(javax.servlet.http.HttpServletRequest req,
                                          javax.servlet.http.HttpServletResponse res,
                                          boolean allowPrivilegedLogin)
                                   throws java.io.IOException,
                                          CmsException
        Handles the user authentification for each request sent to OpenCms.

        User authentification is done in three steps:

        1. Session authentification: OpenCms stores information of all authentificated users in an internal storage based on the users session.
        2. Authorization handler authentification: If the session authentification fails, the current configured authorization handler is called.
        3. Default user: When both authentification methods fail, the user is set to the default (Guest) user.
        Parameters:
        req - the current http request
        res - the current http response
        allowPrivilegedLogin - true to allow login through authorization handlers
        Returns:
        the initialized cms context
        Throws:
        java.io.IOException - if user authentication fails
        CmsException - in case something goes wrong
      • initCmsObjectFromSession

        protected CmsObject initCmsObjectFromSession​(javax.servlet.http.HttpServletRequest req)
                                              throws CmsException
        Initializes a new cms object from the session data of the request.

        If no session data is found, null is returned.

        Parameters:
        req - the request
        Returns:
        the new initialized cms object
        Throws:
        CmsException - if something goes wrong
      • initConfiguration

        protected void initConfiguration​(CmsParameterConfiguration configuration)
                                  throws CmsInitException
        Constructor to create a new OpenCms object.

        It reads the configurations from the opencms.properties file in the config/ subdirectory. With the information from this file is inits a ResourceBroker (Database access module), various caching systems and other options.

        This will only be done once per accessing class.

        Parameters:
        configuration - the configurations from the opencms.properties file
        Throws:
        CmsInitException - in case OpenCms can not be initialized
      • initContext

        protected void initContext​(javax.servlet.ServletContext context)
                            throws CmsInitException
        Initialization of the OpenCms runtime environment.

        The connection information for the database is read from the opencms.properties configuration file and all driver manager are initialized via the initializer, which usually will be an instance of a OpenCms class.

        Parameters:
        context - configuration of OpenCms from web.xml
        Throws:
        CmsInitException - in case OpenCms can not be initialized
      • initMembers

        protected void initMembers()
        Initialize member variables.

      • initResource

        protected 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, 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. If there is no default file in a folder, then the return value is null and no CmsException is thrown.

        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
        See Also:
        OpenCms.initResource(CmsObject, String, HttpServletRequest, HttpServletResponse)
      • initServlet

        protected void initServlet​(OpenCmsServlet servlet)
        Initializes the system with the OpenCms servlet.

        This is the final step that is called on the servlets "init()" method. It registers the servlets request handler and also outputs the final startup message. The servlet should auto-load since the <load-on-startup> parameter is set in the 'web.xml' by default.

        Parameters:
        servlet - the OpenCms servlet
      • invokeBuiltinService

        protected void invokeBuiltinService​(java.lang.String remainingPath,
                                            javax.servlet.http.HttpServletRequest req,
                                            javax.servlet.http.HttpServletResponse res)
                                     throws javax.servlet.ServletException
        Handler for built-in AJAX services that don't belong anywhere else and don't deserve their own request handler.
        Parameters:
        remainingPath - the remainder of the path after /handleBuiltinService
        req - the current request
        res - the current response
        Throws:
        javax.servlet.ServletException - if something goes wrong
      • invokeGwtService

        protected void invokeGwtService​(java.lang.String serviceName,
                                        javax.servlet.http.HttpServletRequest req,
                                        javax.servlet.http.HttpServletResponse res,
                                        javax.servlet.ServletConfig servletConfig)
        Invokes the GWT servlet from within OpenCms.

        Parameters:
        serviceName - the GWT PRC service class name
        req - the current servlet request
        res - the current servlet response
        servletConfig - the servlet configuration
      • setRuntimeProperty

        protected 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
      • showResource

        protected void showResource​(javax.servlet.http.HttpServletRequest req,
                                    javax.servlet.http.HttpServletResponse res)
        Displays a resource from the OpenCms by writing the result to the provided Servlet response output stream.

        Parameters:
        req - the current servlet request
        res - the current servlet response
      • shutDown

        protected void shutDown()
        Destroys this OpenCms instance, called if the servlet (or shell) is shut down.

      • updateContext

        protected CmsObject updateContext​(javax.servlet.http.HttpServletRequest request,
                                          CmsObject cms)
                                   throws CmsException
        This method updates the request context information.

        The update information is:

        • Requested Url
        • Locale
        • Encoding
        • Remote Address
        • Request Time
        Parameters:
        request - the current request
        cms - the cms object to update the request context for
        Returns:
        a new updated cms context
        Throws:
        CmsException - if something goes wrong
      • writeConfiguration

        protected 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