package com.jivesoftware.util;import com.jivesoftware.base.*;
import java.text.*;
import java.util.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import com.jivesoftware.base.JiveGlobals;// Referenced classes of package com.jivesoftware.util:
//            CookieUtilspublic class LocaleUtils
{    private LocaleUtils()
    {
    }    public static Locale localeCodeToLocale(String localeCode)
    {
        Locale locale = null;
        if(localeCode != null)
        {
            String language = null;
            String country = null;
            String variant = null;
            if(localeCode != null)
            {
                StringTokenizer tokenizer = new StringTokenizer(localeCode, "_");
                if(tokenizer.hasMoreTokens())
                {
                    language = tokenizer.nextToken();
                    if(tokenizer.hasMoreTokens())
                    {
                        country = tokenizer.nextToken();
                        if(tokenizer.hasMoreTokens())
                            variant = tokenizer.nextToken();
                    }
                }
            }
            locale = new Locale(language, country == null ? "" : country, variant == null ? "" : variant);
        }
        return locale;
    }    public static String[][] getTimeZoneList()
    {
        if(timeZoneList == null)
            synchronized(timeZoneLock)
            {
                if(timeZoneList == null)
                {
                    Date now = new Date();
                    String timeZoneIDs[] = TimeZone.getAvailableIDs();
                    Locale jiveLocale = JiveGlobals.getLocale();
                    timeZoneList = new String[timeZoneIDs.length][2];
                    for(int i = 0; i < timeZoneList.length; i++)
                    {
                        String zoneID = timeZoneIDs[i];
                        timeZoneList[i][0] = zoneID;
                        timeZoneList[i][1] = getTimeZoneName(zoneID, now, jiveLocale);
                    }                }
            }
        return timeZoneList;
    }    public static Locale getUserLocale(HttpServletRequest request, User user)
    {
        Locale locale = null;
        if(user != null)
        {
            if("true".equals(JiveGlobals.getJiveProperty("skin.default.usersChooseLocale")))
            {
                Locale userLocale = localeCodeToLocale(user.getProperty("jiveLocale"));
                if(userLocale != null)
                    locale = userLocale;
            }
        } else
        if("true".equals(JiveGlobals.getJiveProperty("skin.default.usersChooseLocale")))
        {
            Cookie cookie = CookieUtils.getCookie(request, "jiveLocale");
            if(cookie != null)
            {
                Locale userLocale = localeCodeToLocale(cookie.getValue());
                if(userLocale != null)
                    locale = userLocale;
            }
        }
        if(locale != null)
            return locale;
        else
            return JiveGlobals.getLocale();
    }    public static TimeZone getTimeZone(HttpServletRequest request, User user)
    {
        TimeZone timeZone = JiveGlobals.getTimeZone();
        String timeZoneID = null;
        if(user != null)
        {
            timeZoneID = user.getProperty("jiveTimeZoneID");
        } else
        {
            Cookie cookie = CookieUtils.getCookie(request, "jiveTimeZoneID");
            if(cookie != null)
                timeZoneID = cookie.getValue();
        }
        if(timeZoneID != null)
            timeZone = TimeZone.getTimeZone(timeZoneID);
        return timeZone;
    }    private static String getTimeZoneName(String zoneID, Date now, Locale locale)
    {
        TimeZone zone = TimeZone.getTimeZone(zoneID);
        StringBuffer buf = new StringBuffer();
        int offset = zone.getRawOffset();
        if(zone.inDaylightTime(now) && zone.useDaylightTime())
            offset += 0x36ee80;
        if(offset < 0)
            buf.append("GMT-");
        else
            buf.append("GMT+");
        offset = Math.abs(offset);
        int hours = offset / 0x36ee80;
        int minutes = (offset % 0x36ee80) / 60000;
        buf.append(hours).append(":");
        if(minutes < 10)
            buf.append("0").append(minutes);
        else
            buf.append(minutes);
        buf.append(" - ").append(zoneID.replace('_', ' ').replace('/', ' ')).append(" ");
        buf.append(zone.getDisplayName(true, 0, locale).replace('_', ' ').replace('/', ' '));
        return buf.toString();
    }//see next........

解决方案 »

  1.   

    //go on.......    public static ResourceBundle getResourceBundle(String baseName, Locale locale)
        {
            return ResourceBundle.getBundle(baseName, locale);
        }//偶添加的中文转换函数    public static String toChinese(String strvalue)
               {
                     try{
                         if(strvalue==null)
                            return null;
                         else
                         {
                            strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
                            return strvalue;
                     }
                     }catch(Exception e){
                           return null;
                     }
               }    public static String getLocalizedString(String key)
        {
            return getLocalizedString(key, JiveGlobals.getLocale(), null);
        }
        public static String getLocalizedString(String key, Locale locale)
        {
            return getLocalizedString(key, locale, null);
        }    public static String getLocalizedString(String key, List arguments)
        {
            return getLocalizedString(key, JiveGlobals.getLocale(), arguments);
        }    public static String getLocalizedString(String key, Locale locale, List arguments)
        {
            if(key == null)
                throw new NullPointerException("Key cannot be null");
            if(locale == null)
                locale = JiveGlobals.getLocale();
            String value = "";
            ResourceBundle bundle = ResourceBundle.getBundle("jive_i18n", locale);
            try
            {
                value = bundle.getString(key);        }
            catch(MissingResourceException mre)
            {
                Log.error("Missing resource for key: " + key + " in locale " + locale.toString());
                value = "";
            }
            if(arguments != null)
            {
                MessageFormat messageFormat = new MessageFormat("");
                messageFormat.setLocale(bundle.getLocale());
                messageFormat.applyPattern(value);
                try
                {
                    java.text.Format formats[] = messageFormat.getFormats();
                    for(int i = 0; i < formats.length; i++)
                    {
                        java.text.Format format = formats[i];
                        if(format != null)
                            if(format instanceof DateFormat)
                            {
                                if(arguments.size() > i)
                                {
                                    Object val = arguments.get(i);
                                    if(val instanceof String)
                                    {
                                        DateFormat dateFmt = (DateFormat)format;
                                        try
                                        {
                                            val = dateFmt.parse((String)val);
                                            arguments.set(i, val);
                                        }
                                        catch(ParseException e)
                                        {
                                            Log.error(e);
                                        }
                                    }
                                }
                            } else
                            if((format instanceof NumberFormat) && arguments.size() > i)
                            {
                                Object val = arguments.get(i);
                                if(val instanceof String)
                                {
                                    NumberFormat nbrFmt = (NumberFormat)format;
                                    try
                                    {
                                        val = nbrFmt.parse((String)val);
                                        arguments.set(i, val);
                                    }
                                    catch(ParseException e)
                                    {
                                        Log.error(e);
                                    }
                                }
                            }
                    }                value = messageFormat.format(((Object) (arguments.toArray())));
                }
                catch(IllegalArgumentException e)
                {
                    Log.error("Unable to format resource string for key: " + key + ", argument type not supported");
                    value = "";
                }
            }
            return toChinese(value);  //偶修改的地方
        }    public static String getLocalizedNumber(long number)
        {
            return NumberFormat.getInstance().format(number);
        }    public static String getLocalizedNumber(long number, Locale locale)
        {
            return NumberFormat.getInstance(locale).format(number);
        }    public static String getLocalizedNumber(double number)
        {
            return NumberFormat.getInstance().format(number);
        }    public static String getLocalizedNumber(double number, Locale locale)
        {
            return NumberFormat.getInstance(locale).format(number);
        }    private static String timeZoneList[][] = null;
        private static Object timeZoneLock = new Object();
        private static final String resourceBaseName = "jive_i18n";}    哈哈偶加了一个toChinese的函数,是在网上抄的,嘿嘿。
    然后在getLocalizedString函数返回值时转化了一下,就是这里return toChinese(value);就这样偶用JBUILDER8 从新编译了该CLASS,用JAR从新打包后,覆盖了原来的JAR包,运行TOMCAT后就出现了我可爱的中文。    总结:做任何事情遇到困难是最正常不过的,只有在重重困难下,我的生活才显得无比可爱与美好,而事物的两面性是我们分析问题解决问题的基础,当我们在动过脑子,冷静下来后,问题的解决方法总是可爱的跳到我们面前,原来我们的问题是因为我们的无知才出现的,兄弟姐妹们用平和的心态来看待这个世界,那点点滴滴都是那么的美好与可爱,嘿嘿还好偶已经不做IT了。
      

  2.   

    从好用、功能等方面来讲,还是jive 3.2.9等好,如果想学习源码,只好是jive2.6.4
      

  3.   

    pig !!
    should use naive2ascii.
      

  4.   

    楼主所说的好象是解决汉字显示的问题,并不是汉化啊,并且JIVE3。0以上并不需要这样做了,只需要设置数据库编码方式即可汉化是如naxin所说的要先去汉化资源文件,然后用naive2ascii转换一下啊。
      

  5.   

    能不能给我发一份啊??
    [email protected]