Pass our site identifier to the message manager regardless of whether we're
using site bundles. The message manager will now allow a simpler form of site-specific messaging wherein it prefixes the site string to the message bundle and looks for that (assuming we're not using site bundles). git-svn-id: https://samskivert.googlecode.com/svn/trunk@1857 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -44,13 +44,18 @@ public class MessageManager
|
|||||||
* with the supplied path, so it should conform to the naming
|
* with the supplied path, so it should conform to the naming
|
||||||
* conventions defined by that class.
|
* conventions defined by that class.
|
||||||
*
|
*
|
||||||
|
* @param siteIdent an optional site identifier that can be used to
|
||||||
|
* identify the site via which an http request was made.
|
||||||
|
*
|
||||||
* @see java.util.ResourceBundle
|
* @see java.util.ResourceBundle
|
||||||
*/
|
*/
|
||||||
public MessageManager (String bundlePath, Locale deflocale)
|
public MessageManager (String bundlePath, Locale deflocale,
|
||||||
|
SiteIdentifier siteIdent)
|
||||||
{
|
{
|
||||||
// keep these for later
|
// keep these for later
|
||||||
_bundlePath = bundlePath;
|
_bundlePath = bundlePath;
|
||||||
_deflocale = deflocale;
|
_deflocale = deflocale;
|
||||||
|
_siteIdent = siteIdent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,16 +69,12 @@ public class MessageManager
|
|||||||
* resources.
|
* resources.
|
||||||
* @param siteLoader a site-specific resource loader, properly
|
* @param siteLoader a site-specific resource loader, properly
|
||||||
* configured with a site identifier.
|
* configured with a site identifier.
|
||||||
* @param siteIdent a site identifier that can be used to identify the
|
|
||||||
* site via which an http request was made.
|
|
||||||
*/
|
*/
|
||||||
public void activateSiteSpecificMessages (String siteBundlePath,
|
public void activateSiteSpecificMessages (String siteBundlePath,
|
||||||
SiteResourceLoader siteLoader,
|
SiteResourceLoader siteLoader)
|
||||||
SiteIdentifier siteIdent)
|
|
||||||
{
|
{
|
||||||
_siteBundlePath = siteBundlePath;
|
_siteBundlePath = siteBundlePath;
|
||||||
_siteLoader = siteLoader;
|
_siteLoader = siteLoader;
|
||||||
_siteIdent = siteIdent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,16 +194,20 @@ public class MessageManager
|
|||||||
return bundles;
|
return bundles;
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab our site-specific class loader if we have one
|
|
||||||
ClassLoader siteLoader = null;
|
ClassLoader siteLoader = null;
|
||||||
if (_siteLoader != null && _siteIdent != null) {
|
String siteString = null;
|
||||||
|
if (_siteIdent != null) {
|
||||||
int siteId = _siteIdent.identifySite(req);
|
int siteId = _siteIdent.identifySite(req);
|
||||||
try {
|
siteString = _siteIdent.getSiteString(siteId);
|
||||||
siteLoader = _siteLoader.getSiteClassLoader(siteId);
|
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
// grab our site-specific class loader if we have one
|
||||||
Log.warning("Unable to fetch site-specific classloader " +
|
if (_siteLoader != null) {
|
||||||
"[siteId=" + siteId + ", error=" + ioe + "].");
|
try {
|
||||||
|
siteLoader = _siteLoader.getSiteClassLoader(siteId);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
Log.warning("Unable to fetch site-specific classloader " +
|
||||||
|
"[siteId=" + siteId + ", error=" + ioe + "].");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,12 +216,17 @@ public class MessageManager
|
|||||||
|
|
||||||
// first from the site-specific classloader
|
// first from the site-specific classloader
|
||||||
if (siteLoader != null) {
|
if (siteLoader != null) {
|
||||||
bundles[0] = resolveBundle(req, _siteBundlePath, siteLoader);
|
bundles[0] = resolveBundle(req, _siteBundlePath, siteLoader, false);
|
||||||
|
} else if (siteString != null) {
|
||||||
|
// or just try prefixing the site string to the normal bundle path
|
||||||
|
// and see if that turns something up
|
||||||
|
bundles[0] = resolveBundle(req, siteString + "_" + _bundlePath,
|
||||||
|
getClass().getClassLoader(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// then from the default classloader
|
// then from the default classloader
|
||||||
bundles[1] = resolveBundle(req, _bundlePath,
|
bundles[1] = resolveBundle(
|
||||||
getClass().getClassLoader());
|
req, _bundlePath, getClass().getClassLoader(), false);
|
||||||
|
|
||||||
// if we found either or both bundles, cache 'em
|
// if we found either or both bundles, cache 'em
|
||||||
if (bundles[0] != null || bundles[1] != null && req != null) {
|
if (bundles[0] != null || bundles[1] != null && req != null) {
|
||||||
@@ -231,7 +241,8 @@ public class MessageManager
|
|||||||
* information provided in the supplied http request object.
|
* information provided in the supplied http request object.
|
||||||
*/
|
*/
|
||||||
protected ResourceBundle resolveBundle (
|
protected ResourceBundle resolveBundle (
|
||||||
HttpServletRequest req, String bundlePath, ClassLoader loader)
|
HttpServletRequest req, String bundlePath, ClassLoader loader,
|
||||||
|
boolean silent)
|
||||||
{
|
{
|
||||||
ResourceBundle bundle = null;
|
ResourceBundle bundle = null;
|
||||||
|
|
||||||
@@ -272,14 +283,16 @@ public class MessageManager
|
|||||||
try {
|
try {
|
||||||
bundle = ResourceBundle.getBundle(bundlePath, locale, loader);
|
bundle = ResourceBundle.getBundle(bundlePath, locale, loader);
|
||||||
} catch (MissingResourceException mre) {
|
} catch (MissingResourceException mre) {
|
||||||
// if we were unable even to find a default bundle, we've
|
if (!silent) {
|
||||||
// got real problems. time to freak out
|
// if we were unable even to find a default bundle, we may
|
||||||
Log.warning("Unable to resolve any message bundle " +
|
// want to log a warning
|
||||||
"[req=" + getURL(req) + ", locale=" + locale +
|
Log.warning("Unable to resolve any message bundle " +
|
||||||
", bundlePath=" + bundlePath +
|
"[req=" + getURL(req) + ", locale=" + locale +
|
||||||
", classLoader=" + loader +
|
", bundlePath=" + bundlePath +
|
||||||
", siteBundlePath=" + _siteBundlePath +
|
", classLoader=" + loader +
|
||||||
", siteLoader=" + _siteLoader + "].");
|
", siteBundlePath=" + _siteBundlePath +
|
||||||
|
", siteLoader=" + _siteLoader + "].");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public class Application
|
|||||||
// instantiate our message manager if the application wants one
|
// instantiate our message manager if the application wants one
|
||||||
String bundlePath = getInitParameter(config, MESSAGE_BUNDLE_PATH_KEY);
|
String bundlePath = getInitParameter(config, MESSAGE_BUNDLE_PATH_KEY);
|
||||||
if (!StringUtil.isBlank(bundlePath)) {
|
if (!StringUtil.isBlank(bundlePath)) {
|
||||||
_msgmgr = new MessageManager(bundlePath, null);
|
_msgmgr = new MessageManager(bundlePath, null, _siteIdent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have a site-specific resource loader, configure the
|
// if we have a site-specific resource loader, configure the
|
||||||
@@ -128,7 +128,7 @@ public class Application
|
|||||||
config, SITE_MESSAGE_BUNDLE_PATH_KEY);
|
config, SITE_MESSAGE_BUNDLE_PATH_KEY);
|
||||||
if (!StringUtil.isBlank(siteBundlePath)) {
|
if (!StringUtil.isBlank(siteBundlePath)) {
|
||||||
_msgmgr.activateSiteSpecificMessages(
|
_msgmgr.activateSiteSpecificMessages(
|
||||||
siteBundlePath, _siteLoader, _siteIdent);
|
siteBundlePath, _siteLoader);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.info("No '" + SITE_MESSAGE_BUNDLE_PATH_KEY + "' " +
|
Log.info("No '" + SITE_MESSAGE_BUNDLE_PATH_KEY + "' " +
|
||||||
|
|||||||
Reference in New Issue
Block a user