org.springframework.web.servlet.ThemeResolver Java Examples

The following examples show how to use org.springframework.web.servlet.ThemeResolver. 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: ThemeResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void internalTest(ThemeResolver themeResolver, boolean shouldSet, String defaultName) {
	// create mocks
	MockServletContext context = new MockServletContext();
	MockHttpServletRequest request = new MockHttpServletRequest(context);
	MockHttpServletResponse response = new MockHttpServletResponse();
	// check original theme
	String themeName = themeResolver.resolveThemeName(request);
	assertEquals(themeName, defaultName);
	// set new theme name
	try {
		themeResolver.setThemeName(request, response, TEST_THEME_NAME);
		if (!shouldSet)
			fail("should not be able to set Theme name");
		// check new theme namelocale
		themeName = themeResolver.resolveThemeName(request);
		assertEquals(TEST_THEME_NAME, themeName);
		themeResolver.setThemeName(request, response, null);
		themeName = themeResolver.resolveThemeName(request);
		assertEquals(themeName, defaultName);
	}
	catch (UnsupportedOperationException ex) {
		if (shouldSet)
			fail("should be able to set Theme name");
	}
}
 
Example #2
Source File: ThemeResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void internalTest(ThemeResolver themeResolver, boolean shouldSet, String defaultName) {
	// create mocks
	MockServletContext context = new MockServletContext();
	MockHttpServletRequest request = new MockHttpServletRequest(context);
	MockHttpServletResponse response = new MockHttpServletResponse();
	// check original theme
	String themeName = themeResolver.resolveThemeName(request);
	assertEquals(themeName, defaultName);
	// set new theme name
	try {
		themeResolver.setThemeName(request, response, TEST_THEME_NAME);
		if (!shouldSet)
			fail("should not be able to set Theme name");
		// check new theme namelocale
		themeName = themeResolver.resolveThemeName(request);
		assertEquals(TEST_THEME_NAME, themeName);
		themeResolver.setThemeName(request, response, null);
		themeName = themeResolver.resolveThemeName(request);
		assertEquals(themeName, defaultName);
	}
	catch (UnsupportedOperationException ex) {
		if (shouldSet)
			fail("should be able to set Theme name");
	}
}
 
Example #3
Source File: AbstractTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: AbstractTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
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);
}
 
Example #5
Source File: ThemeResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void internalTest(ThemeResolver themeResolver, boolean shouldSet, String defaultName) {
	// create mocks
	MockServletContext context = new MockServletContext();
	MockHttpServletRequest request = new MockHttpServletRequest(context);
	MockHttpServletResponse response = new MockHttpServletResponse();
	// check original theme
	String themeName = themeResolver.resolveThemeName(request);
	assertEquals(themeName, defaultName);
	// set new theme name
	try {
		themeResolver.setThemeName(request, response, TEST_THEME_NAME);
		if (!shouldSet)
			fail("should not be able to set Theme name");
		// check new theme namelocale
		themeName = themeResolver.resolveThemeName(request);
		assertEquals(TEST_THEME_NAME, themeName);
		themeResolver.setThemeName(request, response, null);
		themeName = themeResolver.resolveThemeName(request);
		assertEquals(themeName, defaultName);
	}
	catch (UnsupportedOperationException ex) {
		if (shouldSet)
			fail("should be able to set Theme name");
	}
}
 
Example #6
Source File: AbstractTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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);
}
 
Example #7
Source File: RequestContextUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the current theme from the given request, using the ThemeResolver
 * and ThemeSource bound to the request by the DispatcherServlet.
 * @param request current HTTP request
 * @return the current theme, or {@code null} if not found
 * @see #getThemeResolver
 */
public static Theme getTheme(HttpServletRequest request) {
	ThemeResolver themeResolver = getThemeResolver(request);
	ThemeSource themeSource = getThemeSource(request);
	if (themeResolver != null && themeSource != null) {
		String themeName = themeResolver.resolveThemeName(request);
		return themeSource.getTheme(themeName);
	}
	else {
		return null;
	}
}
 
Example #8
Source File: RequestContextUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Retrieves the current theme from the given request, using the ThemeResolver
 * and ThemeSource bound to the request by the DispatcherServlet.
 * @param request current HTTP request
 * @return the current theme, or {@code null} if not found
 * @see #getThemeResolver
 */
@Nullable
public static Theme getTheme(HttpServletRequest request) {
	ThemeResolver themeResolver = getThemeResolver(request);
	ThemeSource themeSource = getThemeSource(request);
	if (themeResolver != null && themeSource != null) {
		String themeName = themeResolver.resolveThemeName(request);
		return themeSource.getTheme(themeName);
	}
	else {
		return null;
	}
}
 
Example #9
Source File: RequestContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Change the current theme to the specified one,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param theme the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(@Nullable Theme theme) {
	ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
	if (themeResolver == null) {
		throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
	}
	themeResolver.setThemeName(this.request, this.response, (theme != null ? theme.getName() : null));
	this.theme = theme;
}
 
Example #10
Source File: ThemeChangeInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws ServletException {

	String newTheme = request.getParameter(this.paramName);
	if (newTheme != null) {
		ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
		if (themeResolver == null) {
			throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
		}
		themeResolver.setThemeName(request, response, newTheme);
	}
	// Proceed in any case.
	return true;
}
 
Example #11
Source File: RequestContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Change the current theme to the specified theme by name,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param themeName the name of the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(String themeName) {
	ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
	if (themeResolver == null) {
		throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
	}
	themeResolver.setThemeName(this.request, this.response, themeName);
	// Ask for re-resolution on next getTheme call.
	this.theme = null;
}
 
Example #12
Source File: RequestContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Change the current theme to the specified one,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param theme the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(Theme theme) {
	ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
	if (themeResolver == null) {
		throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
	}
	themeResolver.setThemeName(this.request, this.response, (theme != null ? theme.getName() : null));
	this.theme = theme;
}
 
Example #13
Source File: RequestContextUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the current theme from the given request, using the ThemeResolver
 * and ThemeSource bound to the request by the DispatcherServlet.
 * @param request current HTTP request
 * @return the current theme, or {@code null} if not found
 * @see #getThemeResolver
 */
public static Theme getTheme(HttpServletRequest request) {
	ThemeResolver themeResolver = getThemeResolver(request);
	ThemeSource themeSource = getThemeSource(request);
	if (themeResolver != null && themeSource != null) {
		String themeName = themeResolver.resolveThemeName(request);
		return themeSource.getTheme(themeName);
	}
	else {
		return null;
	}
}
 
Example #14
Source File: ThemeChangeInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws ServletException {

	String newTheme = request.getParameter(this.paramName);
	if (newTheme != null) {
		ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
		if (themeResolver == null) {
			throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
		}
		themeResolver.setThemeName(request, response, newTheme);
	}
	// Proceed in any case.
	return true;
}
 
Example #15
Source File: RequestContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Change the current theme to the specified theme by name,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param themeName the name of the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(String themeName) {
	ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
	if (themeResolver == null) {
		throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
	}
	themeResolver.setThemeName(this.request, this.response, themeName);
	// Ask for re-resolution on next getTheme call.
	this.theme = null;
}
 
Example #16
Source File: RequestContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Change the current theme to the specified one,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param theme the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(Theme theme) {
	ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
	if (themeResolver == null) {
		throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
	}
	themeResolver.setThemeName(this.request, this.response, (theme != null ? theme.getName() : null));
	this.theme = theme;
}
 
Example #17
Source File: RequestContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Change the current theme to the specified theme by name,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param themeName the name of the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(String themeName) {
	ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
	if (themeResolver == null) {
		throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
	}
	themeResolver.setThemeName(this.request, this.response, themeName);
	// Ask for re-resolution on next getTheme call.
	this.theme = null;
}
 
Example #18
Source File: ThemeChangeInterceptor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws ServletException {

	String newTheme = request.getParameter(this.paramName);
	if (newTheme != null) {
		ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
		if (themeResolver == null) {
			throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
		}
		themeResolver.setThemeName(request, response, newTheme);
	}
	// Proceed in any case.
	return true;
}
 
Example #19
Source File: RequestContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Change the current theme to the specified theme by name,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param themeName the name of the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(String themeName) {
	ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
	if (themeResolver == null) {
		throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
	}
	themeResolver.setThemeName(this.request, this.response, themeName);
	// Ask for re-resolution on next getTheme call.
	this.theme = null;
}
 
Example #20
Source File: RequestContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Change the current theme to the specified one,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param theme the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(@Nullable Theme theme) {
	ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
	if (themeResolver == null) {
		throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
	}
	themeResolver.setThemeName(this.request, this.response, (theme != null ? theme.getName() : null));
	this.theme = theme;
}
 
Example #21
Source File: RequestContextUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Retrieves the current theme from the given request, using the ThemeResolver
 * and ThemeSource bound to the request by the DispatcherServlet.
 * @param request current HTTP request
 * @return the current theme, or {@code null} if not found
 * @see #getThemeResolver
 */
@Nullable
public static Theme getTheme(HttpServletRequest request) {
	ThemeResolver themeResolver = getThemeResolver(request);
	ThemeSource themeSource = getThemeSource(request);
	if (themeResolver != null && themeSource != null) {
		String themeName = themeResolver.resolveThemeName(request);
		return themeSource.getTheme(themeName);
	}
	else {
		return null;
	}
}
 
Example #22
Source File: ThemeChangeInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws ServletException {

	String newTheme = request.getParameter(this.paramName);
	if (newTheme != null) {
		ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
		if (themeResolver == null) {
			throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
		}
		themeResolver.setThemeName(request, response, newTheme);
	}
	// Proceed in any case.
	return true;
}
 
Example #23
Source File: ServletWebServerInitializer.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(GenericApplicationContext context) {
	context.registerBean("webServerFactoryCustomizerBeanPostProcessor", WebServerFactoryCustomizerBeanPostProcessor.class, WebServerFactoryCustomizerBeanPostProcessor::new);
	context.registerBean(WebMvcProperties.class, () -> this.webMvcProperties);
	context.registerBean(ServletWebServerFactoryAutoConfiguration.BeanPostProcessorsRegistrar.class, ServletWebServerFactoryAutoConfiguration.BeanPostProcessorsRegistrar::new);
	context.registerBean(TomcatServletWebServerFactory.class, () -> new ServletWebServerFactoryConfiguration.EmbeddedTomcat().tomcatServletWebServerFactory(
			context.getBeanProvider(TomcatConnectorCustomizer.class),
			context.getBeanProvider(TomcatContextCustomizer.class),
			context.getBeanProvider(ResolvableType.forClass(TomcatProtocolHandlerCustomizer.class))));
	ServletWebServerFactoryAutoConfiguration servletWebServerFactoryConfiguration = new ServletWebServerFactoryAutoConfiguration();
	context.registerBean(ServletWebServerFactoryCustomizer.class, () -> servletWebServerFactoryConfiguration.servletWebServerFactoryCustomizer(serverProperties));
	context.registerBean(TomcatServletWebServerFactoryCustomizer.class, () -> servletWebServerFactoryConfiguration.tomcatServletWebServerFactoryCustomizer(serverProperties));
	context.registerBean(FilterRegistrationBean.class, servletWebServerFactoryConfiguration::forwardedHeaderFilter);

	DispatcherServletAutoConfiguration.DispatcherServletConfiguration dispatcherServletConfiguration = new DispatcherServletAutoConfiguration.DispatcherServletConfiguration();
	context.registerBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, DispatcherServlet.class, () -> dispatcherServletConfiguration.dispatcherServlet(webMvcProperties));
	context.registerBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME, DispatcherServletRegistrationBean.class, () -> new DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration().dispatcherServletRegistration(context.getBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, DispatcherServlet.class), webMvcProperties, context.getBeanProvider(MultipartConfigElement.class)));

	WebMvcAutoConfiguration webMvcConfiguration = new WebMvcAutoConfiguration();
	context.registerBean(OrderedHiddenHttpMethodFilter.class, webMvcConfiguration::hiddenHttpMethodFilter);

	Supplier<WebMvcAutoConfigurationAdapter> webMvcConfigurationAdapter = new Supplier<WebMvcAutoConfigurationAdapter>() {

		private WebMvcAutoConfigurationAdapter configuration;

		@Override
		public WebMvcAutoConfigurationAdapter get() {
			if (configuration == null) {
				configuration = new WebMvcAutoConfigurationAdapter(resourceProperties, webMvcProperties, context, context.getBeanProvider(HttpMessageConverters.class), context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), context.getBeanProvider(DispatcherServletPath.class));
				return configuration;
			}
			return configuration;
		}
	};
	context.registerBean(InternalResourceViewResolver.class, () -> webMvcConfigurationAdapter.get().defaultViewResolver());
	context.registerBean(BeanNameViewResolver.class, () -> webMvcConfigurationAdapter.get().beanNameViewResolver());
	context.registerBean("viewResolver", ContentNegotiatingViewResolver.class, () -> webMvcConfigurationAdapter.get().viewResolver(context));
	context.registerBean(RequestContextFilter.class, WebMvcAutoConfigurationAdapter::requestContextFilter);
	// TODO Favicon management

	Supplier<EnableWebMvcConfiguration> enableWebMvcConfiguration = new Supplier<EnableWebMvcConfiguration>() {

		private EnableWebMvcConfiguration configuration;

		@Override
		public EnableWebMvcConfiguration get() {
			if (configuration == null) {
				configuration = new EnableWebMvcConfigurationWrapper(context.getBeanProvider(WebMvcProperties.class), context.getBeanProvider(WebMvcRegistrations.class), context);
				configuration.setApplicationContext(context);
				configuration.setServletContext(((WebApplicationContext) context).getServletContext());
				configuration.setResourceLoader(context);
			}
			return configuration;
		}
	};

	context.registerBean(FormattingConversionService.class, () -> enableWebMvcConfiguration.get().mvcConversionService());
	context.registerBean(Validator.class, () -> enableWebMvcConfiguration.get().mvcValidator());
	context.registerBean(ContentNegotiationManager.class, () -> enableWebMvcConfiguration.get().mvcContentNegotiationManager());
	context.registerBean(ResourceChainResourceHandlerRegistrationCustomizer.class, () -> new ResourceChainCustomizerConfiguration().resourceHandlerRegistrationCustomizer());
	context.registerBean(PathMatcher.class, () -> enableWebMvcConfiguration.get().mvcPathMatcher());
	context.registerBean(UrlPathHelper.class, () -> enableWebMvcConfiguration.get().mvcUrlPathHelper());
	context.registerBean(HandlerMapping.class, () ->  enableWebMvcConfiguration.get().viewControllerHandlerMapping(context.getBean(FormattingConversionService.class), context.getBean(ResourceUrlProvider.class)));
	context.registerBean(RouterFunctionMapping.class, () ->  {

		return enableWebMvcConfiguration.get().routerFunctionMapping(context.getBean(FormattingConversionService.class), context.getBean(ResourceUrlProvider.class));
	});
	context.registerBean(HandlerMapping.class, () -> enableWebMvcConfiguration.get().resourceHandlerMapping(context.getBean(ContentNegotiationManager.class), context.getBean(FormattingConversionService.class), context.getBean(ResourceUrlProvider.class)));
	context.registerBean(ResourceUrlProvider.class, () -> enableWebMvcConfiguration.get().mvcResourceUrlProvider());
	context.registerBean(HandlerMapping.class, () -> enableWebMvcConfiguration.get().defaultServletHandlerMapping());
	context.registerBean(HandlerFunctionAdapter.class, () -> enableWebMvcConfiguration.get().handlerFunctionAdapter());
	context.registerBean(HttpRequestHandlerAdapter.class, () -> enableWebMvcConfiguration.get().httpRequestHandlerAdapter());
	context.registerBean(SimpleControllerHandlerAdapter.class, () -> enableWebMvcConfiguration.get().simpleControllerHandlerAdapter());
	context.registerBean(HandlerExceptionResolver.class, () -> enableWebMvcConfiguration.get().handlerExceptionResolver(context.getBean(ContentNegotiationManager.class)));
	context.registerBean(ViewResolver.class, () -> enableWebMvcConfiguration.get().mvcViewResolver(context.getBean(ContentNegotiationManager.class)));
	context.registerBean(HandlerMappingIntrospector.class, () -> enableWebMvcConfiguration.get().mvcHandlerMappingIntrospector(), bd -> bd.setLazyInit(true));
	context.registerBean(WelcomePageHandlerMapping.class, () -> enableWebMvcConfiguration.get().welcomePageHandlerMapping(context, context.getBean(FormattingConversionService.class), context.getBean(ResourceUrlProvider.class)));
	context.registerBean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class, () -> enableWebMvcConfiguration.get().localeResolver());
	context.registerBean(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, ThemeResolver.class, () -> enableWebMvcConfiguration.get().themeResolver());
	context.registerBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, FlashMapManager.class, () -> enableWebMvcConfiguration.get().flashMapManager());
	context.registerBean(DispatcherServlet.REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, RequestToViewNameTranslator.class, () -> enableWebMvcConfiguration.get().viewNameTranslator());
}
 
Example #24
Source File: RequestContextUtils.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the ThemeResolver that has been bound to the request by the
 * DispatcherServlet.
 * @param request current HTTP request
 * @return the current ThemeResolver, or {@code null} if not found
 */
public static ThemeResolver getThemeResolver(HttpServletRequest request) {
	return (ThemeResolver) request.getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE);
}
 
Example #25
Source File: RequestContextUtils.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Return the ThemeResolver that has been bound to the request by the
 * DispatcherServlet.
 * @param request current HTTP request
 * @return the current ThemeResolver, or {@code null} if not found
 */
@Nullable
public static ThemeResolver getThemeResolver(HttpServletRequest request) {
	return (ThemeResolver) request.getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE);
}
 
Example #26
Source File: RequestContextUtils.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Return the ThemeResolver that has been bound to the request by the
 * DispatcherServlet.
 * @param request current HTTP request
 * @return the current ThemeResolver, or {@code null} if not found
 */
public static ThemeResolver getThemeResolver(HttpServletRequest request) {
	return (ThemeResolver) request.getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE);
}
 
Example #27
Source File: RequestContextUtils.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Return the ThemeResolver that has been bound to the request by the
 * DispatcherServlet.
 * @param request current HTTP request
 * @return the current ThemeResolver, or {@code null} if not found
 */
@Nullable
public static ThemeResolver getThemeResolver(HttpServletRequest request) {
	return (ThemeResolver) request.getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE);
}