Class CmsSiteManagerImpl

java.lang.Object
org.opencms.site.CmsSiteManagerImpl
All Implemented Interfaces:
I_CmsEventListener

public final class CmsSiteManagerImpl extends Object implements I_CmsEventListener
Manages all configured sites in OpenCms.

To obtain the configured site manager instance, use OpenCms.getSiteManager().

Since:
7.0.2
  • Field Details

  • Constructor Details

  • Method Details

    • createAliasSiteMatcher

      public static CmsSiteMatcher createAliasSiteMatcher(String alias, String redirect, 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(CmsObject cms, CmsSite site) throws CmsException
      Adds a site.

      Parameters:
      cms - the CMS object
      site - the site to add
      Throws:
      CmsException - if something goes wrong
    • addSite

      public void addSite(String server, String uri, String title, String position, String errorPage, String webserver, String sslMode, String secureServer, String exclusive, String error, String usePermanentRedirects, String subsiteSelection, SortedMap<String,String> params, List<CmsSiteMatcher> aliases, 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(String server, String uri, String title, String position, String errorPage, String webserver, String sslMode, String secureServer, String exclusive, String error, String usePermanentRedirects, String subsiteSelection, SortedMap<String,String> params, List<CmsSiteMatcher> aliases, 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(String workplaceServer, String sslmode)
      Adds a workplace server, this is only allowed during configuration.

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

      public void cmsEvent(CmsEvent event)
      Description copied from interface: I_CmsEventListener
      Acknowledge the occurrence of the specified event, implement this method to check for CmsEvents in your class.
      Specified by:
      cmsEvent in interface I_CmsEventListener
      Parameters:
      event - CmsEvent that has occurred
      See Also:
    • getAvailableCorruptedSites

      public List<CmsSite> getAvailableCorruptedSites(CmsObject cms, boolean workplaceMode)
      Returns all wrong configured sites.

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

      public List<CmsSite> getAvailableSites(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 List<CmsSite> getAvailableSites(CmsObject cms, boolean workplaceMode, boolean showShared, 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 List<CmsSite> getAvailableSites(CmsObject cms, boolean workplaceMode, boolean showShared, 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 List<CmsSite> getAvailableSites(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 List<CmsSite> getAvailableSites(CmsObject cms, boolean workplaceMode, 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

      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
    • getDefaultSite

      Returns the default site.

      Returns:
      the default site
    • getDefaultUri

      Returns the defaultUri.

      Returns:
      the defaultUri
    • getSharedFolder

      Returns the shared folder path.

      Returns:
      the shared folder path
    • getSite

      public CmsSite getSite(String rootPath, 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:
    • getSiteForDefaultUri

      public com.google.common.base.Optional<CmsSite> getSiteForDefaultUri()
      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(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

      public CmsSite getSiteForSiteRoot(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:
    • getSiteRoot

      public String getSiteRoot(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:
    • getSiteRoots

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

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

      Returns the map of configured sites, using CmsSiteMatcher objects as keys and CmsSite objects as values.

      Returns:
      the map of configured sites, using CmsSiteMatcher objects as keys and CmsSite objects as values
    • getSiteTitle

      public 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

      Gets the SSLMode for given workplace server.

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

      Get web server scripting configurations.

      Returns:
      Map with configuration data
    • getWorkplaceServer

      Returns the workplace server.

      Returns:
      the workplace server
    • getWorkplaceServer

      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

      Returns the configured worklace servers.

      Returns:
      the workplace servers
    • getWorkplaceServers

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

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

      Returns the configured worklace servers.

      Returns:
      the workplace servers
    • 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
    • isOldStyleSecureServerAllowed

      Checks if old style secure server is allowed.

      Returns:
      boolean
    • 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(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(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(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
    • removeSite

      public void removeSite(CmsObject cms, CmsSite site) throws CmsException
      Removes a site from the list of configured sites.

      Parameters:
      cms - the cms object
      site - the site to remove
      Throws:
      CmsException - if something goes wrong
    • setDefaultUri

      public void setDefaultUri(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

      Sets the old style secure server boolean.

      Parameters:
      value - value
    • setSharedFolder

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

      Parameters:
      sharedFolder - the shared folder path
    • setWebServerScripting

      public void setWebServerScripting(String webserverscript, String targetpath, String configtemplate, String securetemplate, String filenameprefix, 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(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, String defaultUri, List<String> workplaceServersList, 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, String defaulrUri, Map<String,CmsSSLMode> workplaceServers, 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(String siteRoot)
      Validates the site root, throwing an exception if the validation fails.
      Parameters:
      siteRoot - the site root to check