Merge branch 'maint-rel-1.6' into develop

This commit is contained in:
j2blake 2014-03-11 14:46:18 -04:00
commit 3e15baee6e
3 changed files with 21 additions and 17 deletions

View file

@ -497,7 +497,7 @@
target: distribute target: distribute
================================= --> ================================= -->
<target name="distribute" <target name="distribute"
depends="revisionInfo, prepareSolr" depends="revisionInfo, prepareVitroHomeDir, prepareSolr"
description="--> Build the app and create a distribution bundle"> description="--> Build the app and create a distribution bundle">
<mkdir dir="${distribution.dir}" /> <mkdir dir="${distribution.dir}" />

View file

@ -3,9 +3,9 @@
package edu.cornell.mannlib.vitro.webapp.i18n.selection; package edu.cornell.mannlib.vitro.webapp.i18n.selection;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.servlet.Filter; import javax.servlet.Filter;
@ -17,7 +17,6 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.commons.collections.EnumerationUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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 private static class LocaleSelectionRequestWrapper extends
HttpServletRequestWrapper { HttpServletRequestWrapper {
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);
@ -87,18 +85,12 @@ public class LocaleSelectionFilter implements Filter {
"selectedLocale may not be null."); "selectedLocale may not be null.");
} }
Locale selectedLanguage = new Locale(selectedLocale.getLanguage()); this.selectedLocale = selectedLocale;
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 locales.get(0); return selectedLocale;
} }
/** /**
@ -107,7 +99,7 @@ public class LocaleSelectionFilter implements Filter {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public Enumeration getLocales() { public Enumeration getLocales() {
return Collections.enumeration(locales); return Collections.enumeration(Arrays.asList(selectedLocale));
} }
} }

View file

@ -52,6 +52,7 @@ public abstract class SelectedLocale {
* <ul> * <ul>
* <li>The forced Locale in the servlet context</li> * <li>The forced Locale in the servlet context</li>
* <li>The selected Locale in the session</li> * <li>The selected Locale in the session</li>
* <li>The first of the selectable Locales</li>
* <li>null</li> * <li>null</li>
* </ul> * </ul>
*/ */
@ -80,6 +81,17 @@ public abstract class SelectedLocale {
} }
} }
if (ctxInfo instanceof ContextSelectedLocale) {
List<Locale> 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; return null;
} }