|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.samskivert.servlet.SiteResourceLoader
public class SiteResourceLoader
Web applications may wish to load resources in such a way that the site on which they are running is allowed to override a resource with a site-specific version (a header, footer or navigation template for example). The site resource loader provides this capability by loading resources from a site-specific jar file.
The site resource loader must be configured with the path to the
site-specific jar files, the names of which are dictated by the string
identifiers returned by the SiteIdentifier provided to the
resource loader at construct time. For example, if the configuration
dictates that site-specific jar files are located in
/usr/share/java/webapps/site-data and the site identifier
returns samskivert as the site identifier for a particular
request, site-specific resources will be loaded from
/usr/share/java/webapps/site-data/samskivert.jar.
| Nested Class Summary | |
|---|---|
protected static class |
SiteResourceLoader.SiteClassLoader
|
static class |
SiteResourceLoader.SiteResourceBundle
Encapsulates the information we need to load data from a site resource bundle as well as to determine whether the loaded bundle is up to date. |
| Field Summary | |
|---|---|
protected HashIntMap<SiteResourceLoader.SiteResourceBundle> |
_bundles
The table of site-specific jar file information. |
protected String |
_jarPath
The path to our site-specific jar files. |
protected HashIntMap<ClassLoader> |
_loaders
The table of site-specific class loaders. |
protected HashIntMap<Object> |
_locks
We synchronize on a per-site basis. |
protected SiteIdentifier |
_siteIdent
The site identifier we use to identify requests. |
protected static String |
DEFAULT_SITE_JAR_PATH
The default path to the site-specific jar files. |
protected static String |
JAR_EXTENSION
The file extension to be appended to the string site identifier to obtain the file name of the site-specific jar file. |
| Constructor Summary | |
|---|---|
SiteResourceLoader(SiteIdentifier siteIdent,
String siteJarPath)
Constructs a new resource loader. |
|
| Method Summary | |
|---|---|
protected SiteResourceLoader.SiteResourceBundle |
getBundle(int siteId)
Obtains the site-specific jar file for the specified site. |
long |
getLastModified(int siteId)
Returns the last modification time of the site-specific jar file for the specified site. |
protected Object |
getLock(int siteId)
We synchronize on a per-site basis, but we use a separate lock object for each site so that the process of loading a bundle for the first time does not require blocking access to resources from other sites. |
InputStream |
getResourceAsStream(javax.servlet.http.HttpServletRequest req,
String path)
Loads the specific resource, from the site-specific jar file if one exists and contains the specified resource. |
InputStream |
getResourceAsStream(int siteId,
String path)
Loads the specific resource, from the site-specific jar file if one exists and contains the specified resource. |
ClassLoader |
getSiteClassLoader(int siteId)
Returns a class loader that loads resources from the site-specific jar file for the specified site. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected SiteIdentifier _siteIdent
protected String _jarPath
protected HashIntMap<Object> _locks
protected HashIntMap<SiteResourceLoader.SiteResourceBundle> _bundles
protected HashIntMap<ClassLoader> _loaders
protected static final String DEFAULT_SITE_JAR_PATH
protected static final String JAR_EXTENSION
| Constructor Detail |
|---|
public SiteResourceLoader(SiteIdentifier siteIdent,
String siteJarPath)
siteIdent - the site identifier to be used to identify which
site through which a request was made when loading resources.siteJarPath - the path to the site-specific jar files.| Method Detail |
|---|
public InputStream getResourceAsStream(javax.servlet.http.HttpServletRequest req,
String path)
throws IOException
req - the http request for which we are loading a resource
(this will be used to determine for which site the resource will be
loaded).path - the path to the desired resource.
IOException - thrown if an I/O error occurs while loading
a resource.
public InputStream getResourceAsStream(int siteId,
String path)
throws IOException
siteId - the unique identifer for the site for which we are
loading the resource.path - the path to the desired resource.
IOException - thrown if an I/O error occurs while loading
a resource.
public long getLastModified(int siteId)
throws IOException
IOException - thrown if an error occurs accessing the
site-specific jar file (like it doesn't exist).
public ClassLoader getSiteClassLoader(int siteId)
throws IOException
IOExceptionpublic String toString()
toString in class Objectprotected Object getLock(int siteId)
protected SiteResourceLoader.SiteResourceBundle getBundle(int siteId)
throws IOException
IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||