PropUtilpublic class PropUtil extends Object Utilities to make it easier to get property values.
Properties can be strings or type-specific value objects. |
Constructors Summary |
---|
private PropUtil()
|
Methods Summary |
---|
private static boolean | getBoolean(java.lang.Object value, boolean def)Interpret the value object as a boolean,
returning def if unable.
if (value == null)
return def;
if (value instanceof String) {
/*
* If the default is true, only "false" turns it off.
* If the default is false, only "true" turns it on.
*/
if (def)
return !((String)value).equalsIgnoreCase("false");
else
return ((String)value).equalsIgnoreCase("true");
}
if (value instanceof Boolean)
return ((Boolean)value).booleanValue();
return def;
| public static boolean | getBooleanProperty(java.util.Properties props, java.lang.String name, boolean def)Get a boolean valued property.
return getBoolean(props.get(name), def);
| public static boolean | getBooleanSessionProperty(javax.mail.Session session, java.lang.String name, boolean def)Get a boolean valued property.
return getBoolean(session.getProperties().get(name), def);
| public static boolean | getBooleanSystemProperty(java.lang.String name, boolean def)Get a boolean valued System property.
try {
return getBoolean(System.getProperties().get(name), def);
} catch (SecurityException sex) {
// fall through...
}
/*
* If we can't get the entire System Properties object because
* of a SecurityException, just ask for the specific property.
*/
try {
String value = System.getProperty(name);
if (value == null)
return def;
if (def)
return !value.equalsIgnoreCase("false");
else
return value.equalsIgnoreCase("true");
} catch (SecurityException sex) {
return def;
}
| private static int | getInt(java.lang.Object value, int def)Interpret the value object as an integer,
returning def if unable.
if (value == null)
return def;
if (value instanceof String) {
try {
return Integer.parseInt((String)value);
} catch (NumberFormatException nfex) { }
}
if (value instanceof Integer)
return ((Integer)value).intValue();
return def;
| public static int | getIntProperty(java.util.Properties props, java.lang.String name, int def)Get an integer valued property.
return getInt(props.get(name), def);
| public static int | getIntSessionProperty(javax.mail.Session session, java.lang.String name, int def)Get an integer valued property.
return getInt(session.getProperties().get(name), def);
|
|