VIVO-12 NIHVIVO-4011 Improve LocaleSelectionFilter. Clean up comments.

This commit is contained in:
j2blake 2013-02-07 16:06:49 -05:00
parent e2f30577bd
commit d2d20291b9
3 changed files with 23 additions and 17 deletions

View file

@ -84,7 +84,8 @@ public class I18n {
/**
* Get an I18nBundle by this name. The request provides the preferred
* Locale, the theme directory and the development mode flag.
* Locale, the application directory, the theme directory and the
* development mode flag.
*
* If the request indicates that the system is in development mode, then the
* cache is cleared on each request.
@ -155,7 +156,8 @@ public class I18n {
// ----------------------------------------------------------------------
/**
* Instead of looking in the classpath, look in the theme directory.
* Instead of looking in the classpath, look in the theme i18n directory and
* the application i18n directory.
*/
private static class ThemeBasedControl extends ResourceBundle.Control {
private static final String BUNDLE_DIRECTORY = "i18n/";
@ -177,7 +179,8 @@ public class I18n {
/**
* Don't look in the class path, look in the current servlet context, in
* the bundle directory under the theme directory.
* the bundle directory under the theme directory and in the bundle
* directory under the application directory.
*/
@Override
public ResourceBundle newBundle(String baseName, Locale locale,

View file

@ -72,9 +72,9 @@ public class LocaleSelectionFilter implements Filter {
*/
private static class LocaleSelectionRequestWrapper extends
HttpServletRequestWrapper {
private final HttpServletRequest request;
private final Locale selectedLocale;
private final List<Locale> locales;
@SuppressWarnings("unchecked")
public LocaleSelectionRequestWrapper(HttpServletRequest request,
Locale selectedLocale) {
super(request);
@ -82,31 +82,32 @@ public class LocaleSelectionFilter implements Filter {
if (request == null) {
throw new NullPointerException("request may not be null.");
}
this.request = request;
if (selectedLocale == null) {
throw new NullPointerException(
"selectedLocale may not be null.");
}
this.selectedLocale = selectedLocale;
Locale selectedLanguage = new Locale(selectedLocale.getLanguage());
locales = EnumerationUtils.toList(request.getLocales());
locales.remove(selectedLanguage);
locales.add(0, selectedLanguage);
locales.remove(selectedLocale);
locales.add(0, selectedLocale);
}
@Override
public Locale getLocale() {
return selectedLocale;
return locales.get(0);
}
/**
* Put the selected Locale on the front of the list of acceptable
* Locales.
* Get the modified list of locales.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("rawtypes")
@Override
public Enumeration getLocales() {
List list = EnumerationUtils.toList(request.getLocales());
list.remove(selectedLocale);
list.add(0, selectedLocale);
return Collections.enumeration(list);
return Collections.enumeration(locales);
}
}

View file

@ -1,3 +1,5 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package stubs.com.hp.hpl.jena.rdf.model;
import com.hp.hpl.jena.datatypes.RDFDatatype;