mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Fix retrieval of Locale for an EPerson so that if the language isn't set, an NPE isn't thrown
git-svn-id: http://scm.dspace.org/svn/repo/trunk@2457 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -37,6 +37,10 @@
|
||||
|
||||
package org.dspace.core;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
@@ -62,6 +66,8 @@ import java.util.StringTokenizer;
|
||||
|
||||
public class I18nUtil
|
||||
{
|
||||
private static final Logger log = Logger.getLogger(I18nUtil.class);
|
||||
|
||||
// the default Locale of this DSpace Instance
|
||||
public static final Locale DEFAULTLOCALE = getDefaultLocale();
|
||||
|
||||
@@ -110,6 +116,32 @@ public class I18nUtil
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Locale for a specified EPerson. If the language is missing,
|
||||
* return the default Locale for the repository.
|
||||
*
|
||||
* @param ep
|
||||
* @return
|
||||
*/
|
||||
public static Locale getEPersonLocale(EPerson ep)
|
||||
{
|
||||
if (ep == null)
|
||||
{
|
||||
log.error("No EPerson specified, returning default locale");
|
||||
return I18nUtil.getDefaultLocale();
|
||||
}
|
||||
|
||||
String lang = ep.getLanguage();
|
||||
|
||||
if (StringUtils.isBlank(lang))
|
||||
{
|
||||
log.error("No language specified for EPerson " + ep.getID());
|
||||
return I18nUtil.getDefaultLocale();
|
||||
}
|
||||
|
||||
return I18nUtil.getSupportedLocale(new Locale(lang));
|
||||
}
|
||||
|
||||
/**
|
||||
* get the available Locales for the User Interface as defined in dspace.cfg
|
||||
* returns an array of Locales or null
|
||||
|
@@ -314,8 +314,7 @@ public class SubscriptionManager
|
||||
ObjectIdentifier identifier = null;
|
||||
|
||||
// Get a resource bundle according to the eperson language preferences
|
||||
Locale epersonLocale = new Locale(eperson.getLanguage());
|
||||
Locale supportedLocale = I18nUtil.getSupportedLocale(epersonLocale);
|
||||
Locale supportedLocale = I18nUtil.getEPersonLocale(eperson);
|
||||
ResourceBundle labels = ResourceBundle.getBundle("Messages", supportedLocale);
|
||||
|
||||
// Get the start and end dates for yesterday
|
||||
|
@@ -629,8 +629,7 @@ public class WorkflowManager
|
||||
// Get submitter
|
||||
EPerson ep = i.getSubmitter();
|
||||
// Get the Locale
|
||||
Locale epLocale = new Locale(ep.getLanguage());
|
||||
Locale supportedLocale = I18nUtil.getSupportedLocale(epLocale);
|
||||
Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
|
||||
Email email = ConfigurationManager.getEmail(
|
||||
I18nUtil.getEmailFilename(supportedLocale,
|
||||
"submit_archive"));
|
||||
@@ -812,8 +811,7 @@ public class WorkflowManager
|
||||
|
||||
for (int i = 0; i < epa.length; i++)
|
||||
{
|
||||
Locale epersonLocale = new Locale(epa[i].getLanguage());
|
||||
Locale supportedLocale = I18nUtil.getSupportedLocale(epersonLocale);
|
||||
Locale supportedLocale = I18nUtil.getEPersonLocale(epa[i]);
|
||||
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_task"));
|
||||
email.addArgument(title);
|
||||
email.addArgument(coll.getMetadata("name"));
|
||||
@@ -893,8 +891,7 @@ public class WorkflowManager
|
||||
|
||||
// Get rejector's name
|
||||
String rejector = getEPersonName(e);
|
||||
Locale eLocale = new Locale(e.getLanguage());
|
||||
Locale supportedLocale = I18nUtil.getSupportedLocale(eLocale);
|
||||
Locale supportedLocale = I18nUtil.getEPersonLocale(e);
|
||||
Email email = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(supportedLocale,"submit_reject"));
|
||||
|
||||
email.addRecipient(getSubmitterEPerson(wi).getEmail());
|
||||
|
@@ -102,8 +102,7 @@ public class PasswordServlet extends DSpaceServlet
|
||||
Authenticate.loggedIn(context, request, context.getCurrentUser());
|
||||
|
||||
// Set the Locale according to user preferences
|
||||
String preferredLanguage = context.getCurrentUser().getLanguage();
|
||||
Locale epersonLocale = I18nUtil.getSupportedLocale(new Locale(preferredLanguage));
|
||||
Locale epersonLocale = I18nUtil.getEPersonLocale(context.getCurrentUser());
|
||||
context.setCurrentLocale(epersonLocale);
|
||||
Config.set(request.getSession(), Config.FMT_LOCALE, epersonLocale);
|
||||
|
||||
|
Reference in New Issue
Block a user