Prevent repo-based message bundle fetching from failing after login failure

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22196 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-09-02 17:58:03 +00:00
parent 24ff9c9195
commit 797930fae1

View File

@@ -39,7 +39,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.springframework.extensions.surf.util.I18NUtil;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
@@ -54,6 +53,7 @@ import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;
/** /**
* Message Service to get localised messages/strings which have been loaded from resource bundles either dynamically * Message Service to get localised messages/strings which have been loaded from resource bundles either dynamically
@@ -138,65 +138,36 @@ public class MessageServiceImpl implements MessageService
this.messagesCache = messagesCache; this.messagesCache = messagesCache;
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#setLocale(java.util.Locale)
*/
public void setLocale(Locale locale) public void setLocale(Locale locale)
{ {
I18NUtil.setLocale(locale); I18NUtil.setLocale(locale);
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#getLocale()
*/
public Locale getLocale() public Locale getLocale()
{ {
return I18NUtil.getLocale(); return I18NUtil.getLocale();
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#setContentLocale(java.util.Locale)
*/
public void setContentLocale(Locale locale) public void setContentLocale(Locale locale)
{ {
I18NUtil.setContentLocale(locale); I18NUtil.setContentLocale(locale);
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#getContentLocale()
*/
public Locale getContentLocale() public Locale getContentLocale()
{ {
return I18NUtil.getContentLocale(); return I18NUtil.getContentLocale();
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#getNearestLocale(java.util.Locale, java.util.Set)
*/
public Locale getNearestLocale(Locale templateLocale, Set<Locale> options) public Locale getNearestLocale(Locale templateLocale, Set<Locale> options)
{ {
return I18NUtil.getNearestLocale(templateLocale, options); return I18NUtil.getNearestLocale(templateLocale, options);
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#parseLocale(java.lang.String)
*/
public Locale parseLocale(String localeStr) public Locale parseLocale(String localeStr)
{ {
return I18NUtil.parseLocale(localeStr); return I18NUtil.parseLocale(localeStr);
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#registerResourceBundle(java.lang.String)
*/
public void registerResourceBundle(String resBundlePath) public void registerResourceBundle(String resBundlePath)
{ {
String tenantDomain = getTenantDomain(); String tenantDomain = getTenantDomain();
@@ -231,19 +202,11 @@ public class MessageServiceImpl implements MessageService
} }
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#getMessage(java.lang.String)
*/
public String getMessage(String messageKey) public String getMessage(String messageKey)
{ {
return getMessage(messageKey, getLocale()); return getMessage(messageKey, getLocale());
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#getMessage(java.lang.String, java.util.Locale)
*/
public String getMessage(final String messageKey, final Locale locale) public String getMessage(final String messageKey, final Locale locale)
{ {
String message = null; String message = null;
@@ -289,19 +252,11 @@ public class MessageServiceImpl implements MessageService
return message; return message;
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#getMessage(java.lang.String, java.lang.Object[])
*/
public String getMessage(String messageKey, Object ... params) public String getMessage(String messageKey, Object ... params)
{ {
return getMessage(messageKey, getLocale(), params); return getMessage(messageKey, getLocale(), params);
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#getMessage(java.lang.String, java.util.Locale, java.lang.Object[])
*/
public String getMessage(String messageKey, Locale locale, Object ... params) public String getMessage(String messageKey, Locale locale, Object ... params)
{ {
String message = getMessage(messageKey, locale); String message = getMessage(messageKey, locale);
@@ -312,10 +267,6 @@ public class MessageServiceImpl implements MessageService
return message; return message;
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#unregisterResourceBundle(java.lang.String)
*/
public void unregisterResourceBundle(String resBundlePath) public void unregisterResourceBundle(String resBundlePath)
{ {
Map<Locale, Set<String>> loadedResourceBundlesForAllLocales; Map<Locale, Set<String>> loadedResourceBundlesForAllLocales;
@@ -561,18 +512,21 @@ public class MessageServiceImpl implements MessageService
return props; return props;
} }
/* public ResourceBundle getRepoResourceBundle(
* (non-Javadoc) final StoreRef storeRef,
* @see org.alfresco.repo.i18n.MessageService#getRepoResourceBundle(org.alfresco.service.cmr.repository.StoreRef, java.lang.String, java.util.Locale) final String path,
*/ final Locale locale) throws IOException
public ResourceBundle getRepoResourceBundle(StoreRef storeRef, String path, Locale locale) throws IOException
{ {
ResourceBundle resBundle = null;
// TODO - need to replace basic strategy with a more complete // TODO - need to replace basic strategy with a more complete
// search & instantiation strategy similar to ResourceBundle.getBundle() // search & instantiation strategy similar to ResourceBundle.getBundle()
// Consider search query with basename* and then apply strategy ... // Consider search query with basename* and then apply strategy ...
// Avoid permission exceptions
RunAsWork<ResourceBundle> getBundleWork = new RunAsWork<ResourceBundle>()
{
@Override
public ResourceBundle doWork() throws Exception
{
NodeRef rootNode = nodeService.getRootNode(storeRef); NodeRef rootNode = nodeService.getRootNode(storeRef);
// first attempt - with locale // first attempt - with locale
@@ -594,39 +548,28 @@ public class MessageServiceImpl implements MessageService
{ {
throw new RuntimeException("Found more than one message resource bundle " + storeRef + path); throw new RuntimeException("Found more than one message resource bundle " + storeRef + path);
} }
else
{
NodeRef messageResourceNodeRef = nodeRefs.get(0); NodeRef messageResourceNodeRef = nodeRefs.get(0);
ContentReader cr = contentService.getReader(messageResourceNodeRef, ContentModel.PROP_CONTENT); ContentReader cr = contentService.getReader(messageResourceNodeRef, ContentModel.PROP_CONTENT);
resBundle = new MessagePropertyResourceBundle(new InputStreamReader(cr.getContentInputStream(), cr.getEncoding())); ResourceBundle resBundle = new MessagePropertyResourceBundle(
} new InputStreamReader(cr.getContentInputStream(), cr.getEncoding()));
return resBundle; return resBundle;
} }
};
return AuthenticationUtil.runAs(getBundleWork, AuthenticationUtil.getSystemUserName());
}
/*
* (non-Javadoc)
* @see org.alfresco.repo.tenant.TenantDeployer#onEnableTenant()
*/
public void onEnableTenant() public void onEnableTenant()
{ {
// NOOP - refer to DictionaryRepositoryBootstrap // NOOP - refer to DictionaryRepositoryBootstrap
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.tenant.TenantDeployer#onDisableTenant()
*/
public void onDisableTenant() public void onDisableTenant()
{ {
destroy(); // will be called in context of tenant destroy(); // will be called in context of tenant
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.tenant.TenantDeployer#init()
*/
public void init() public void init()
{ {
// initialise empty message service // initialise empty message service
@@ -639,10 +582,6 @@ public class MessageServiceImpl implements MessageService
logger.info("Empty message service initialised"); logger.info("Empty message service initialised");
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.tenant.TenantDeployer#destroy()
*/
public void destroy() public void destroy()
{ {
// used by reset and also as callback when destroying tenant(s) during shutdown // used by reset and also as callback when destroying tenant(s) during shutdown
@@ -655,10 +594,6 @@ public class MessageServiceImpl implements MessageService
logger.info("Messages cache destroyed (all locales)"); logger.info("Messages cache destroyed (all locales)");
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#getRegisteredBundles()
*/
public Set<String> getRegisteredBundles() public Set<String> getRegisteredBundles()
{ {
try try
@@ -821,10 +756,6 @@ public class MessageServiceImpl implements MessageService
return tenantService.getCurrentUserDomain(); return tenantService.getCurrentUserDomain();
} }
/*
* (non-Javadoc)
* @see org.alfresco.repo.i18n.MessageService#register(org.alfresco.repo.i18n.MessageDeployer)
*/
public void register(MessageDeployer messageDeployer) public void register(MessageDeployer messageDeployer)
{ {
if (! messageDeployers.contains(messageDeployer)) if (! messageDeployers.contains(messageDeployer))