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


Java AcceptHeaderLocaleResolver类代码示例

本文整理汇总了Java中org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver的典型用法代码示例。如果您正苦于以下问题:Java AcceptHeaderLocaleResolver类的具体用法?Java AcceptHeaderLocaleResolver怎么用?Java AcceptHeaderLocaleResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AcceptHeaderLocaleResolver类属于org.springframework.web.servlet.i18n包,在下文中一共展示了AcceptHeaderLocaleResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	wac = new StaticWebApplicationContext();
	wac.setServletContext(new MockServletContext());

	// final Template expectedTemplate = new Template();
	fc = new FreeMarkerConfigurer();
	fc.setTemplateLoaderPaths("classpath:/", "file://" + System.getProperty("java.io.tmpdir"));
	fc.afterPropertiesSet();

	wac.getDefaultListableBeanFactory().registerSingleton("freeMarkerConfigurer", fc);
	wac.refresh();

	request = new MockHttpServletRequest();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	response = new MockHttpServletResponse();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:FreeMarkerMacroTests.java

示例2: setUp

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	wac = new StaticWebApplicationContext();
	wac.setServletContext(new MockServletContext());

	final Template expectedTemplate = new Template();
	VelocityConfig vc = new VelocityConfig() {
		@Override
		public VelocityEngine getVelocityEngine() {
			return new TestVelocityEngine("test.vm", expectedTemplate);
		}
	};
	wac.getDefaultListableBeanFactory().registerSingleton("velocityConfigurer", vc);
	wac.refresh();

	request = new MockHttpServletRequest();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	response = new MockHttpServletResponse();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:VelocityRenderTests.java

示例3: setUp

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	wac = new StaticWebApplicationContext();
	wac.setServletContext(new MockServletContext());

	final Template expectedTemplate = new Template();
	VelocityConfig vc = new VelocityConfig() {
		@Override
		public VelocityEngine getVelocityEngine() {
			return new TestVelocityEngine(TEMPLATE_FILE, expectedTemplate);
		}
	};
	wac.getDefaultListableBeanFactory().registerSingleton("velocityConfigurer", vc);
	wac.refresh();

	request = new MockHttpServletRequest();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	response = new MockHttpServletResponse();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:VelocityMacroTests.java

示例4: createPageContext

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
protected MockPageContext createPageContext() {
	MockServletContext sc = new MockServletContext();
	SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
	wac.setServletContext(sc);
	wac.setNamespace("test");
	wac.refresh();

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	MockHttpServletResponse response = new MockHttpServletResponse();
	if (inDispatcherServlet()) {
		request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
		LocaleResolver lr = new AcceptHeaderLocaleResolver();
		request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
		ThemeResolver tr = new FixedThemeResolver();
		request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
		request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);
	}
	else {
		sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	}

	return new MockPageContext(sc, request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:AbstractTagTests.java

示例5: setUp

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	wac = new StaticWebApplicationContext();
	wac.setServletContext(new MockServletContext());

	// final Template expectedTemplate = new Template();
	fc = new FreeMarkerConfigurer();
	fc.setTemplateLoaderPaths(new String[] { "classpath:/", "file://" + System.getProperty("java.io.tmpdir") });
	fc.afterPropertiesSet();

	wac.getDefaultListableBeanFactory().registerSingleton("freeMarkerConfigurer", fc);
	wac.refresh();

	request = new MockHttpServletRequest();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	response = new MockHttpServletResponse();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:FreeMarkerMacroTests.java

示例6: setUp

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
	wac = new StaticWebApplicationContext();
	wac.setServletContext(new MockServletContext());

	final Template expectedTemplate = new Template();
	VelocityConfig vc = new VelocityConfig() {
		@Override
		public VelocityEngine getVelocityEngine() {
			return new TestVelocityEngine(TEMPLATE_FILE, expectedTemplate);
		}
	};
	wac.getDefaultListableBeanFactory().registerSingleton("velocityConfigurer", vc);
	wac.refresh();

	request = new MockHttpServletRequest();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	response = new MockHttpServletResponse();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:VelocityMacroTests.java

示例7: createPageContext

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
protected MockPageContext createPageContext() {
	MockServletContext sc = new MockServletContext();
	sc.addInitParameter("springJspExpressionSupport", "true");
	SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
	wac.setServletContext(sc);
	wac.setNamespace("test");
	wac.refresh();

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	MockHttpServletResponse response = new MockHttpServletResponse();
	if (inDispatcherServlet()) {
		request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
		LocaleResolver lr = new AcceptHeaderLocaleResolver();
		request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
		ThemeResolver tr = new FixedThemeResolver();
		request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
		request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);
	}
	else {
		sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	}

	return new MockPageContext(sc, request, response);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:25,代码来源:AbstractTagTests.java

示例8: createPageContext

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
protected MockPageContext createPageContext() {
    MockServletContext sc = new MockServletContext();
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);
    wac.setNamespace("test");
    wac.registerSingleton("validator",
            org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.class);
    wac.refresh();

    MockHttpServletRequest request = new MockHttpServletRequest(sc);
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    LocaleResolver lr = new AcceptHeaderLocaleResolver();
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
    ThemeResolver tr = new FixedThemeResolver();
    request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
    request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);

    return new MockPageContext(sc, request, response);
}
 
开发者ID:arey,项目名称:spring-mvc-toolkit,代码行数:21,代码来源:TestHtml5InputTag.java

示例9: doTestUrlBasedViewResolverWithoutPrefixes

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
private void doTestUrlBasedViewResolverWithoutPrefixes(UrlBasedViewResolver vr) throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(new MockServletContext());
	wac.refresh();
	vr.setApplicationContext(wac);
	vr.setContentType("myContentType");
	vr.setRequestContextAttribute("rc");

	View view = vr.resolveViewName("example1", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example1", ((InternalResourceView) view).getUrl());
	assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType());

	view = vr.resolveViewName("example2", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example2", ((InternalResourceView) view).getUrl());
	assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType());

	HttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	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") instanceof RequestContext);

	view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
	assertEquals("Correct view class", RedirectView.class, view.getClass());
	assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl());
	assertSame("View not initialized as bean", wac, ((RedirectView) view).getApplicationContext());

	view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
	assertEquals("Correct view class", InternalResourceView.class, view.getClass());
	assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java

示例10: testInternalResourceViewResolverWithContextBeans

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Test
public void testInternalResourceViewResolverWithContextBeans() throws Exception {
	MockServletContext sc = new MockServletContext();
	final StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("myBean", TestBean.class);
	wac.registerSingleton("myBean2", TestBean.class);
	wac.setServletContext(sc);
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	Properties props = new Properties();
	props.setProperty("key1", "value1");
	vr.setAttributes(props);
	Map map = new HashMap();
	map.put("key2", new Integer(2));
	vr.setAttributesMap(map);
	vr.setExposeContextBeansAsAttributes(true);
	vr.setApplicationContext(wac);

	MockHttpServletRequest request = new MockHttpServletRequest(sc) {
		@Override
		public RequestDispatcher getRequestDispatcher(String path) {
			return new MockRequestDispatcher(path) {
				@Override
				public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
					assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
					assertEquals("value1", forwardRequest.getAttribute("key1"));
					assertEquals(new Integer(2), forwardRequest.getAttribute("key2"));
					assertSame(wac.getBean("myBean"), forwardRequest.getAttribute("myBean"));
					assertSame(wac.getBean("myBean2"), forwardRequest.getAttribute("myBean2"));
				}
			};
		}
	};
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	View view = vr.resolveViewName("example1", Locale.getDefault());
	view.render(new HashMap(), request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java

示例11: testInternalResourceViewResolverWithSpecificContextBeans

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Test
public void testInternalResourceViewResolverWithSpecificContextBeans() throws Exception {
	MockServletContext sc = new MockServletContext();
	final StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("myBean", TestBean.class);
	wac.registerSingleton("myBean2", TestBean.class);
	wac.setServletContext(sc);
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	Properties props = new Properties();
	props.setProperty("key1", "value1");
	vr.setAttributes(props);
	Map map = new HashMap();
	map.put("key2", new Integer(2));
	vr.setAttributesMap(map);
	vr.setExposedContextBeanNames(new String[] {"myBean2"});
	vr.setApplicationContext(wac);

	MockHttpServletRequest request = new MockHttpServletRequest(sc) {
		@Override
		public RequestDispatcher getRequestDispatcher(String path) {
			return new MockRequestDispatcher(path) {
				@Override
				public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
					assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
					assertEquals("value1", forwardRequest.getAttribute("key1"));
					assertEquals(new Integer(2), forwardRequest.getAttribute("key2"));
					assertNull(forwardRequest.getAttribute("myBean"));
					assertSame(wac.getBean("myBean2"), forwardRequest.getAttribute("myBean2"));
				}
			};
		}
	};
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	View view = vr.resolveViewName("example1", Locale.getDefault());
	view.render(new HashMap(), request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java

示例12: validTemplateName

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Test
public void validTemplateName() throws Exception {
	FreeMarkerView fv = new FreeMarkerView();

	WebApplicationContext wac = mock(WebApplicationContext.class);
	MockServletContext sc = new MockServletContext();

	Map<String, FreeMarkerConfig> configs = new HashMap<String, FreeMarkerConfig>();
	FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
	configurer.setConfiguration(new TestConfiguration());
	configs.put("configurer", configurer);
	given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
	given(wac.getServletContext()).willReturn(sc);

	fv.setUrl("templateName");
	fv.setApplicationContext(wac);

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addPreferredLocale(Locale.US);
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	HttpServletResponse response = new MockHttpServletResponse();

	Map<String, Object> model = new HashMap<String, Object>();
	model.put("myattr", "myvalue");
	fv.render(model, request, response);

	assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, response.getContentType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:FreeMarkerViewTests.java

示例13: keepExistingContentType

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Test
public void keepExistingContentType() throws Exception {
	FreeMarkerView fv = new FreeMarkerView();

	WebApplicationContext wac = mock(WebApplicationContext.class);
	MockServletContext sc = new MockServletContext();

	Map<String, FreeMarkerConfig> configs = new HashMap<String, FreeMarkerConfig>();
	FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
	configurer.setConfiguration(new TestConfiguration());
	configs.put("configurer", configurer);
	given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
	given(wac.getServletContext()).willReturn(sc);

	fv.setUrl("templateName");
	fv.setApplicationContext(wac);

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addPreferredLocale(Locale.US);
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	HttpServletResponse response = new MockHttpServletResponse();
	response.setContentType("myContentType");

	Map<String, Object> model = new HashMap<String, Object>();
	model.put("myattr", "myvalue");
	fv.render(model, request, response);

	assertEquals("myContentType", response.getContentType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:FreeMarkerViewTests.java

示例14: handleRequest

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	if (!(RequestContextUtils.getWebApplicationContext(request) instanceof SimpleWebApplicationContext)) {
		throw new ServletException("Incorrect WebApplicationContext");
	}
	if (!(RequestContextUtils.getLocaleResolver(request) instanceof AcceptHeaderLocaleResolver)) {
		throw new ServletException("Incorrect LocaleResolver");
	}
	if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) {
		throw new ServletException("Incorrect Locale");
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:SimpleWebApplicationContext.java

示例15: useAcceptHeaderLocale

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; //导入依赖的package包/类
@Test
public void useAcceptHeaderLocale() {
	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"));
	request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, "nl_NL");
	LocaleResolver localeResolver = this.context.getBean(LocaleResolver.class);
	assertThat(localeResolver).isInstanceOf(AcceptHeaderLocaleResolver.class);
	Locale locale = localeResolver.resolveLocale(request);
	// test locale resolver uses user preferred locale
	assertThat(locale.toString()).isEqualTo("nl_NL");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:WebMvcAutoConfigurationTests.java


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