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

org.springframework.biz.web.server.i18n.NestedLocaleContextResolver Maven / Gradle / Ivy

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

import java.util.List;

import org.springframework.context.i18n.LocaleContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.i18n.LocaleContextResolver;

/**
 * 嵌套Locale解析器;解决同时设置Locale到Session和Cookie的问题
 */
public class NestedLocaleContextResolver implements LocaleContextResolver {
	
	protected List resolvers;

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

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

	@Override
	public LocaleContext resolveLocaleContext(ServerWebExchange exchange) {
		if(isNested()){
			for (LocaleContextResolver localeResolver : getResolvers()) {
				//解析locale
				LocaleContext localeContext = localeResolver.resolveLocaleContext(exchange);
				if(localeContext == null){
					continue;
				}
				LocaleContextHolder.setLocaleContext(localeContext);
				return localeContext;
			}
		}
		return null;
	}

	@Override
	public void setLocaleContext(ServerWebExchange exchange, LocaleContext localeContext) {
		if(isNested()){
			for (LocaleContextResolver localeResolver : getResolvers()) {
				localeResolver.setLocaleContext(exchange, localeContext);
			}
		}
		
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy