Java Code Examples for org.springframework.beans.propertyeditors.LocaleEditor#setAsText()

The following examples show how to use org.springframework.beans.propertyeditors.LocaleEditor#setAsText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdminLocaleInterceptor.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: FrontLocaleInterceptor.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: IndexAction.java    From albert with MIT License 5 votes vote down vote up
/**
 * 国家化语言
 *
 * @param modelMap
 * @return
 * @throws IOException 
 */
@ResponseBody
@RequestMapping(value = "/changeLanguage", method = {RequestMethod.POST,RequestMethod.GET})
public Map changeLanguage( 
		@RequestParam(
				value="language", required=false) String language,
				HttpServletRequest request,
				HttpServletResponse reponse,
				ModelMap modelMap)  {
	Map<String,Object> map = new HashMap<String,Object>();
	map.put("msg","");
	map.put("res","false");
	try {
		request.getSession().setAttribute(Constants.SYS_LANGUAGE_SESSION_KEY, language);
		LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
		if (localeResolver == null) {
			log.debug("No LocaleResolver found: not in a DispatcherServlet request?");
		}
		LocaleEditor localeEditor = new LocaleEditor();
		localeEditor.setAsText(language);
		localeResolver.setLocale(request, reponse, (Locale) localeEditor.getValue());
		map.put("res", "true");
	}
	catch(Exception e){
		log.debug("修改系统语言 /changeLanguage.do", e); 
	}
	return map;  
}
 
Example 4
Source File: FrontUtils.java    From Lottery with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 获得模板路径。将对模板文件名称进行本地化处理。
 * 
 * @param messageSource
 * @param lang
 *            本地化语言
 * @param solution
 *            方案路径
 * @param dir
 *            模板目录。不本地化处理。
 * @param name
 *            模板名称。本地化处理。
 * @return
 */
public static String getTplPath(MessageSource messageSource, String lang,
		String solution, String dir, String name) {
	LocaleEditor localeEditor = new LocaleEditor();
	localeEditor.setAsText(lang);
	Locale locale = (Locale) localeEditor.getValue();
	return solution + "/" + dir + "/"
			+ messageSource.getMessage(name, null, locale) + TPL_SUFFIX;
}