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 * 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 * If the request indicates that the system is in development mode, then the
* cache is cleared on each request. * 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 class ThemeBasedControl extends ResourceBundle.Control {
private static final String BUNDLE_DIRECTORY = "i18n/"; 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 * 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 @Override
public ResourceBundle newBundle(String baseName, Locale locale, public ResourceBundle newBundle(String baseName, Locale locale,

View file

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

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; package stubs.com.hp.hpl.jena.rdf.model;
import com.hp.hpl.jena.datatypes.RDFDatatype; import com.hp.hpl.jena.datatypes.RDFDatatype;