📄 messagetext.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: MessageText.java
package org.gudy.azureus2.core3.internat;
import java.io.*;
import java.net.*;
import java.security.AccessController;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.logging.LogAlert;
import org.gudy.azureus2.core3.logging.Logger;
import org.gudy.azureus2.core3.util.*;
import sun.security.action.GetPropertyAction;
// Referenced classes of package org.gudy.azureus2.core3.internat:
// IntegratedResourceBundle
public class MessageText
{
public static interface MessageTextListener
{
public abstract void localeChanged(Locale locale, Locale locale1);
}
public static final Locale LOCALE_ENGLISH = new Locale("en", "");
public static final Locale LOCALE_DEFAULT;
private static Locale LOCALE_CURRENT;
private static final String BUNDLE_NAME = "org.gudy.azureus2.internat.MessagesBundle";
private static Map pluginLocalizationPaths;
private static Collection pluginResourceBundles = new ArrayList();
private static IntegratedResourceBundle RESOURCE_BUNDLE;
private static Set platform_specific_keys = new HashSet();
private static final Pattern PAT_PARAM_ALPHA = Pattern.compile("\\{([^0-9].+?)\\}");
private static int bundle_fail_count = 0;
private static List listeners = new ArrayList();
private static IntegratedResourceBundle DEFAULT_BUNDLE;
public MessageText()
{
}
public static void loadBundle()
{
loadBundle(false);
}
public static void loadBundle(boolean forceReload)
{
Locale old_locale = getCurrentLocale();
String savedLocaleString = COConfigurationManager.getStringParameter("locale");
String savedLocaleStrings[] = savedLocaleString.split("_", 3);
Locale savedLocale;
if (savedLocaleStrings.length > 0 && savedLocaleStrings[0].length() == 2)
{
if (savedLocaleStrings.length == 3)
savedLocale = new Locale(savedLocaleStrings[0], savedLocaleStrings[1], savedLocaleStrings[2]);
else
if (savedLocaleStrings.length == 2 && savedLocaleStrings[1].length() == 2)
savedLocale = new Locale(savedLocaleStrings[0], savedLocaleStrings[1]);
else
savedLocale = new Locale(savedLocaleStrings[0]);
} else
if (savedLocaleStrings.length == 3 && savedLocaleStrings[0].length() == 0 && savedLocaleStrings[2].length() > 0)
savedLocale = new Locale(savedLocaleStrings[0], savedLocaleStrings[1], savedLocaleStrings[2]);
else
savedLocale = Locale.getDefault();
changeLocale(savedLocale, forceReload);
COConfigurationManager.setParameter("locale.set.complete.count", COConfigurationManager.getIntParameter("locale.set.complete.count") + 1);
Locale new_locale = getCurrentLocale();
if (!old_locale.equals(new_locale) || forceReload)
{
for (int i = 0; i < listeners.size(); i++)
try
{
((MessageTextListener)listeners.get(i)).localeChanged(old_locale, new_locale);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
}
public static void addListener(MessageTextListener listener)
{
listeners.add(listener);
}
public static void addAndFireListener(MessageTextListener listener)
{
listeners.add(listener);
listener.localeChanged(getCurrentLocale(), getCurrentLocale());
}
public static void removeListener(MessageTextListener listener)
{
listeners.remove(listener);
}
static ResourceBundle getResourceBundle(String name, Locale loc, ClassLoader cl)
{
return ResourceBundle.getBundle(name, loc, cl);
Throwable e;
e;
bundle_fail_count++;
if (bundle_fail_count == 1)
{
e.printStackTrace();
Logger.log(new LogAlert(true, 3, (new StringBuilder()).append("Failed to load resource bundle. One possible cause is that you have installed ").append(Constants.APP_NAME).append(" into a directory ").append("with a '!' in it. If so, please remove the '!'.").toString()));
}
return new ResourceBundle() {
public Locale getLocale()
{
return MessageText.LOCALE_DEFAULT;
}
protected Object handleGetObject(String key)
{
return null;
}
public Enumeration getKeys()
{
return (new Vector()).elements();
}
};
}
private static void setResourceBundle(IntegratedResourceBundle bundle)
{
RESOURCE_BUNDLE = bundle;
Iterator keys = RESOURCE_BUNDLE.getKeysLight();
String platform_suffix = getPlatformSuffix();
Set platformKeys = new HashSet();
do
{
if (!keys.hasNext())
break;
String key = (String)keys.next();
if (key.endsWith(platform_suffix))
platformKeys.add(key);
} while (true);
platform_specific_keys = platformKeys;
}
public static boolean keyExists(String key)
{
getResourceBundleString(key);
return true;
MissingResourceException e;
e;
return false;
}
public static boolean keyExistsForDefaultLocale(String key)
{
DEFAULT_BUNDLE.getString(key);
return true;
MissingResourceException e;
e;
return false;
}
public static String getString(String key, String sDefault)
{
String target_key;
if (key == null)
return "";
target_key = (new StringBuilder()).append(key).append(getPlatformSuffix()).toString();
if (!platform_specific_keys.contains(target_key))
target_key = key;
return getResourceBundleString(target_key);
MissingResourceException e;
e;
return getPlatformNeutralString(key, sDefault);
}
public static String getString(String key)
{
String target_key;
if (key == null)
return "";
target_key = (new StringBuilder()).append(key).append(getPlatformSuffix()).toString();
if (!platform_specific_keys.contains(target_key))
target_key = key;
return getResourceBundleString(target_key);
MissingResourceException e;
e;
return getPlatformNeutralString(key);
}
public static String getPlatformNeutralString(String key)
{
return getResourceBundleString(key);
MissingResourceException e;
e;
if (key.startsWith("!") && key.endsWith("!"))
return key.substring(1, key.length() - 1);
else
return (new StringBuilder()).append('!').append(key).append('!').toString();
}
public static String getPlatformNeutralString(String key, String sDefault)
{
return getResourceBundleString(key);
MissingResourceException e;
e;
return sDefault;
}
private static String getResourceBundleString(String key)
{
if (key == null)
return "";
String value = RESOURCE_BUNDLE.getString(key);
if (value != null && value.indexOf('}') > 0)
{
Matcher matcher = PAT_PARAM_ALPHA.matcher(value);
do
{
if (!matcher.find())
break;
key = matcher.group(1);
try
{
String text = getResourceBundleString(key);
if (text != null)
value = value.replaceAll((new StringBuilder()).append("\\Q{").append(key).append("}\\E").toString(), text);
}
catch (MissingResourceException e) { }
} while (true);
}
return value;
}
private static String getPlatformSuffix()
{
if (Constants.isOSX)
return "._mac";
if (Constants.isLinux)
return "._linux";
if (Constants.isUnix)
return "._unix";
if (Constants.isFreeBSD)
return "._freebsd";
if (Constants.isSolaris)
return "._solaris";
if (Constants.isWindows)
return "._windows";
else
return "._unknown";
}
public static String getStringForSentence(String sentence)
{
StringTokenizer st = new StringTokenizer(sentence, " ");
StringBuffer result = new StringBuffer(sentence.length());
String separator = "";
while (st.hasMoreTokens())
{
result.append(separator);
separator = " ";
String word = st.nextToken();
int length = word.length();
int position = word.lastIndexOf(".");
if (position == -1 || position + 1 == length)
{
result.append(word);
} else
{
String translated = getString(word);
if (translated.equals((new StringBuilder()).append("!").append(word).append("!").toString()))
result.append(word);
else
result.append(translated);
}
}
return result.toString();
}
public static String getString(String key, String params[])
{
String res = getString(key);
if (params == null)
return res;
for (int i = 0; i < params.length; i++)
{
String from_str = (new StringBuilder()).append("%").append(i + 1).toString();
String to_str = params[i];
res = replaceStrings(res, from_str, to_str);
}
return res;
}
protected static String replaceStrings(String str, String f_s, String t_s)
{
int pos = 0;
String res = "";
do
{
if (pos >= str.length())
break;
int p1 = str.indexOf(f_s, pos);
if (p1 == -1)
{
res = (new StringBuilder()).append(res).append(str.substring(pos)).toString();
break;
}
res = (new StringBuilder()).append(res).append(str.substring(pos, p1)).append(t_s).toString();
pos = p1 + f_s.length();
} while (true);
return res;
}
public static String getDefaultLocaleString(String key)
{
return DEFAULT_BUNDLE.getString(key);
MissingResourceException e;
e;
if (key.startsWith("!") && key.endsWith("!"))
return key.substring(1, key.length() - 1);
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -