LocaleConfigService localeConfigService = (LocaleConfigService) container
.getComponentInstanceOfType(LocaleConfigService.class);
LocalePolicy localePolicy = (LocalePolicy) container.getComponentInstanceOfType(LocalePolicy.class);
LocaleContextInfo localeCtx = new LocaleContextInfo();
Set<Locale> supportedLocales = new HashSet<Locale>();
for (LocaleConfig lc : localeConfigService.getLocalConfigs()) {
supportedLocales.add(lc.getLocale());
}
localeCtx.setSupportedLocales(supportedLocales);
HttpServletRequest request = HttpServletRequest.class.cast(context.getRequest());
localeCtx.setBrowserLocales(Collections.list(request.getLocales()));
localeCtx.setCookieLocales(getCookieLocales(request));
localeCtx.setSessionLocale(getSessionLocale(request));
localeCtx.setUserProfileLocale(getUserProfileLocale(reqCtx));
localeCtx.setRemoteUser(reqCtx.getRemoteUser());
DataStorage dataStorage = (DataStorage) container.getComponentInstanceOfType(DataStorage.class);
PortalConfig pConfig = null;
try {
pConfig = dataStorage.getPortalConfig(SiteType.PORTAL.getName(), reqCtx.getPortalOwner());
if (pConfig == null)
log.warn("No UserPortalConfig available! Portal locale set to 'en'");
} catch (Exception ignored) {
if (log.isDebugEnabled())
log.debug("IGNORED: Failed to load UserPortalConfig: ", ignored);
}
String portalLocaleName = "en";
if (pConfig != null)
portalLocaleName = pConfig.getLocale();
Locale portalLocale = LocaleContextInfo.getLocale(portalLocaleName);
localeCtx.setPortalLocale(portalLocale);
localeCtx.setRequestLocale(reqCtx.getRequestLocale());
Locale locale = localePolicy.determineLocale(localeCtx);
boolean supported = supportedLocales.contains(locale);
if (!supported && !"".equals(locale.getCountry())) {