當前位置: 首頁>>代碼示例>>Java>>正文


Java SessionLocaleResolver類代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:xianrendzw,項目名稱:EasyReport,代碼行數:26,代碼來源:LocaleUtils.java

示例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;
}
 
開發者ID:yuanmomo,項目名稱:maven-archetype,代碼行數:25,代碼來源:I18nController.java

示例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;
}
 
開發者ID:e-gov,項目名稱:TARA-Server,代碼行數:9,代碼來源:CasWebAppConfiguration.java

示例4: localeResolver

import org.springframework.web.servlet.i18n.SessionLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver() {
    SessionLocaleResolver slr = new SessionLocaleResolver();
    // 默認語言
    slr.setDefaultLocale(Locale.CHINA);
    return slr;
}
 
開發者ID:kawhii,項目名稱:wolf,代碼行數:8,代碼來源:LocaleConfig.java

示例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);
}
 
開發者ID:KonkerLabs,項目名稱:konker-platform,代碼行數:32,代碼來源:UserDefinedLocaleHandlerInterceptor.java

示例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;
}
 
開發者ID:HiOA-ABI,項目名稱:nikita-noark5-core,代碼行數:12,代碼來源:AppWebMvcConfiguration.java

示例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);
}
 
開發者ID:dovier,項目名稱:coj-web,代碼行數:12,代碼來源:COJAuthenticationSuccessHandler.java

示例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;
}
 
開發者ID:gleb619,項目名稱:hotel_shop,代碼行數:13,代碼來源:TestConfig.java

示例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;
}
 
開發者ID:hpe-idol,項目名稱:find,代碼行數:8,代碼來源:AppConfiguration.java

示例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;
}
 
開發者ID:mv-informatica,項目名稱:components-html5,代碼行數:8,代碼來源:WebConfig.java

示例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");
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:38,代碼來源:ComplexWebApplicationContext.java

示例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;
}
 
開發者ID:SergioLarios,項目名稱:tuts-flow,代碼行數:9,代碼來源:UserJService.java

示例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)));
	}
}
 
開發者ID:CodeSphere,項目名稱:termitaria,代碼行數:17,代碼來源:GeneralFilter.java

示例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;
	}
 
開發者ID:CodeSphere,項目名稱:termitaria,代碼行數:31,代碼來源:ModulesController.java

示例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 - ");
}
 
開發者ID:CodeSphere,項目名稱:termitaria,代碼行數:19,代碼來源:GeneralFilter.java


注:本文中的org.springframework.web.servlet.i18n.SessionLocaleResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。