diff --git a/webapp/build.xml b/webapp/build.xml index 93927a7f7..e8bc13669 100644 --- a/webapp/build.xml +++ b/webapp/build.xml @@ -476,8 +476,8 @@ + target: deploy + ================================= --> @@ -497,7 +497,7 @@ target: distribute ================================= --> diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/LocaleSelectionFilter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/LocaleSelectionFilter.java index 233dad10a..2a1871c72 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/LocaleSelectionFilter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/LocaleSelectionFilter.java @@ -3,9 +3,9 @@ package edu.cornell.mannlib.vitro.webapp.i18n.selection; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; -import java.util.List; import java.util.Locale; import javax.servlet.Filter; @@ -17,7 +17,6 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; -import org.apache.commons.collections.EnumerationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -68,13 +67,12 @@ public class LocaleSelectionFilter implements Filter { // ---------------------------------------------------------------------- /** - * Uses the selected Locale as the preferred Locale of the request. + * Uses the selected Locale as the only acceptable Locale of the request. */ private static class LocaleSelectionRequestWrapper extends HttpServletRequestWrapper { - private final List locales; + private final Locale selectedLocale; - @SuppressWarnings("unchecked") public LocaleSelectionRequestWrapper(HttpServletRequest request, Locale selectedLocale) { super(request); @@ -87,18 +85,12 @@ public class LocaleSelectionFilter implements Filter { "selectedLocale may not be null."); } - 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); + this.selectedLocale = selectedLocale; } @Override public Locale getLocale() { - return locales.get(0); + return selectedLocale; } /** @@ -107,7 +99,7 @@ public class LocaleSelectionFilter implements Filter { @SuppressWarnings("rawtypes") @Override public Enumeration getLocales() { - return Collections.enumeration(locales); + return Collections.enumeration(Arrays.asList(selectedLocale)); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/SelectedLocale.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/SelectedLocale.java index 8356af109..0d7a01129 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/SelectedLocale.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/i18n/selection/SelectedLocale.java @@ -52,6 +52,7 @@ public abstract class SelectedLocale { *
    *
  • The forced Locale in the servlet context
  • *
  • The selected Locale in the session
  • + *
  • The first of the selectable Locales
  • *
  • null
  • *
*/ @@ -80,6 +81,17 @@ public abstract class SelectedLocale { } } + if (ctxInfo instanceof ContextSelectedLocale) { + List selectableLocales = ((ContextSelectedLocale) ctxInfo) + .getSelectableLocales(); + if (selectableLocales != null && !selectableLocales.isEmpty()) { + Locale defaultLocale = selectableLocales.get(0); + log.debug("Using first selectable locale as default: " + + defaultLocale); + return defaultLocale; + } + } + return null; }