Java Code Examples for org.springframework.web.servlet.ThemeResolver#resolveThemeName()

The following examples show how to use org.springframework.web.servlet.ThemeResolver#resolveThemeName() . 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 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 2
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 3
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 4
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 5
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 6
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 7
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;
	}
}