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

The following examples show how to use org.springframework.web.servlet.ThemeResolver#setThemeName() . 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: 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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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;
}