Class CmsSiteManagerImpl

    • Method Detail

      • createAliasSiteMatcher

        public static CmsSiteMatcher createAliasSiteMatcher​(java.lang.String alias,
                                                            java.lang.String redirect,
                                                            java.lang.String offset)
        Creates a site matcher for an alias read from the configuration.
        Parameters:
        alias - the alias
        redirect - redirection enabled (true/false)
        offset - time offset or empty
        Returns:
        the alias site matcher
      • addSite

        public void addSite​(java.lang.String server,
                            java.lang.String uri,
                            java.lang.String title,
                            java.lang.String position,
                            java.lang.String errorPage,
                            java.lang.String webserver,
                            java.lang.String sslMode,
                            java.lang.String secureServer,
                            java.lang.String exclusive,
                            java.lang.String error,
                            java.lang.String usePermanentRedirects,
                            java.lang.String subsiteSelection,
                            java.util.SortedMap<java.lang.String,​java.lang.String> params,
                            java.util.List<CmsSiteMatcher> aliases,
                            java.util.Optional<CmsAlternativeSiteRootMapping> alternativeSiteRootMapping)
                     throws CmsConfigurationException
        Adds a new CmsSite to the list of configured sites, this is only allowed during configuration.

        If this method is called after the configuration is finished, a RuntimeException is thrown.

        Parameters:
        server - the Server
        uri - the VFS path
        title - the display title for this site
        position - the display order for this site
        errorPage - the URI to use as error page for this site
        sslMode - the SSLMode of the site
        webserver - indicates whether to write the web server configuration for this site or not
        secureServer - a secure server, can be null
        exclusive - if set to true, secure resources will only be available using the configured secure url
        error - if exclusive, and set to true will generate a 404 error, if set to false will redirect to secure URL
        usePermanentRedirects - if set to "true", permanent redirects should be used when redirecting to the secure URL
        subsiteSelection - true if subsite selection should be enabled
        params - the site parameters
        aliases - the aliases for the site
        alternativeSiteRootMapping - an optional alternative site root mapping
        Throws:
        CmsConfigurationException - if the site contains a server name, that is already assigned
      • addSiteInternally

        public void addSiteInternally​(java.lang.String server,
                                      java.lang.String uri,
                                      java.lang.String title,
                                      java.lang.String position,
                                      java.lang.String errorPage,
                                      java.lang.String webserver,
                                      java.lang.String sslMode,
                                      java.lang.String secureServer,
                                      java.lang.String exclusive,
                                      java.lang.String error,
                                      java.lang.String usePermanentRedirects,
                                      java.lang.String subsiteSelection,
                                      java.util.SortedMap<java.lang.String,​java.lang.String> params,
                                      java.util.List<CmsSiteMatcher> aliases,
                                      java.util.Optional<CmsAlternativeSiteRootMapping> alternativeSiteRoot)
                               throws CmsConfigurationException
        Adds a new CmsSite to the list of configured sites, this is only allowed during configuration.

        If this method is called after the configuration is finished, a RuntimeException is thrown.

        Parameters:
        server - the Server
        uri - the VFS path
        title - the display title for this site
        position - the display order for this site
        errorPage - the URI to use as error page for this site
        sslMode - the SSLMode of the site
        webserver - indicates whether to write the web server configuration for this site or not
        secureServer - a secure server, can be null
        exclusive - if set to true, secure resources will only be available using the configured secure url
        error - if exclusive, and set to true will generate a 404 error, if set to false will redirect to secure URL
        usePermanentRedirects - if set to "true", permanent redirects should be used when redirecting to the secure URL
        subsiteSelection - true if subsite selection should be enabled for this site
        params - the site parameters
        aliases - the aliases
        alternativeSiteRoot - an optional alternative site root mapping
        Throws:
        CmsConfigurationException - in case the site was not configured correctly
      • addWorkplaceServer

        public void addWorkplaceServer​(java.lang.String workplaceServer,
                                       java.lang.String sslmode)
        Adds a workplace server, this is only allowed during configuration.

        Parameters:
        workplaceServer - the workplace server
        sslmode - CmsSSLMode of workplace server
      • getAvailableCorruptedSites

        public java.util.List<CmsSitegetAvailableCorruptedSites​(CmsObject cms,
                                                                  boolean workplaceMode)
        Returns all wrong configured sites.

        Parameters:
        cms - CmsObject
        workplaceMode - workplace mode
        Returns:
        List of CmsSite
      • getAvailableSites

        public java.util.List<CmsSitegetAvailableSites​(CmsObject cms,
                                                         boolean workplaceMode)
        Returns a list of all sites available (visible) for the current user.

        Parameters:
        cms - the current OpenCms user context
        workplaceMode - if true, the root and current site is included for the admin user and the view permission is required to see the site root
        Returns:
        a list of all sites available for the current user
      • getAvailableSites

        public java.util.List<CmsSitegetAvailableSites​(CmsObject cms,
                                                         boolean workplaceMode,
                                                         boolean showShared,
                                                         java.lang.String ouFqn)
        Returns a list of all CmsSite instances that are compatible to the given organizational unit.

        Parameters:
        cms - the current OpenCms user context
        workplaceMode - if true, the root and current site is included for the admin user and the view permission is required to see the site root
        showShared - if the shared folder should be shown
        ouFqn - the organizational unit
        Returns:
        a list of all site available for the current user
      • getAvailableSites

        public java.util.List<CmsSitegetAvailableSites​(CmsObject cms,
                                                         boolean workplaceMode,
                                                         boolean showShared,
                                                         java.lang.String ouFqn,
                                                         CmsSSLMode filterMode)
        Returns a list of all CmsSite instances that are compatible to the given organizational unit.

        Parameters:
        cms - the current OpenCms user context
        workplaceMode - if true, the root and current site is included for the admin user and the view permission is required to see the site root
        showShared - if the shared folder should be shown
        ouFqn - the organizational unit
        filterMode - The CmsSLLMode to filter, null if no filter
        Returns:
        a list of all site available for the current user
      • getAvailableSites

        public java.util.List<CmsSitegetAvailableSites​(CmsObject cms,
                                                         boolean workplaceMode,
                                                         CmsSSLMode filterMode)
        Returns a list of all sites available (visible) for the current user.

        Parameters:
        cms - the current OpenCms user context
        workplaceMode - if true, the root and current site is included for the admin user and the view permission is required to see the site root
        filterMode - The CmsSLLMode to filter, null if no filter
        Returns:
        a list of all sites available for the current user
      • getAvailableSites

        public java.util.List<CmsSitegetAvailableSites​(CmsObject cms,
                                                         boolean workplaceMode,
                                                         java.lang.String ouFqn)
        Returns a list of all CmsSite instances that are compatible to the given organizational unit.

        Parameters:
        cms - the current OpenCms user context
        workplaceMode - if true, the root and current site is included for the admin user and the view permission is required to see the site root
        ouFqn - the organizational unit
        Returns:
        a list of all site available for the current user
      • getCurrentSite

        public CmsSite getCurrentSite​(CmsObject cms)
        Returns the current site for the provided OpenCms user context object.

        In the unlikely case that no site matches with the provided OpenCms user context, the default site is returned.

        Parameters:
        cms - the OpenCms user context object to check for the site
        Returns:
        the current site for the provided OpenCms user context object
      • getDefaultUri

        public java.lang.String getDefaultUri()
        Returns the defaultUri.

        Returns:
        the defaultUri
      • getSharedFolder

        public java.lang.String getSharedFolder()
        Returns the shared folder path.

        Returns:
        the shared folder path
      • getSite

        public CmsSite getSite​(java.lang.String rootPath,
                               java.lang.String fallbackSiteRoot)
        Returns the site for the given resource path, using the fall back site root in case the resource path is no root path.

        In case neither the given resource path, nor the given fall back site root matches any configured site, the default site is returned.

        Usually the fall back site root should be taken from CmsRequestContext.getSiteRoot(), in which case a site for the site root should always exist.

        This is the same as first calling getSiteForRootPath(String) with the resourcePath parameter, and if this fails calling getSiteForSiteRoot(String) with the fallbackSiteRoot parameter, and if this fails calling getDefaultSite().

        Parameters:
        rootPath - the resource root path to get the site for
        fallbackSiteRoot - site root to use in case the resource path is no root path
        Returns:
        the site for the given resource path, using the fall back site root in case the resource path is no root path
        See Also:
        getSiteForRootPath(String)
      • getSiteForDefaultUri

        public com.google.common.base.Optional<CmsSitegetSiteForDefaultUri()
        Gets the site which is mapped to the default uri, or the 'absent' value of no such site exists.

        Returns:
        the optional site mapped to the default uri
      • getSiteForRootPath

        public CmsSite getSiteForRootPath​(java.lang.String rootPath)
        Returns the site for the given resources root path, or null if the resources root path does not match any site.

        Parameters:
        rootPath - the root path of a resource
        Returns:
        the site for the given resources root path, or null if the resources root path does not match any site
        See Also:
        getSiteForSiteRoot(String), getSiteRoot(String)
      • getSiteForSiteRoot

        public CmsSite getSiteForSiteRoot​(java.lang.String siteRoot)
        Returns the site with has the provided site root, or null if no configured site has that site root.

        The site root must have the form: /sites/default.
        That means there must be a leading, but no trailing slash.

        Parameters:
        siteRoot - the site root to look up the site for
        Returns:
        the site with has the provided site root, or null if no configured site has that site root
        See Also:
        getSiteForRootPath(String)
      • getSiteRoot

        public java.lang.String getSiteRoot​(java.lang.String rootPath)
        Returns the site root part for the given resources root path, or null if the given resources root path does not match any site root.

        The site root returned will have the form: /sites/default.
        That means there will a leading, but no trailing slash.

        Parameters:
        rootPath - the root path of a resource
        Returns:
        the site root part of the resources root path, or null if the path does not match any site root
        See Also:
        getSiteForRootPath(String)
      • getSiteRoots

        public java.util.Set<java.lang.String> getSiteRoots()
        Returns an unmodifiable set of all configured site roots (Strings).

        Returns:
        an unmodifiable set of all configured site roots (Strings)
      • getSiteTitle

        public java.lang.String getSiteTitle​(CmsObject cms,
                                             CmsResource resource)
                                      throws CmsException
        Returns the site title.

        Parameters:
        cms - the cms context
        resource - the site root resource
        Returns:
        the title
        Throws:
        CmsException - in case reading the title property fails
      • getSSLModeForWorkplaceServer

        public CmsSSLMode getSSLModeForWorkplaceServer​(java.lang.String server)
        Gets the SSLMode for given workplace server.

        Parameters:
        server - to obtain ssl mode for
        Returns:
        CmsSSLMode
      • getWebServerConfig

        public java.util.Map<java.lang.String,​java.lang.String> getWebServerConfig()
        Get web server scripting configurations.

        Returns:
        Map with configuration data
      • getWorkplaceServer

        public java.lang.String getWorkplaceServer()
        Returns the workplace server.

        Returns:
        the workplace server
      • getWorkplaceServer

        public java.lang.String getWorkplaceServer​(CmsObject cms)
        Gets the first configured workplace server that matches the host from the current CmsRequestContext, or the first configured workplace server if there is no match.

        If there are no workplace configured at all, null is returned.

        Parameters:
        cms - the CmsObject used to check the host
        Returns:
        the workplace server
      • getWorkplaceServers

        public java.util.List<java.lang.String> getWorkplaceServers()
        Returns the configured worklace servers.

        Returns:
        the workplace servers
      • getWorkplaceServers

        public java.util.List<java.lang.String> getWorkplaceServers​(CmsSSLMode filterMode)
        Returns the configured worklace servers.

        Parameters:
        filterMode - CmsSSLMode to filter results for.
        Returns:
        the workplace servers
      • getWorkplaceServersMap

        public java.util.Map<java.lang.String,​CmsSSLModegetWorkplaceServersMap()
        Returns the configured worklace servers.

        Returns:
        the workplace servers
      • getWorkplaceSiteMatcher

        public CmsSiteMatcher getWorkplaceSiteMatcher()
        Returns the site matcher that matches the workplace site.

        Returns:
        the site matcher that matches the workplace site
      • initialize

        public void initialize​(CmsObject cms)
        Initializes the site manager with the OpenCms system configuration.

        Parameters:
        cms - an OpenCms context object that must have been initialized with "Admin" permissions
      • isConfigurableWebServer

        public boolean isConfigurableWebServer()
        Checks if web server scripting is enabled.

        Returns:
        true if web server scripting is set to available
      • isMatching

        public boolean isMatching​(CmsSiteMatcher matcher)
        Returns true if the given site matcher matches any configured site, which includes the workplace site.

        Parameters:
        matcher - the site matcher to match the site with
        Returns:
        true if the matcher matches a site
      • isMatchingCurrentSite

        public boolean isMatchingCurrentSite​(CmsObject cms,
                                             CmsSiteMatcher matcher)
        Returns true if the given site matcher matches the current site.

        Parameters:
        cms - the current OpenCms user context
        matcher - the site matcher to match the site with
        Returns:
        true if the matcher matches the current site
      • isOnlyOfflineSite

        public boolean isOnlyOfflineSite​(CmsSite site)
        Indicates if given site is only available for offline repository.

        Parameters:
        site - to be looked up
        Returns:
        true if only offline exists, false otherwise
      • isSharedFolder

        public boolean isSharedFolder​(java.lang.String name)
        Checks if the given path is that of a shared folder.

        Parameters:
        name - a path prefix
        Returns:
        true if the given prefix represents a shared folder
      • isSiteRoot

        public boolean isSiteRoot​(java.lang.String rootPath)
        Checks whether a given root path is a site root.

        Parameters:
        rootPath - a root path
        Returns:
        true if the given path is the path of a site root
      • isSiteUnderSite

        public boolean isSiteUnderSite​(CmsSite site)
        Checks if a given site is under another site.

        Parameters:
        site - CmsSite to check
        Returns:
        true if given site is invalid
      • isSiteUnderSite

        public boolean isSiteUnderSite​(java.lang.String siteRootPath)
        Checks if a given site is under another site.

        Parameters:
        siteRootPath - site root path to check
        Returns:
        true if given site is invalid
      • isWorkplaceRequest

        public boolean isWorkplaceRequest​(CmsSiteMatcher matcher)
        Returns true if the given site matcher matches the configured OpenCms workplace.

        Parameters:
        matcher - the site matcher to match the site with
        Returns:
        true if the given site matcher matches the configured OpenCms workplace
      • isWorkplaceRequest

        public boolean isWorkplaceRequest​(javax.servlet.http.HttpServletRequest req)
        Returns true if the given request is against the configured OpenCms workplace.

        Parameters:
        req - the request to match
        Returns:
        true if the given request is against the configured OpenCms workplace
      • matchRequest

        public CmsSite matchRequest​(javax.servlet.http.HttpServletRequest req)
        Matches the given request against all configures sites and returns the matching site, or the default site if no sites matches.

        Parameters:
        req - the request to match
        Returns:
        the matching site, or the default site if no sites matches
      • matchSite

        public CmsSite matchSite​(CmsSiteMatcher matcher)
        Return the configured site that matches the given site matcher, or the default site if no sites matches.

        Does NOT match auto-generated sites from alternative site root mappings, since the site matcher does not contain path information.

        Parameters:
        matcher - the site matcher to match the site with
        Returns:
        the matching site, or the default site if no sites matches
      • setDefaultUri

        public void setDefaultUri​(java.lang.String defaultUri)
        Sets the default URI, this is only allowed during configuration.

        If this method is called after the configuration is finished, a RuntimeException is thrown.

        Parameters:
        defaultUri - the defaultUri to set
      • setOldStyleSecureServerAllowed

        public void setOldStyleSecureServerAllowed​(java.lang.String value)
        Sets the old style secure server boolean.

        Parameters:
        value - value
      • setSharedFolder

        public void setSharedFolder​(java.lang.String sharedFolder)
        Sets the shared folder path.

        Parameters:
        sharedFolder - the shared folder path
      • setWebServerScripting

        public void setWebServerScripting​(java.lang.String webserverscript,
                                          java.lang.String targetpath,
                                          java.lang.String configtemplate,
                                          java.lang.String securetemplate,
                                          java.lang.String filenameprefix,
                                          java.lang.String loggingdir)
        Set webserver script configuration.

        Parameters:
        webserverscript - path
        targetpath - path
        configtemplate - path
        securetemplate - path
        filenameprefix - to add to files
        loggingdir - path
      • startsWithShared

        public boolean startsWithShared​(java.lang.String path)
        Returns true if the path starts with the shared folder path.

        Parameters:
        path - the path to check
        Returns:
        true if the path starts with the shared folder path
      • updateGeneralSettings

        public void updateGeneralSettings​(CmsObject cms,
                                          java.lang.String defaultUri,
                                          java.util.List<java.lang.String> workplaceServersList,
                                          java.lang.String sharedFolder)
                                   throws CmsException
        Method for backward compability reasons. Not sure if really needed //TODO check! CmsSSLMode are set to No as default.

        Parameters:
        cms - the cms to use
        defaultUri - the default URI
        workplaceServersList - the workplace server URLs
        sharedFolder - the shared folder URI
        Throws:
        CmsException - if something goes wrong
      • updateGeneralSettings

        public void updateGeneralSettings​(CmsObject cms,
                                          java.lang.String defaulrUri,
                                          java.util.Map<java.lang.String,​CmsSSLMode> workplaceServers,
                                          java.lang.String sharedFolder)
                                   throws CmsException
        Updates the general settings.

        Parameters:
        cms - the cms to use
        defaulrUri - the default URI
        workplaceServers - the workplace server URLs
        sharedFolder - the shared folder URI
        Throws:
        CmsException - if something goes wrong
      • updateSite

        public void updateSite​(CmsObject cms,
                               CmsSite oldSite,
                               CmsSite newSite)
                        throws CmsException
        Updates or creates a site.

        Parameters:
        cms - the CMS object
        oldSite - the site to remove if not null
        newSite - the site to add if not null
        Throws:
        CmsException - if something goes wrong
      • usesSecureSite

        public boolean usesSecureSite​(javax.servlet.http.HttpServletRequest req)
        Returns true if this request goes to a secure site.

        Parameters:
        req - the request to check
        Returns:
        true if the request goes to a secure site
      • validateSiteRoot

        public void validateSiteRoot​(java.lang.String siteRoot)
        Validates the site root, throwing an exception if the validation fails.
        Parameters:
        siteRoot - the site root to check