⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localefilter.java

📁 基于Jabber协议的即时消息服务器
💻 JAVA
字号:
/* * $RCSfile$ * $Revision: 4153 $ * $Date: 2006-06-28 20:29:09 -0700 (Wed, 28 Jun 2006) $ * * Copyright (C) 2004-2005 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. */package org.jivesoftware.util;import javax.servlet.*;import javax.servlet.http.HttpServletRequest;import javax.servlet.jsp.jstl.core.Config;import javax.servlet.jsp.jstl.fmt.LocalizationContext;import java.io.IOException;import java.util.ResourceBundle;/** * Sets the locale context-wide. */public class LocaleFilter implements Filter {    private ServletContext context;    public void init(FilterConfig config) throws ServletException {        this.context = config.getServletContext();    }    /**     * Ssets the locale context-wide based on a call to {@link JiveGlobals#getLocale()}.     */    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)            throws IOException, ServletException {        final String pathInfo = ((HttpServletRequest)request).getPathInfo();        if (pathInfo == null) {            // Note, putting the locale in the application at this point is a little overkill            // (ie, every user who hits this filter will do this). Eventually, it might make            // sense to just set the locale in the user's session and if that's done we might            // want to honor a preference to get the user's locale based on request headers.            // For now, this is just a convenient place to set the locale globally.            Config.set(context, Config.FMT_LOCALE, JiveGlobals.getLocale());        }        else {            try {                String[] parts = pathInfo.split("/");                String pluginName = parts[1];                ResourceBundle bundle = LocaleUtils.getPluginResourceBundle(pluginName);                LocalizationContext ctx = new LocalizationContext(bundle, JiveGlobals.getLocale());                Config.set(request, Config.FMT_LOCALIZATION_CONTEXT, ctx);            }            catch (Exception e) {                // Note, putting the locale in the application at this point is a little overkill                // (ie, every user who hits this filter will do this). Eventually, it might make                // sense to just set the locale in the user's session and if that's done we might                // want to honor a preference to get the user's locale based on request headers.                // For now, this is just a convenient place to set the locale globally.                Config.set(context, Config.FMT_LOCALE, JiveGlobals.getLocale());            }        }        // Move along:        chain.doFilter(request, response);    }    /**     * Does nothing     */    public void destroy() {    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -