FileDocCategorySizeDatePackage
PropUtil.javaAPI DocJavaMail 1.4.34752Tue Nov 17 10:38:12 GMT 2009com.sun.mail.util

PropUtil

public class PropUtil extends Object
Utilities to make it easier to get property values. Properties can be strings or type-specific value objects.
author
Bill Shannon

Fields Summary
Constructors Summary
private PropUtil()

    
Methods Summary
private static booleangetBoolean(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 booleangetBooleanProperty(java.util.Properties props, java.lang.String name, boolean def)
Get a boolean valued property.

	return getBoolean(props.get(name), def);
    
public static booleangetBooleanSessionProperty(javax.mail.Session session, java.lang.String name, boolean def)
Get a boolean valued property.

	return getBoolean(session.getProperties().get(name), def);
    
public static booleangetBooleanSystemProperty(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 intgetInt(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 intgetIntProperty(java.util.Properties props, java.lang.String name, int def)
Get an integer valued property.

	return getInt(props.get(name), def);
    
public static intgetIntSessionProperty(javax.mail.Session session, java.lang.String name, int def)
Get an integer valued property.

	return getInt(session.getProperties().get(name), def);