org.opencms.site
Class CmsSiteManagerImpl

java.lang.Object
  extended by org.opencms.site.CmsSiteManagerImpl

public final class CmsSiteManagerImpl
extends java.lang.Object

Manages all configured sites in OpenCms.

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

Since:
7.0.2
Version:
$Revision: 1.12 $
Author:
Alexander Kandzior

Constructor Summary
CmsSiteManagerImpl()
          Creates a new CmsSiteManager.
 
Method Summary
 void addAliasToConfigSite(java.lang.String alias, java.lang.String offset)
          Adds an alias to the currently configured site.
 void addSite(java.lang.String server, java.lang.String uri, java.lang.String secureServer, java.lang.String exclusive, java.lang.String error)
          Adds a new CmsSite to the list of configured sites, this is only allowed during configuration.
 java.util.List getAvailableSites(CmsObject cms, boolean workplaceMode)
          Returns a list of all sites available for the current user.
 java.util.List getAvailableSites(CmsObject cms, boolean workplaceMode, java.lang.String ouFqn)
          Returns a list of all CmsSite instances that are compatible to the given organizational unit.
 CmsSite getCurrentSite(CmsObject cms)
          Returns the current site for the provided OpenCms user context object.
 CmsSite getDefaultSite()
          Returns the default site.
 java.lang.String getDefaultUri()
          Returns the defaultUri.
 CmsSite getSite(java.lang.String siteRoot)
          Deprecated. use getSiteForSiteRoot(String) instead
 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.
 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.
 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.
 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.
 java.util.Set getSiteRoots()
          Returns an unmodifiable set of all configured site roots (Strings).
 java.util.Map getSites()
          Returns the map of configured sites, using CmsSiteMatcher objects as keys and CmsSite objects as values.
 java.lang.String getWorkplaceServer()
          Returns the workplace server.
 CmsSiteMatcher getWorkplaceSiteMatcher()
          Returns the site matcher that matches the workplace site.
 void initialize(CmsObject cms)
          Initializes the site manager with the OpenCms system configuration.
 boolean isMatching(CmsSiteMatcher matcher)
          Returns true if the given site matcher matches any configured site, which includes the workplace site.
 boolean isMatchingCurrentSite(CmsObject cms, CmsSiteMatcher matcher)
          Returns true if the given site matcher matches the current site.
 boolean isWorkplaceRequest(CmsSiteMatcher matcher)
          Returns true if the given site matcher matches the configured OpenCms workplace.
 boolean isWorkplaceRequest(javax.servlet.http.HttpServletRequest req)
          Returns true if the given request is against the configured OpenCms workplace.
 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.
 CmsSite matchSite(CmsSiteMatcher matcher)
          Return the configured site that matches the given site matcher, or the default site if no sites matches.
 void setDefaultUri(java.lang.String defaultUri)
          Sets the default URI, this is only allowed during configuration.
 void setWorkplaceServer(java.lang.String workplaceServer)
          Sets the workplace server, this is only allowed during configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsSiteManagerImpl

public CmsSiteManagerImpl()
Creates a new CmsSiteManager.

Method Detail

addAliasToConfigSite

public void addAliasToConfigSite(java.lang.String alias,
                                 java.lang.String offset)
Adds an alias to the currently configured site.

Parameters:
alias - the URL of the alias server
offset - the optional time offset for this alias

addSite

public void addSite(java.lang.String server,
                    java.lang.String uri,
                    java.lang.String secureServer,
                    java.lang.String exclusive,
                    java.lang.String error)
             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
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
Throws:
CmsConfigurationException - if the site contains a server name, that is already assigned

getAvailableSites

public java.util.List getAvailableSites(CmsObject cms,
                                        boolean workplaceMode)
Returns a list of all sites available 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 site available for the current user

getAvailableSites

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

getDefaultSite

public CmsSite getDefaultSite()
Returns the default site.

Returns:
the default site

getDefaultUri

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

Returns:
the defaultUri

getSite

public CmsSite getSite(java.lang.String siteRoot)
Deprecated. use getSiteForSiteRoot(String) instead

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:
getSiteForSiteRoot(String)

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)

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 getSiteRoots()
Returns an unmodifiable set of all configured site roots (Strings).

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

getSites

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

getWorkplaceServer

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

Returns:
the workplace server

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

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

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.

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

setWorkplaceServer

public void setWorkplaceServer(java.lang.String workplaceServer)
Sets the workplace server, this is only allowed during configuration.

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

Parameters:
workplaceServer - the workplace server to set