1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
@Bean(name="localesManager")
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class LocalesManagerBean {
@Autowired
private be.cyberplongeurs.system.spring.WebApplicationContext applicationContext;
public LocalesManagerBean() {
Logger.getLogger( LocalesManagerBean.class ).debug("Constructor");
}
public void setApplicationContext(be.cyberplongeurs.system.spring.WebApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@PostConstruct
public void init()
{
Logger.getLogger( LocalesManagerBean.class ).debug("init()");
try {
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
request.setAttribute(LocalesManagerBean.class.getName(), this);
} catch (Exception e) {
e.printStackTrace();
Logger.getLogger( LocalesManagerBean.class ).debug("Exception occured while initializing " + LocalesManagerBean.class + ": " + e + " Message: " + e.getMessage());
}
}
public List<Locale> getCurrentLocales()
{
Map<String, ILocaleResolver> resolvers = applicationContext.getBeansOfType( ILocaleResolver.class );
java.util.List<Locale> currentLocales = null;
int currentPriority = Integer.MIN_VALUE;
LocalesResolution currentResolution;
for(ILocaleResolver resolver : resolvers.values() )
{
currentResolution = resolver.getContextLocale();
if ( ( currentResolution != null ) && ( currentResolution.getPriority() > currentPriority ) )
{
currentLocales = currentResolution.getLocaleList();
currentPriority = currentResolution.getPriority();
Logger.getLogger( LocalesManagerBean.class ).debug("The result of " + resolver.getClass() + " is took into account (" + currentResolution + " with priority "+ currentPriority + ")");
}
else
{
Logger.getLogger( LocalesManagerBean.class ).debug("The result of " + resolver.getClass() + " won't be took into account (" + currentResolution + ")");
}
}
return currentLocales;
}
} |
Partager