📄 cmssitemanager.java
字号:
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_CONFIG_FROZEN_0));
}
CmsSiteMatcher matcher = new CmsSiteMatcher(server);
CmsSite site = new CmsSite(uri, matcher);
addServer(matcher, site);
if (CmsStringUtil.isNotEmpty(secureServer)) {
matcher = new CmsSiteMatcher(secureServer);
site.setSecureServer(matcher);
site.setExclusiveUrl(Boolean.valueOf(exclusive).booleanValue());
site.setExclusiveError(Boolean.valueOf(error).booleanValue());
addServer(matcher, site);
}
// Note that Digester first calls the addAliasToConfigSite method.
// Therefore, the aliases are already
site.setAliases(m_aliases);
Iterator i = m_aliases.iterator();
while (i.hasNext()) {
matcher = (CmsSiteMatcher)i.next();
addServer(matcher, site);
}
m_aliases = new ArrayList();
m_siteRoots.add(site.getSiteRoot());
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SITE_ROOT_ADDED_1, site.toString()));
}
}
/**
* Returns the default site.<p>
*
* @return the default site
*/
public CmsSite getDefaultSite() {
return m_defaultSite;
}
/**
* Returns the defaultUri.<p>
*
* @return the defaultUri
*/
public String getDefaultUri() {
return m_defaultUri;
}
/**
* Returns an unmodifiable set of all configured site roots (Strings).<p>
*
* @return an unmodifiable set of all configured site roots (Strings)
*/
public Set getSiteRoots() {
return m_siteRoots;
}
/**
* Returns a map of configured sites.<p>
*
* The map uses CmsSiteMatcher objects as key and CmsSite as value.<p>
*
* @return a map of configured sites
*/
public Map getSites() {
return m_sites;
}
/**
* Returns the workplace server.<p>
*
* @return the workplace server
*/
public String getWorkplaceServer() {
return m_workplaceServer;
}
/**
* Returns the site matcher that matches the workplace site.<p>
*
* @return the site matcher that matches the workplace site
*/
public CmsSiteMatcher getWorkplaceSiteMatcher() {
return m_workplaceSiteMatcher;
}
/**
* Initializes the site manager with the OpenCms system configuration.<p>
*
* @param cms an OpenCms context object that must have been initialized with "Admin" permissions
*/
public void initialize(CmsObject cms) {
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_NUM_SITE_ROOTS_CONFIGURED_1,
new Integer((m_sites.size() + ((m_defaultUri != null) ? 1 : 0)))));
}
// check the presence of sites in VFS
Iterator i = m_sites.values().iterator();
while (i.hasNext()) {
CmsSite site = (CmsSite)i.next();
if (site != null) {
try {
cms.readResource(site.getSiteRoot());
} catch (Throwable t) {
if (CmsLog.INIT.isWarnEnabled()) {
CmsLog.INIT.warn(Messages.get().getBundle().key(Messages.INIT_NO_ROOT_FOLDER_1, site));
}
}
}
}
// check the presence of the default site in VFS
if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_defaultUri)) {
m_defaultSite = null;
} else {
m_defaultSite = new CmsSite(m_defaultUri, CmsSiteMatcher.DEFAULT_MATCHER);
try {
cms.readResource(m_defaultSite.getSiteRoot());
} catch (Throwable t) {
if (CmsLog.INIT.isWarnEnabled()) {
CmsLog.INIT.warn(Messages.get().getBundle().key(
Messages.INIT_NO_ROOT_FOLDER_DEFAULT_SITE_1,
m_defaultSite));
}
}
}
if (m_defaultSite == null) {
m_defaultSite = new CmsSite("/", CmsSiteMatcher.DEFAULT_MATCHER);
}
if (CmsLog.INIT.isInfoEnabled()) {
if (m_defaultSite != null) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DEFAULT_SITE_ROOT_1, m_defaultSite));
} else {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DEFAULT_SITE_ROOT_0));
}
}
m_workplaceSiteMatcher = new CmsSiteMatcher(m_workplaceServer);
if (CmsLog.INIT.isInfoEnabled()) {
if (m_workplaceSiteMatcher != null) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_WORKPLACE_SITE_1, m_workplaceSiteMatcher));
} else {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_WORKPLACE_SITE_0));
}
}
// set site lists to unmodifiable
m_sites = Collections.unmodifiableMap(m_sites);
m_siteRoots = Collections.unmodifiableSet(m_siteRoots);
// initialization is done, set the frozen flag to true
m_frozen = true;
}
/**
* Returns true if the given site matcher matches a site.<p>
*
* @param matcher the site matcher to match the site with
* @return true if the matcher matches a site
*/
public boolean isMatching(CmsSiteMatcher matcher) {
return m_sites.get(matcher) != null;
}
/**
* Returns if the given site matcher matches the current site.<p>
*
* @param cms the cms object
* @param matcher the site matcher to match the site with
* @return true if the matcher matches the current site
*/
public boolean isMatchingCurrentSite(CmsObject cms, CmsSiteMatcher matcher) {
return m_sites.get(matcher) == getCurrentSite(cms);
}
/**
* Returns <code>true</code> if the given request is against the configured OpenCms workplace.<p>
*
* @param req the request to match
* @return <code>true</code> if the given request is against the configured OpenCms workplace
*/
public boolean isWorkplaceRequest(HttpServletRequest req) {
if (req == null) {
// this may be true inside a static export test case scenario
return false;
}
CmsSiteMatcher matcher = new CmsSiteMatcher(req.getScheme(), req.getServerName(), req.getServerPort());
return m_workplaceSiteMatcher.equals(matcher);
}
/**
* Matches the given request against all configures sites and returns
* the matching site, or the default site if no sites matches.<p>
*
* @param req the request to match
* @return the matching site, or the default site if no sites matches
*/
public CmsSite matchRequest(HttpServletRequest req) {
CmsSiteMatcher matcher = new CmsSiteMatcher(req.getScheme(), req.getServerName(), req.getServerPort());
CmsSite site = matchSite(matcher);
if (LOG.isDebugEnabled()) {
String requestServer = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_MATCHING_REQUEST_TO_SITE_2,
requestServer,
site.toString()));
}
return site;
}
/**
* Return the site that matches the given site matcher,
* or the default site if no sites matches.<p>
*
* @param matcher the site matcher to match the site with
* @return the matching site, or the defaule site if no sites matches
*/
public CmsSite matchSite(CmsSiteMatcher matcher) {
CmsSite site = (CmsSite)m_sites.get(matcher);
if (site == null) {
// return the default site (might be null as well)
site = m_defaultSite;
}
return site;
}
/**
* Sets the default uri, this is only allowed during configuration.<p>
*
* If this method is called after the configuration is finished,
* a <code>RuntimeException</code> is thrown.<p>
*
* @param defaultUri the defaultUri to set
*/
public void setDefaultUri(String defaultUri) {
if (m_frozen) {
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_CONFIG_FROZEN_0));
}
m_defaultUri = defaultUri;
}
/**
* Sets the workplace server, this is only allowed during configuration.<p>
*
* If this method is called after the configuration is finished,
* a <code>RuntimeException</code> is thrown.<p>
*
* @param workplaceServer the workplace server to set
*/
public void setWorkplaceServer(String workplaceServer) {
if (m_frozen) {
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_CONFIG_FROZEN_0));
}
m_workplaceServer = workplaceServer;
}
/**
* Adds a new Site matcher object to the map of server names.
*
* @param server the SiteMatcher of the server
* @param site the site to add
*
* @throws CmsConfigurationException if the site contains a servername, that is already assigned
*/
private void addServer(CmsSiteMatcher server, CmsSite site) throws CmsConfigurationException {
if (m_sites.containsKey(server)) {
throw new CmsConfigurationException(Messages.get().container(
Messages.ERR_DUPLICATE_SERVER_NAME_1,
server.getUrl()));
}
m_sites.put(server, site);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -