[opencms-dev] (5.3.5) Query about SiteRoot
Alexander Kandzior
alex at opencms.org
Wed Aug 4 09:26:01 CEST 2004
> Can someone explain why getSiteRoot works the way it does.
> I am attempting to make my menu builder jsp more generic so
> it can be used by multiple sites, and I need to get the site root.
Sure.
The site root concept works as follows:
OpenCms 6 (or post 5.0) can manage multiple sites. This is accomplished by
having a special folder structure. By default, the content of one site are
stores in the /sites/ folder in a subfolder. The default site is stored in
/sites/default/. This folder is then the site root for the default site.
The a request is processed by OpenCms, the site configuration (currently in
opencms.properties) is used to determine the "right" site. This is done by
analyzing the server name / port and mapping this to one of the folders in
the VFS. So for example in a default installation, "http://localhost:8080"
is mapped to /sites/default/. So if a user requests
http://localhost:8080/index.html OpenCms will try to deliver
/sites/default/index.html. You can configure another site to a different
server name / port.
The site root for the current request is stored in the CmsRequestContext.
This information is used to internall pull the "right" resource from the
VFS. Using the CmsObject API, you must NOT use the "root path"
(/sites/default/index.html) but always use the current site path
(/index.html) since the site root in the context is always internally
appended.
A special case is the /system/ folder. This folder is "mapped" to all sites,
so reading "/system/file.txt" will NOT read
"/sites/default/system/file.txt".
In case you need to access different site roots, you can switch the site
root in the context. Let's say you have configured a second site in
/sites/mysite/. In case you must read from this site, you can use the
following methods to switch the site root:
CmsRequestContext context;
context.saveSiteRoot();
try {
context.setSiteRoot("/sites/mysite");
// no all operations will read from the selected site
} finally {
context.restoreSiteRoot();
}
Hoever, you usually will NOT have to read from a different site. In case you
need to share resources, the best thing is to place these in a module and
have them in the /system/modules/ folder, which is shared by all sites.
Best Regards,
Alex.
Alexander Kandzior
Alkacon Software - The OpenCms Experts
http://www.alkacon.com
More information about the opencms-dev
mailing list