本文整理汇总了Java中org.springframework.web.servlet.i18n.FixedLocaleResolver类的典型用法代码示例。如果您正苦于以下问题:Java FixedLocaleResolver类的具体用法?Java FixedLocaleResolver怎么用?Java FixedLocaleResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FixedLocaleResolver类属于org.springframework.web.servlet.i18n包,在下文中一共展示了FixedLocaleResolver类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testInternalResourceViewResolverWithJstl
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void testInternalResourceViewResolverWithJstl() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
MockServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.addMessage("code1", locale, "messageX");
wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example1", ((JstlView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example2", ((JstlView) view).getUrl());
MockHttpServletRequest request = new MockHttpServletRequest(sc);
HttpServletResponse response = new MockHttpServletResponse();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
Map model = new HashMap();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, request, response);
assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
assertTrue("Correct rc attribute", request.getAttribute("rc") == null);
assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
assertEquals("messageX", lc.getResourceBundle().getString("code1"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:ViewResolverTests.java
示例2: testInternalResourceViewResolverWithJstlAndContextParam
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void testInternalResourceViewResolverWithJstlAndContextParam() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
MockServletContext sc = new MockServletContext();
sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.addMessage("code1", locale, "messageX");
wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example1", ((JstlView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example2", ((JstlView) view).getUrl());
MockHttpServletRequest request = new MockHttpServletRequest(sc);
HttpServletResponse response = new MockHttpServletResponse();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
Map model = new HashMap();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, request, response);
assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
assertTrue("Correct rc attribute", request.getAttribute("rc") == null);
assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
assertEquals("message1", lc.getResourceBundle().getString("code1"));
assertEquals("message2", lc.getResourceBundle().getString("code2"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java
示例3: localeFromResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void localeFromResolver() throws Exception {
Locale locale = Locale.ENGLISH;
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(locale));
MethodParameter localeParameter = new MethodParameter(method, 4);
assertTrue("Locale not supported", resolver.supportsParameter(localeParameter));
Object result = resolver.resolveArgument(localeParameter, null, webRequest, null);
assertSame("Invalid result", locale, result);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:ServletRequestMethodArgumentResolverTests.java
示例4: timeZoneFromResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void timeZoneFromResolver() throws Exception {
TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(Locale.US, timeZone));
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter));
Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null);
assertEquals("Invalid result", timeZone, result);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:ServletRequestMethodArgumentResolverTests.java
示例5: zoneIdFromResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void zoneIdFromResolver() throws Exception {
TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(Locale.US, timeZone));
MethodParameter zoneIdParameter = new MethodParameter(method, 9);
assertTrue("ZoneId not supported", resolver.supportsParameter(zoneIdParameter));
Object result = resolver.resolveArgument(zoneIdParameter, null, webRequest, null);
assertEquals("Invalid result", timeZone.toZoneId(), result);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:ServletRequestMethodArgumentResolverTests.java
示例6: overrideLocale
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void overrideLocale() throws Exception {
load(AllResources.class, "spring.mvc.locale:en_UK",
"spring.mvc.locale-resolver=fixed");
// mock request and set user preferred locale
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, "nl_NL");
LocaleResolver localeResolver = this.context.getBean(LocaleResolver.class);
assertThat(localeResolver).isInstanceOf(FixedLocaleResolver.class);
Locale locale = localeResolver.resolveLocale(request);
// test locale resolver uses fixed locale and not user preferred locale
assertThat(locale.toString()).isEqualTo("en_UK");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:WebMvcAutoConfigurationTests.java
示例7: overrideLocale
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void overrideLocale() throws Exception {
load(AllResources.class, "spring.mvc.locale:en_UK");
// mock request and set user preferred locale
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
LocaleResolver localeResolver = this.context.getBean(LocaleResolver.class);
Locale locale = localeResolver.resolveLocale(request);
assertThat(localeResolver).isInstanceOf(FixedLocaleResolver.class);
// test locale resolver uses fixed locale and not user preferred locale
assertThat(locale.toString()).isEqualTo("en_UK");
}
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:13,代码来源:WebMvcAutoConfigurationTests.java
示例8: overrideLocale
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void overrideLocale() throws Exception {
load(AllResources.class, "spring.mvc.locale:en_UK");
// mock request and set user preferred locale
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
LocaleResolver localeResolver = this.context.getBean(LocaleResolver.class);
Locale locale = localeResolver.resolveLocale(request);
assertThat(localeResolver, instanceOf(FixedLocaleResolver.class));
// test locale resolver uses fixed locale and not user preferred locale
assertThat(locale.toString(), equalTo("en_UK"));
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:14,代码来源:WebMvcAutoConfigurationTests.java
示例9: tilesJstlView
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void tilesJstlView() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
StaticWebApplicationContext wac = prepareWebApplicationContext();
InternalResourceViewResolver irvr = new InternalResourceViewResolver();
irvr.setApplicationContext(wac);
irvr.setViewClass(TilesJstlView.class);
View view = irvr.resolveViewName("testTile", new Locale("nl", ""));
MockHttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
MockHttpServletResponse response = new MockHttpServletResponse();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
wac.addMessage("code1", locale, "messageX");
view.render(new HashMap<String, Object>(), request, response);
assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
ComponentContext cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
assertNotNull(cc);
PathAttribute attr = (PathAttribute) cc.getAttribute("content");
assertEquals("/WEB-INF/jsp/content.jsp", attr.getValue());
assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
assertEquals("messageX", lc.getResourceBundle().getString("code1"));
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:29,代码来源:TilesViewTests.java
示例10: tilesJstlViewWithContextParam
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Test
public void tilesJstlViewWithContextParam() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
StaticWebApplicationContext wac = prepareWebApplicationContext();
((MockServletContext) wac.getServletContext()).addInitParameter(
Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/servlet/view/tiles/context-messages");
InternalResourceViewResolver irvr = new InternalResourceViewResolver();
irvr.setApplicationContext(wac);
irvr.setViewClass(TilesJstlView.class);
View view = irvr.resolveViewName("testTile", new Locale("nl", ""));
MockHttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
MockHttpServletResponse response = new MockHttpServletResponse();
wac.addMessage("code1", locale, "messageX");
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
view.render(new HashMap<String, Object>(), request, response);
assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
ComponentContext cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
assertNotNull(cc);
PathAttribute attr = (PathAttribute) cc.getAttribute("content");
assertEquals("/WEB-INF/jsp/content.jsp", attr.getValue());
LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
assertEquals("message1", lc.getResourceBundle().getString("code1"));
assertEquals("message2", lc.getResourceBundle().getString("code2"));
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:31,代码来源:TilesViewTests.java
示例11: localeResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Bean
public LocaleResolver localeResolver() {
return new FixedLocaleResolver(Locale.ENGLISH);
}
开发者ID:xabgesagtx,项目名称:mensa-api,代码行数:5,代码来源:ThymeleafConfig.java
示例12: localeResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.mvc", name = "locale")
public LocaleResolver localeResolver() {
return new FixedLocaleResolver(this.mvcProperties.getLocale());
}
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:7,代码来源:WebMvcAutoConfiguration.java
示例13: localeResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Bean
public LocaleResolver localeResolver() {
return new FixedLocaleResolver(new Locale("pt", "BR"));
}
开发者ID:gsag,项目名称:Estudo-Spring,代码行数:5,代码来源:WebMvcConfiguration.java
示例14: localeResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Bean
public LocaleResolver localeResolver() {
return new FixedLocaleResolver(new Locale("pt", "BR"));
}
开发者ID:gsag,项目名称:spring-mvc-seed,代码行数:5,代码来源:WebMvcConfiguration.java
示例15: localeSettingFilter
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Bean
public Filter localeSettingFilter() {
LocaleSettingFilter filter = new LocaleSettingFilter();
filter.setLocaleResolver(new FixedLocaleResolver(Locale.ENGLISH));
return filter;
}
开发者ID:CeON,项目名称:saos,代码行数:7,代码来源:SecurityConfiguration.java
示例16: localeResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Bean
public LocaleResolver localeResolver() {
return new FixedLocaleResolver(new Locale("pl"));
}
开发者ID:CeON,项目名称:saos,代码行数:5,代码来源:GeneralConfiguration.java
示例17: fixedLocaleResolver
import org.springframework.web.servlet.i18n.FixedLocaleResolver; //导入依赖的package包/类
@Bean
public FixedLocaleResolver fixedLocaleResolver() {
FixedLocaleResolver resolver = new FixedLocaleResolver();
resolver.setDefaultLocale(Locale.CHINA);
return resolver;
}
开发者ID:bingoohuang,项目名称:quartz-glass,代码行数:7,代码来源:SpringConfig.java
注:本文中的org.springframework.web.servlet.i18n.FixedLocaleResolver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论