Methods Summary |
---|
public boolean | getBoolean(java.lang.String key)Look up the named resource and try to interpret it as a boolean.
String s = bundle.getString(key);
s = s.toLowerCase();
if (s.equals("true")) return true;
else if (s.equals("false")) return false;
else if (s.equals("yes")) return true;
else if (s.equals("no")) return false;
else if (s.equals("on")) return true;
else if (s.equals("off")) return false;
else {
throw new MalformedResourceException("boolean", key);
}
|
public boolean | getBoolean(java.lang.String key, boolean defaultValue)As above, but return the default instead of throwing an exception
try { return getBoolean(key); }
catch(MissingResourceException e) {
if (e instanceof MalformedResourceException)
System.err.println("WARNING: " + e.getMessage());
return defaultValue;
}
|
public java.awt.Color | getColor(java.lang.String key)Look up the named resource, and convert to a Color
try {
return Color.decode(bundle.getString(key));
}
catch (NumberFormatException e) {
// It would be useful to try to parse color names here as well
// as numeric color specifications
throw new MalformedResourceException("Color", key);
}
|
public java.awt.Color | getColor(java.lang.String key, java.awt.Color defaultValue)As above, but with a default value
try { return getColor(key); }
catch(MissingResourceException e) {
if (e instanceof MalformedResourceException)
System.err.println("WARNING: " + e.getMessage());
return defaultValue;
}
|
public double | getDouble(java.lang.String key)Return a resource of type double
String s = bundle.getString(key);
try {
return Double.parseDouble(s);
} catch (NumberFormatException e) {
throw new MalformedResourceException("double", key);
}
|
public double | getDouble(java.lang.String key, double defaultValue)As above, but with a default value
try { return getDouble(key); }
catch(MissingResourceException e) {
if (e instanceof MalformedResourceException)
System.err.println("WARNING: " + e.getMessage());
return defaultValue;
}
|
public java.awt.Font | getFont(java.lang.String key)Look up the named resource and convert to a Font
// Font.decode() always returns a Font object, so we can't check
// whether the resource value was well-formed or not.
return Font.decode(bundle.getString(key));
|
public java.awt.Font | getFont(java.lang.String key, java.awt.Font defaultValue)As above, but with a default value
try { return getFont(key); }
catch (MissingResourceException e) { return defaultValue; }
|
public int | getInt(java.lang.String key)Like getBoolean(), but for integers
String s = bundle.getString(key);
try {
// Use decode() instead of parseInt() so we support octal
// and hexadecimal numbers
return Integer.decode(s).intValue();
} catch (NumberFormatException e) {
throw new MalformedResourceException("int", key);
}
|
public int | getInt(java.lang.String key, int defaultValue)As above, but with a default value
try { return getInt(key); }
catch(MissingResourceException e) {
if (e instanceof MalformedResourceException)
System.err.println("WARNING: " + e.getMessage());
return defaultValue;
}
|
public java.util.Enumeration | getKeys()This is one of the abstract methods of ResourceBundle return bundle.getKeys();
|
public java.lang.Object | getResource(java.lang.String key, java.lang.Class type)Look for a ResourceParser for the named type, and if one is found,
ask it to parse and return the named resource
// Get a parser for the specified type
ResourceParser parser = (ResourceParser)parsers.get(type);
if (parser == null)
throw new MissingResourceException(
"No ResourceParser registered for " +
type.getName() + " resources",
type.getName(), key);
try { // Ask the parser to parse the resource
return parser.parse(this, key, type);
}
catch(MissingResourceException e) {
throw e; // Rethrow MissingResourceException exceptions
}
catch(Exception e) {
// If any other type of exception occurs, convert it to
// a MalformedResourceException
String msg = "Malformed " + type.getName() + " resource: " +
key + ": " + e.getMessage();
throw new MalformedResourceException(msg, type.getName(), key);
}
|
public java.lang.Object | getResource(java.lang.String key, java.lang.Class type, java.lang.Object defaultValue)Like the 2-argument version of getResource, but return a default value
instead of throwing a MissingResourceException
try { return getResource(key, type); }
catch (MissingResourceException e) {
if (e instanceof MalformedResourceException)
System.err.println("WARNING: " + e.getMessage());
return defaultValue;
}
|
public static ResourceParser | getResourceParser(java.lang.Class type)Look up a ResourceParser for the specified resource type
return (ResourceParser) parsers.get(type);
|
public java.lang.Object | getRoot()This is a property accessor method for our root object return root;
|
public java.lang.String | getString(java.lang.String key, java.lang.String defaultValue)This method is like the inherited getString() method, except that
when the named resource is not found, it returns the specified default
instead of throwing an exception
try { return bundle.getString(key); }
catch(MissingResourceException e) { return defaultValue; }
|
public java.util.List | getStringList(java.lang.String key, java.util.List defaultValue)Like above, but return a default instead of throwing an exception
try { return getStringList(key); }
catch(MissingResourceException e) { return defaultValue; }
|
public java.util.List | getStringList(java.lang.String key)Look up the named resource and parse it as a list of strings separated
by spaces, tabs, or commas.
String s = getString(key);
StringTokenizer t = new StringTokenizer(s, ", \t", false);
ArrayList list = new ArrayList();
while(t.hasMoreTokens()) list.add(t.nextToken());
return list;
|
protected java.lang.Object | handleGetObject(java.lang.String key)This is the other abstract method of ResourceBundle
return bundle.getObject(key); // simply defer to the wrapped bundle
|
public static void | registerResourceParser(ResourceParser parser)An extension mechanism: register a parser for new resource types
// Ask the ResourceParser what types it can parse
Class[] supportedTypes = parser.getResourceTypes();
// Register it in the hashtable for each of those types
for(int i = 0; i < supportedTypes.length; i++)
parsers.put(supportedTypes[i], parser);
|