本文整理匯總了Java中org.springframework.web.servlet.i18n.SessionLocaleResolver類的典型用法代碼示例。如果您正苦於以下問題:Java SessionLocaleResolver類的具體用法?Java SessionLocaleResolver怎麽用?Java SessionLocaleResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SessionLocaleResolver類屬於org.springframework.web.servlet.i18n包,在下文中一共展示了SessionLocaleResolver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setInitLocale
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
/**
* 根據當前request對象中的locale(Header的Accept屬性)初始化係統國際化語言區域環境
*
* @param request 當前請求對象
* @param response 當前響應對象
*/
public static void setInitLocale(final HttpServletRequest request, final HttpServletResponse response) {
final Locale locale = request.getLocale();
log.info("Init locale from user request,country:{},lang:{}", locale.getCountry(), locale.toLanguageTag());
if (localeResolver instanceof CookieLocaleResolver) {
final CookieLocaleResolver cookieLocaleResolver = (CookieLocaleResolver)localeResolver;
final Cookie cookie = WebUtils.getCookie(request, cookieLocaleResolver.getCookieName());
if (cookie == null) {
setLocale(locale.toLanguageTag(), request, response);
}
}
if (localeResolver instanceof SessionLocaleResolver) {
final Locale sessionLocale = (Locale)WebUtils.getRequiredSessionAttribute(
request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
if (sessionLocale == null) {
setLocale(locale.toLanguageTag(), request, response);
}
}
}
示例2: lang
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
/**
* 切換國際化語言,langType=zh,中文;langType=en,英文。
*
* @param langType 切換的語言類型。
* @param request
* @return
*/
@RequestMapping("lang.do")
@ResponseBody
public String lang(
@RequestParam("langType") String langType,
HttpServletRequest request){
Locale locale = null;
if("zh".equalsIgnoreCase(langType)){
locale = new Locale("zh", "CN");
}
else if("en".equalsIgnoreCase(langType)){
locale = new Locale("en", "US");
}else {
LocaleContextHolder.getLocale();
}
request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,locale);
return null;
}
示例3: localeResolver
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver bean = new SessionLocaleResolver();
String locale = this.casProperties.getLocale().getDefaultValue();
this.log.debug("Setting default locale to [{}]", locale);
bean.setDefaultLocale(new Locale(locale));
return bean;
}
示例4: localeResolver
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
// 默認語言
slr.setDefaultLocale(Locale.CHINA);
return slr;
}
示例5: preHandle
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication()).isPresent() &&
SecurityContextHolder.getContext().getAuthentication().getPrincipal()
instanceof User) {
try {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (Optional.ofNullable(request.getSession()).isPresent()
&& Optional.ofNullable(user).isPresent()) {
if (!Optional.ofNullable(request.getSession()
.getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME)).isPresent() ||
!request.getSession().getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME)
.equals(user.getLanguage().getLocale())) {
request.getSession().setAttribute(
SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
user.getLanguage().getLocale());
}
}
} catch (ClassCastException e){
User invalidUSer = User.builder().name("INVALID USER").tenant(Tenant.builder().name("INVALID TENANT").build()).build();
LOG.error("Invalid user type on session",
invalidUSer.toURI(),
invalidUSer.getTenant().getLogLevel(),
e);
}
}
return super.preHandle(request, response, handler);
}
示例6: localeResolver
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
/**
* Set the LocaleResolver for the GUI portion of the application
* By default english pages with be returned to the user
* @return LocaleResolver
*/
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
slr.setDefaultLocale(Locale.US);
return slr;
}
示例7: onAuthenticationSuccess
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
String username = ((User)authentication.getPrincipal()).getUsername();
String locale = userDAO.getUserLocale(username);
SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
sessionLocaleResolver.setLocale(request, response, new Locale(locale));
userDAO.registerLogin(true, request.getRemoteAddr(), ((User) authentication.getPrincipal()).getUsername());
setDefaultTargetUrl(determineTargetUrl(request));
super.onAuthenticationSuccess(request, response, authentication);
}
示例8: sessionLocaleResolver
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
/**
* Session locale resolver.
*
* @return the session locale resolver
*/
@Bean(name = "localeResolver")
public SessionLocaleResolver sessionLocaleResolver() {
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
localeResolver.setDefaultLocale(new Locale("ru"));
return localeResolver;
}
示例9: localeResolver
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver() {
final SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
sessionLocaleResolver.setDefaultLocale(Locale.ENGLISH);
return sessionLocaleResolver;
}
示例10: localeResolver
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Bean
@Override
public LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
slr.setDefaultLocale(new Locale("pt-BR"));
return slr;
}
示例11: doSomething
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Override
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException {
WebApplicationContext wac = RequestContextUtils.getWebApplicationContext(request);
if (!(wac instanceof ComplexWebApplicationContext)) {
throw new ServletException("Incorrect WebApplicationContext");
}
if (!(request instanceof MultipartHttpServletRequest)) {
throw new ServletException("Not in a MultipartHttpServletRequest");
}
if (!(RequestContextUtils.getLocaleResolver(request) instanceof SessionLocaleResolver)) {
throw new ServletException("Incorrect LocaleResolver");
}
if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) {
throw new ServletException("Incorrect Locale");
}
if (!Locale.CANADA.equals(LocaleContextHolder.getLocale())) {
throw new ServletException("Incorrect Locale");
}
if (!(RequestContextUtils.getThemeResolver(request) instanceof SessionThemeResolver)) {
throw new ServletException("Incorrect ThemeResolver");
}
if (!"theme".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
throw new ServletException("Incorrect theme name");
}
if (request.getParameter("fail") != null) {
throw new ModelAndViewDefiningException(new ModelAndView("failed1"));
}
if (request.getParameter("access") != null) {
throw new IllegalAccessException("illegal access");
}
if (request.getParameter("servlet") != null) {
throw new ServletRequestBindingException("servlet");
}
if (request.getParameter("exception") != null) {
throw new RuntimeException("servlet");
}
}
示例12: UserJService
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Autowired
public UserJService(UserLocalService userLocalService,
ReloadableResourceBundleMessageSource messageSource,
SessionLocaleResolver localeResolver) {
this.userLocalService = userLocalService;
this.messageSource = messageSource;
this.localeResolver = localeResolver;
}
示例13: interceptLanguagePreference
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
/**
* Intercepts the selected language
*
* @author Adelina
* @param request
*/
private void interceptLanguagePreference(HttpServletRequest request) {
logger.debug("interceptLanguagePreference");
if (request.getParameter(IConstant.LANGUAGE_ATTRIBUTE) != null) {
logger.debug("siteLanguage: " + request.getParameter(IConstant.LANGUAGE_ATTRIBUTE));
// put on session
request.getSession().setAttribute(
SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
new Locale(request.getParameter(IConstant.LANGUAGE_ATTRIBUTE)));
}
}
示例14: handleRequestInternal
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.debug("===============================================");
logger.debug("=========== MODULES CONTROLLER ================");
logger.debug("===============================================");
ModelAndView mav = new ModelAndView(getView());
InetAddress.getLocalHost().getHostAddress();
UserAuth userAuth = (UserAuth)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
mav.addObject("username", userAuth.getUsername());
// mav.addObject(IS_ADMIN_IT, userAuth.isAdminIT());
// mav.addObject(MODULES, userAuth.getModules());
request.getSession().setAttribute(IS_ADMIN_IT, userAuth.isAdminIT());
request.getSession().setAttribute(MODULES, userAuth.getModules());
Locale locale = (Locale)request.getSession().getAttribute(
SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
if(locale != null){
mav.addObject(IConstant.LANGUAGE_ATTRIBUTE, (locale.getLanguage()));
}else{
mav.addObject(IConstant.LANGUAGE_ATTRIBUTE, ("ro"));
}
Module omModule = BLModule.getInstance().get(IConstant.OM_MODULE);
mav.addObject(OM_MODULE_ID, omModule.getModuleId());
return mav;
}
示例15: interceptLanguagePreference
import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
/**
* Intercepts the selected language
*
* @author Adelina
* @param request
*/
private void interceptLanguagePreference(HttpServletRequest request) {
logger.debug("interceptLanguagePreference - START - ");
if (request.getParameter(IConstant.LANGUAGE_ATTRIBUTE) != null) {
logger.debug("siteLanguage: " + request.getParameter(IConstant.LANGUAGE_ATTRIBUTE));
// put on session
request.getSession().setAttribute(
SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
new Locale(request
.getParameter(IConstant.LANGUAGE_ATTRIBUTE)));
}
logger.debug("interceptLanguagePreference - END - ");
}