User options to change UI language as well as content filter language.

Some small rationalizing of common code for above.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4754 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-01-08 17:27:53 +00:00
parent f9e9d0b808
commit b3a588171a
7 changed files with 167 additions and 97 deletions

View File

@@ -18,18 +18,14 @@ package org.alfresco.web.bean;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.faces.validator.ValidatorException;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.config.Config;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
@@ -42,7 +38,6 @@ import org.alfresco.web.app.servlet.AuthenticationHelper;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.config.LanguagesConfigElement;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -166,62 +161,6 @@ public class LoginBean
return this.password;
}
/**
* @return the available languages
*/
public SelectItem[] getLanguages()
{
Config config = Application.getConfigService(FacesContext.getCurrentInstance()).getConfig("Languages");
LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement(
LanguagesConfigElement.CONFIG_ELEMENT_ID);
List<String> languages = langConfig.getLanguages();
SelectItem[] items = new SelectItem[languages.size()];
int count = 0;
for (String locale : languages)
{
// get label associated to the locale
String label = langConfig.getLabelForLanguage(locale);
// set default selection
if (count == 0 && this.language == null)
{
// first try to get the language that the current user is using
Locale lastLocale = Application.getLanguage(FacesContext.getCurrentInstance());
if (lastLocale != null)
{
this.language = lastLocale.toString();
}
// else we default to the first item in the list
else
{
this.language = locale;
}
}
items[count++] = new SelectItem(locale, label);
}
return items;
}
/**
* @return Returns the language selection.
*/
public String getLanguage()
{
return this.language;
}
/**
* @param language The language selection to set.
*/
public void setLanguage(String language)
{
this.language = language;
Application.setLanguage(FacesContext.getCurrentInstance(), this.language);
}
// ------------------------------------------------------------------------------
// Validator methods
@@ -419,9 +358,10 @@ public class LoginBean
session.put(AuthenticationHelper.SESSION_INVALIDATED, true);
// set language to last used
if (this.language != null && this.language.length() != 0)
String language = preferences.getLanguage();
if (language != null && language.length() != 0)
{
Application.setLanguage(context, this.language);
Application.setLanguage(context, language);
}
return externalAuth ? "logout" : "relogin";
@@ -451,9 +391,6 @@ public class LoginBean
/** password */
private String password = null;
/** language locale selection */
private String language = null;
/** PersonService bean reference */
protected PersonService personService;