当前位置: 首页>>代码示例>>Java>>正文


Java LocaleResolver.setLocale方法代码示例

本文整理汇总了Java中org.springframework.web.servlet.LocaleResolver.setLocale方法的典型用法代码示例。如果您正苦于以下问题:Java LocaleResolver.setLocale方法的具体用法?Java LocaleResolver.setLocale怎么用?Java LocaleResolver.setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.servlet.LocaleResolver的用法示例。


在下文中一共展示了LocaleResolver.setLocale方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: preHandle

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
	if (request.getUserPrincipal() != null) {
		String codiIdioma = request.getParameter(this.paramName);
		
		if (codiIdioma != null) {
			personaService.savePrefIdioma(codiIdioma);
			LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
			if (localeResolver == null)
				throw new IllegalStateException  ("No LocaleResolver found: not in a DispatcherServlet request?");
			LocaleEditor localeEditor = new LocaleEditor();
			localeEditor.setAsText(codiIdioma);
			localeResolver.setLocale(request, response, (Locale)localeEditor.getValue());
		}
	}
	return true;
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:17,代码来源:IdiomaInterceptor.java

示例2: changeLanguage

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@RequestMapping(value = "/api/v1/language", method = RequestMethod.POST)
public String changeLanguage(@ModelAttribute("lang") String language,
                             HttpServletRequest request, HttpServletResponse response) {
    final LocaleResolver localeResolver = getLocaleResolver(request);
    final Locale locale = StringUtils.parseLocaleString(language);

    if (locale != null) {
        localeResolver.setLocale(request, response, locale);

        return locale.toLanguageTag();
    }

    LOG.error("Could not parse language={}", language);

    return localeResolver.resolveLocale(request).toLanguageTag();
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:17,代码来源:LanguageChangeController.java

示例3: preHandle

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
    String newLocale = request.getParameter(getParamName());
    if(newLocale != null) {
        LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
        if(localeResolver == null) {
            throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
        }

        Locale locale = StringUtils.parseLocaleString(newLocale);
        localeResolver.setLocale(request, response, locale);
        localeHolder.setLocale(locale);
    }

    return true;
}
 
开发者ID:Javakit,项目名称:Javakit,代码行数:17,代码来源:LocaleChangeInterceptorWrapper.java

示例4: preHandle

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request,
		HttpServletResponse response, Object handler)
		throws ServletException {
	LocaleResolver localeResolver = RequestContextUtils
			.getLocaleResolver(request);
	if (localeResolver == null) {
		throw new IllegalStateException(
				"No LocaleResolver found: not in a DispatcherServlet request?");
	}
//	CmsSite site = CmsUtils.getSite(request);
	CmsSite site=CmsThreadVariable.getSite();
	String newLocale = site.getLocaleAdmin();
	LocaleEditor localeEditor = new LocaleEditor();
	localeEditor.setAsText(newLocale);
	localeResolver.setLocale(request, response, (Locale) localeEditor
			.getValue());
	// Proceed in any case.
	return true;
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:21,代码来源:AdminLocaleInterceptor.java

示例5: preHandle

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request,
		HttpServletResponse response, Object handler)
		throws ServletException {
	LocaleResolver localeResolver = RequestContextUtils
			.getLocaleResolver(request);
	if (localeResolver == null) {
		throw new IllegalStateException(
				"No LocaleResolver found: not in a DispatcherServlet request?");
	}
	CmsSite site = CmsUtils.getSite(request);
	String newLocale = site.getLocaleFront();
	LocaleEditor localeEditor = new LocaleEditor();
	localeEditor.setAsText(newLocale);
	localeResolver.setLocale(request, response, (Locale) localeEditor
			.getValue());
	// Proceed in any case.
	return true;
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:20,代码来源:FrontLocaleInterceptor.java

示例6: internalTest

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
private void internalTest(LocaleResolver localeResolver, boolean shouldSet) {
	// create mocks
	MockServletContext context = new MockServletContext();
	MockHttpServletRequest request = new MockHttpServletRequest(context);
	request.addPreferredLocale(Locale.UK);
	MockHttpServletResponse response = new MockHttpServletResponse();
	// check original locale
	Locale locale = localeResolver.resolveLocale(request);
	assertEquals(locale, Locale.UK);
	// set new locale
	try {
		localeResolver.setLocale(request, response, Locale.GERMANY);
		if (!shouldSet)
			fail("should not be able to set Locale");
		// check new locale
		locale = localeResolver.resolveLocale(request);
		assertEquals(locale, Locale.GERMANY);
	}
	catch (UnsupportedOperationException ex) {
		if (shouldSet)
			fail("should be able to set Locale");
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:LocaleResolverTests.java

示例7: preHandle

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request,
		HttpServletResponse response, Object handler)
		throws ServletException {
	LocaleResolver localeResolver = RequestContextUtils
			.getLocaleResolver(request);
	if (localeResolver == null) {
		throw new IllegalStateException(
				"No LocaleResolver found: not in a DispatcherServlet request?");
	}
	CmsSite site = CmsUtils.getSite(request);
	String newLocale = site.getLocaleAdmin();
	LocaleEditor localeEditor = new LocaleEditor();
	localeEditor.setAsText(newLocale);
	localeResolver.setLocale(request, response, (Locale) localeEditor
			.getValue());
	// Proceed in any case.
	return true;
}
 
开发者ID:caipiao,项目名称:Lottery,代码行数:20,代码来源:AdminLocaleInterceptor.java

示例8: preHandle

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
    Object newLocale = request.getAttribute(LOCALE_ATTRIBUTE_NAME);
    if (newLocale != null) {
        LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
        if (localeResolver == null) {
            throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
        }
        localeResolver.setLocale(request, response, StringUtils.parseLocaleString(newLocale.toString()));
    }
    return true;
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:13,代码来源:YadaLocalePathChangeInterceptor.java

示例9: changeLang

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@RequestMapping(value = "/changeLang", method = RequestMethod.POST)
@ResponseBody
public String changeLang(HttpServletRequest request, HttpServletResponse response, @RequestParam String lang){
    LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
    if ("zh".equals(lang)) {
        // request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, new Locale("zh", "CN"));
        localeResolver.setLocale(request, response, new Locale("zh", "CN"));
    } else if("en".equals(lang)){
        // request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, new Locale("en", "US"));
        localeResolver.setLocale(request, response, new Locale("en", "US"));
    }
    return "lang:" + LocaleContextHolder.getLocale().getLanguage();
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:14,代码来源:SampleController.java

示例10: changeLocale

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
/**
 * Change the current locale to the specified one,
 * storing the new locale through the configured {@link LocaleResolver}.
 * @param locale the new locale
 * @see LocaleResolver#setLocale
 * @see #changeLocale(java.util.Locale, java.util.TimeZone)
 */
public void changeLocale(Locale locale) {
	LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(this.request);
	if (localeResolver == null) {
		throw new IllegalStateException("Cannot change locale if no LocaleResolver configured");
	}
	localeResolver.setLocale(this.request, this.response, locale);
	this.locale = locale;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:RequestContext.java

示例11: preHandle

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws ServletException {

	String newLocale = request.getParameter(getParamName());
	if (newLocale != null) {
		if (checkHttpMethod(request.getMethod())) {
			LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
			if (localeResolver == null) {
				throw new IllegalStateException(
						"No LocaleResolver found: not in a DispatcherServlet request?");
			}
			try {
				localeResolver.setLocale(request, response, StringUtils.parseLocaleString(newLocale));
			}
			catch (IllegalArgumentException ex) {
				if (isIgnoreInvalidLocale()) {
					logger.debug("Ignoring invalid locale value [" + newLocale + "]: " + ex.getMessage());
				}
				else {
					throw ex;
				}
			}
		}
	}
	// Proceed in any case.
	return true;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:LocaleChangeInterceptor.java

示例12: setLocale

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
/**
 * 根据用户语言设置Locale信息.
 * @param request - HttpRequest对象
 * @param response - HttpResponse对象
 * @param language - 语言的名称(例如zh_CN)
 */
public static void setLocale(HttpServletRequest request, HttpServletResponse response, String language) {
	Locale locale = LocaleUtils.getLocaleOfLanguage(language);
	LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
	localeResolver.setLocale(request, response, locale);
	request.getSession().setAttribute("language", language);
}
 
开发者ID:hzxie,项目名称:voj,代码行数:13,代码来源:LocaleUtils.java

示例13: preHandle

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws ServletException {

	String newLocale = request.getParameter(this.paramName);
	if (newLocale != null) {
		LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
		if (localeResolver == null) {
			throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
		}
		localeResolver.setLocale(request, response, StringUtils.parseLocaleString(newLocale));
	}
	// Proceed in any case.
	return true;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:16,代码来源:LocaleChangeInterceptor.java

示例14: setLocale

import org.springframework.web.servlet.LocaleResolver; //导入方法依赖的package包/类
protected void setLocale(HttpServletRequest request, HttpServletResponse response, String newLocale) {
	if (newLocale != null) {
		LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
		if (localeResolver == null) {
			logger.debug("No LocaleResolver found: not in a DispatcherServlet request?");
			return;
		}
		LocaleEditor localeEditor = new LocaleEditor();
		localeEditor.setAsText(newLocale);
		localeResolver.setLocale(request, response, (Locale) localeEditor.getValue());
	}
}
 
开发者ID:mobilipia,项目名称:Deskera-HRMS,代码行数:13,代码来源:authHandlerController.java


注:本文中的org.springframework.web.servlet.LocaleResolver.setLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。