All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.biz.web.servlet.theme.NestedThemeResolver Maven / Gradle / Ivy

There is a newer version: 3.3.x.20241003.RELEASE
Show newest version
package org.springframework.biz.web.servlet.theme;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ThemeResolver;
import org.springframework.web.servlet.theme.AbstractThemeResolver;

/**
 * 嵌套Theme解析器;解决同时设置Theme到Session和Cookie的问题
 */
public class NestedThemeResolver extends AbstractThemeResolver implements ThemeResolver {

	protected List resolvers;

	@Override
	public String resolveThemeName(HttpServletRequest request) {
		if (isNested()) {
			String def = getDefaultThemeName();
			for (ThemeResolver localeResolver : getResolvers()) {
				// 解析theme
				String theme = localeResolver.resolveThemeName(request);
				if (theme == null || theme.equals(def)) {
					continue;
				}
				return theme;
			}
		}
		return getDefaultThemeName();
	}

	@Override
	public void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName) {
		if (isNested()) {
			for (ThemeResolver localeResolver : getResolvers()) {
				localeResolver.setThemeName(request, response, themeName);
			}
		}
	}

	protected boolean isNested() {
		if (getResolvers() != null) {
			return true;
		}
		return false;
	}

	public List getResolvers() {
		return resolvers;
	}

	public void setResolvers(List resolvers) {
		this.resolvers = resolvers;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy