From b6ad8d456c9c16430ef9785cbfa52f2336301f55 Mon Sep 17 00:00:00 2001 From: j2blake Date: Tue, 11 Mar 2014 12:06:31 -0400 Subject: [PATCH 1/2] VIVO-648 Repair oversight: when rdf files were moved to the home directory, the "distribute" target didn't keep up. --- webapp/build.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 ================================= --> From 7b0ad5ec12c043a910e3586059054814d400eb3a Mon Sep 17 00:00:00 2001 From: j2blake Date: Tue, 11 Mar 2014 14:42:45 -0400 Subject: [PATCH 2/2] VIVO-689 better selection of Locales If there are selectable Locales, and one has been selected, then only that Locale is preferred. The browser preferences are discarded. If there are selectable Locales, and none has been selected, then act as if the first one has been selected. --- .../i18n/selection/LocaleSelectionFilter.java | 20 ++++++------------- .../webapp/i18n/selection/SelectedLocale.java | 12 +++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) 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; }