rb.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 733 行 · 第 1/2 页
JAVA
733 行
return null;
} else if (p1 == null) {
return p2;
} else if (p2 == null) {
return p1;
}
// Now merge. p1 takes precedence
Enumeration enumeration = p2.keys();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
if (p1.getProperty(key) == null) {
p1.put(key, p2.getProperty(key));
}
}
return p1;
}
/**
* Get the underlying properties
*/
public Properties getProperties() {
return resourceProperties;
}
// STATIC ACCESSORS
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param key The resource key
* @return The formatted message
*/
public static String getString(Object caller, String key)
throws MissingResourceException {
return getMessage(caller, BASE_NAME, null, key, null);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @return The formatted message
*/
public static String getString(Object caller, String key, Object arg0)
throws MissingResourceException {
Object[] o = new Object[1];
o[0] = arg0;
return getMessage(caller, BASE_NAME, null, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @param arg1 The argument to place in variable {1}
* @return The formatted message
*/
public static String getString(Object caller, String key, Object arg0, Object arg1)
throws MissingResourceException {
Object[] o = new Object[2];
o[0] = arg0;
o[1] = arg1;
return getMessage(caller, BASE_NAME, null, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @param arg1 The argument to place in variable {1}
* @param arg2 The argument to place in variable {2}
* @return The formatted message
*/
public static String getString(Object caller, String key, Object arg0, Object arg1, Object arg2)
throws MissingResourceException {
Object[] o = new Object[3];
o[0] = arg0;
o[1] = arg1;
o[2] = arg2;
return getMessage(caller, BASE_NAME, null, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @param arg1 The argument to place in variable {1}
* @param arg2 The argument to place in variable {2}
* @param arg3 The argument to place in variable {3}
* @return The formatted message
*/
public static String getString(Object caller, String key, Object arg0, Object arg1, Object arg2,
Object arg3)
throws MissingResourceException {
Object[] o = new Object[4];
o[0] = arg0;
o[1] = arg1;
o[2] = arg2;
o[3] = arg3;
return getMessage(caller, BASE_NAME, null, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @param arg1 The argument to place in variable {1}
* @param arg2 The argument to place in variable {2}
* @param arg3 The argument to place in variable {3}
* @param arg4 The argument to place in variable {4}
* @return Returns the formatted message.
*/
public static String getString(Object caller, String key, Object arg0, Object arg1, Object arg2,
Object arg3, Object arg4)
throws MissingResourceException {
Object[] o = new Object[5];
o[0] = arg0;
o[1] = arg1;
o[2] = arg2;
o[3] = arg3;
o[4] = arg4;
return getMessage(caller, BASE_NAME, null, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param key The resource key
* @param args An array of objects to place in corresponding variables
* @return Returns the formatted message.
*/
public static String getString(Object caller, String key, Object[] args)
throws MissingResourceException {
return getMessage(caller, BASE_NAME, null, key, args);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param locale The locale
* @param key The resource key
* @return The formatted message
*/
public static String getString(Object caller, Locale locale, String key)
throws MissingResourceException {
return getMessage(caller, BASE_NAME, locale, key, null);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param locale The locale
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @return The formatted message
*/
public static String getString(Object caller, Locale locale, String key, Object arg0)
throws MissingResourceException {
Object[] o = new Object[1];
o[0] = arg0;
return getMessage(caller, BASE_NAME, locale, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param locale The locale
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @param arg1 The argument to place in variable {1}
* @return The formatted message
*/
public static String getString(Object caller, Locale locale, String key, Object arg0,
Object arg1)
throws MissingResourceException {
Object[] o = new Object[2];
o[0] = arg0;
o[1] = arg1;
return getMessage(caller, BASE_NAME, locale, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param locale The locale
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @param arg1 The argument to place in variable {1}
* @param arg2 The argument to place in variable {2}
* @return The formatted message
*/
public static String getString(Object caller, Locale locale, String key, Object arg0,
Object arg1, Object arg2)
throws MissingResourceException {
Object[] o = new Object[3];
o[0] = arg0;
o[1] = arg1;
o[2] = arg2;
return getMessage(caller, BASE_NAME, locale, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param locale The locale
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @param arg1 The argument to place in variable {1}
* @param arg2 The argument to place in variable {2}
* @param arg3 The argument to place in variable {3}
* @return The formatted message
*/
public static String getString(Object caller, Locale locale, String key, Object arg0,
Object arg1, Object arg2, Object arg3)
throws MissingResourceException {
Object[] o = new Object[4];
o[0] = arg0;
o[1] = arg1;
o[2] = arg2;
o[3] = arg3;
return getMessage(caller, BASE_NAME, locale, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param locale The locale
* @param key The resource key
* @param arg0 The argument to place in variable {0}
* @param arg1 The argument to place in variable {1}
* @param arg2 The argument to place in variable {2}
* @param arg3 The argument to place in variable {3}
* @return Returns the formatted message.
*/
public static String getString(Object caller, Locale locale, String key, Object arg0,
Object arg1, Object arg2, Object arg3, Object arg4)
throws MissingResourceException {
Object[] o = new Object[5];
o[0] = arg0;
o[1] = arg1;
o[2] = arg2;
o[3] = arg3;
o[4] = arg4;
return getMessage(caller, BASE_NAME, locale, key, o);
}
/**
* Get a message from resource.properties from the package of the given object.
*
* @param caller The calling object, used to get the package name and class loader
* @param locale The locale
* @param key The resource key
* @param args An array of objects to place in corresponding variables
* @return Returns the formatted message.
*/
public static String getString(Object caller, Locale locale, String key, Object[] args)
throws MissingResourceException {
return getMessage(caller, BASE_NAME, locale, key, args);
}
// Workhorse that does the resource loading and key lookup
public static String getMessage(Object caller, String basename, Locale locale, String key,
Object[] args)
throws MissingResourceException {
String msg = null;
MissingResourceException firstEx = null;
String fullName = null;
Class curClass = null;
boolean didNull = false;
if (caller != null) {
if (caller instanceof Class) {
curClass = (Class) caller;
} else {
curClass = caller.getClass();
}
}
while (msg == null) {
// Get the full name of the resource
if (curClass != null) {
// Create the full basename
String pkgName = curClass.getName();
int pos = pkgName.lastIndexOf(".");
if (pos > 0) {
fullName = pkgName.substring(0, pos + 1).replace('.', '/') + basename;
} else {
fullName = basename;
}
} else {
fullName = basename;
}
try {
RB rb = new RB(caller, fullName, locale);
msg = rb.getString(key, args);
} catch (MissingResourceException ex) {
if (curClass == null) {
throw ex;
}
// Save the first exception
if (firstEx == null) {
firstEx = ex;
}
// Get the superclass
curClass = curClass.getSuperclass();
if (curClass == null) {
if (didNull) {
throw firstEx;
}
didNull = true;
caller = null;
} else {
String cname = curClass.getName();
if (cname.startsWith("java.") ||
cname.startsWith("javax.")) {
if (didNull) {
throw firstEx;
}
didNull = true;
caller = null;
curClass = null;
}
}
}
}
return msg;
}
/**
* Clears the internal cache.
*/
public static void clearCache() {
propertyCache.clear();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?