Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
shuaje committed Dec 12, 2017
1 parent a33ea90 commit 61c2920
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
package top.ibase4j.core.interceptor;
package top.ibase4j.core.filter;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;

import cz.mallat.uasparser.OnlineUpdater;
import cz.mallat.uasparser.UASparser;
import top.ibase4j.core.Constants;
import top.ibase4j.core.util.WebUtil;

/**
* 国际化信息设置(基于SESSION)
*
* @author ShenHuaJie
* @version 2016年5月20日 下午3:16:45
*/
public class LocaleInterceptor extends BaseInterceptor {
static UASparser uasParser;

static {
try {
uasParser = new UASparser(OnlineUpdater.getVendoredInputStream());
} catch (IOException e) {
logger.error("", e);
}
public class LocaleFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
HttpSession session = request.getSession();
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)request;
HttpSession session = req.getSession();
// 设置客户端语言
Locale locale = (Locale)session.getAttribute("LOCALE");
if (locale == null) {
Expand All @@ -45,6 +44,12 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
}
}
LocaleContextHolder.setLocale(locale);
return super.preHandle(request, response, handler);

session.setAttribute(Constants.USER_IP, WebUtil.getHost(req));
chain.doFilter(request, response);
}

public void destroy() {

}
}

0 comments on commit 61c2920

Please sign in to comment.