org.opencms.site
Class CmsSiteManager

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

public final class CmsSiteManager
extends java.lang.Object

Manages all configured sites in OpenCms.

Since:
6.0.0
Version:
$Revision: 1.55 $
Author:
Alexander Kandzior

Constructor Summary
CmsSiteManager()
          Creates a new CmsSiteManager.
 
Method Summary
 void addAliasToConfigSite(java.lang.String alias)
          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.
static java.util.List getAvailableSites(CmsObject cms, boolean workplaceMode)
          Returns a list of all sites available for the current user.
static java.util.List getAvailableSites(CmsObject cms, boolean workplaceMode, java.lang.String ouFqn)
          Returns a list of all sites that are compatible to the given organizational unit.
static CmsSite getCurrentSite(CmsObject cms)
          Returns the current site for the provided cms context object.
 CmsSite getDefaultSite()
          Returns the default site.
 java.lang.String getDefaultUri()
          Returns the defaultUri.
static CmsSite getSite(java.lang.String siteRoot)
          Returns the site with has the provided site root path, or null if no configured site has that root path.
static java.lang.String getSiteRoot(java.lang.String path)
          Returns the site root part of the resources root path, or null if the 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 a map of configured sites.
 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

CmsSiteManager

public CmsSiteManager()
Creates a new CmsSiteManager.

Method Detail

getAvailableSites

public static java.util.List getAvailableSites(CmsObject cms,
                                               boolean workplaceMode)
Returns a list of all sites available for the current user.

Parameters:
cms - the current cms 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 static java.util.List getAvailableSites(CmsObject cms,
                                               boolean workplaceMode,
                                               java.lang.String ouFqn)
Returns a list of all sites that are compatible to the given organizational unit.

Parameters:
cms - the current cms 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 static CmsSite getCurrentSite(CmsObject cms)
Returns the current site for the provided cms context object.

Parameters:
cms - the cms context object to check for the site
Returns:
the current site for the provided cms context object

getSite

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

Parameters:
siteRoot - the root path to look up the site for
Returns:
the site with has the provided site root path, or null if no configured site has that root path

getSiteRoot

public static java.lang.String getSiteRoot(java.lang.String path)
Returns the site root part of the resources root path, or null if the path does not match any site root.

Parameters:
path - 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

addAliasToConfigSite

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

Parameters:
alias - the url of the alias server

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 servername, that is already assigned

getDefaultSite

public CmsSite getDefaultSite()
Returns the default site.

Returns:
the default site

getDefaultUri

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

Returns:
the defaultUri

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 a map of configured sites.

The map uses CmsSiteMatcher objects as key and CmsSite as value.

Returns:
a map of configured sites

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 cms object
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