Example usage for org.apache.commons.lang BooleanUtils toBoolean

List of usage examples for org.apache.commons.lang BooleanUtils toBoolean

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils toBoolean.

Prototype

public static boolean toBoolean(String str, String trueString, String falseString) 

Source Link

Document

Converts a String to a Boolean throwing an exception if no match found.

null is returned if there is no match.

 BooleanUtils.toBoolean("true", "true", "false")  = true BooleanUtils.toBoolean("false", "true", "false") = false 

Usage

From source file:com.redhat.rhn.frontend.xmlrpc.user.UserHandler.java

/**
 * Creates a new user//from   www .j ava2 s .c om
 * @param loggedInUser The current user
 * @param desiredLogin The login for the new user
 * @param desiredPassword The password for the new user
 * @param firstName The first name of the new user
 * @param lastName The last name of the new user
 * @param email The email address for the new user
 * @param usePamAuth Should this user authenticate via PAM?
 * @return Returns 1 if successful (exception otherwise)
 * @throws FaultException A FaultException is thrown if the loggedInUser doesn't have
 * permissions to create new users in thier org.
 *
 * @xmlrpc.doc Create a new user.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param_desc("string", "desiredLogin", "Desired login name,
 * will fail if already in use.")
 * @xmlrpc.param #param("string", "desiredPassword")
 * @xmlrpc.param #param("string", "firstName")
 * @xmlrpc.param #param("string", "lastName")
 * @xmlrpc.param #param_desc("string", "email", "User's e-mail address.")
 * @xmlrpc.param #param_desc("int", "usePamAuth", "1 if you wish to use PAM
 * authentication for this user, 0 otherwise.")
 * @xmlrpc.returntype #return_int_success()
 */
public int create(User loggedInUser, String desiredLogin, String desiredPassword, String firstName,
        String lastName, String email, Integer usePamAuth) throws FaultException {
    //Logged in user must be an org admin and we must be on a sat to do this.
    ensureOrgAdmin(loggedInUser);
    ensurePasswordOrPamAuth(usePamAuth, desiredPassword);

    boolean pamAuth = BooleanUtils.toBoolean(usePamAuth, new Integer(1), new Integer(0));

    if (pamAuth) {
        desiredPassword = getDefaultPasswordForPamAuth();
    }

    CreateUserCommand command = new CreateUserCommand();
    command.setUsePamAuthentication(pamAuth);
    command.setLogin(desiredLogin);
    command.setPassword(desiredPassword);
    command.setFirstNames(firstName);
    command.setLastName(lastName);
    command.setEmail(email);
    command.setOrg(loggedInUser.getOrg());
    command.setCompany(loggedInUser.getCompany());

    //Validate the user to be
    ValidatorError[] errors = command.validate();
    if (errors.length > 0) {
        StringBuilder errorString = new StringBuilder();
        LocalizationService ls = LocalizationService.getInstance();
        //Build a sane error message here
        for (int i = 0; i < errors.length; i++) {
            ValidatorError err = errors[i];
            errorString.append(ls.getMessage(err.getKey(), err.getValues()));
            if (i != errors.length - 1) {
                errorString.append(" :: ");
            }
        }
        //Throw a BadParameterException with our message string
        throw new BadParameterException(errorString.toString());
    }

    command.storeNewUser();
    return 1;
}

From source file:com.redhat.rhn.frontend.xmlrpc.user.UserHandler.java

private void ensurePasswordOrPamAuth(Integer usePamAuth, String password) throws FaultException {
    if (!BooleanUtils.toBoolean(usePamAuth, new Integer(1), new Integer(0)) && StringUtils.isEmpty(password)) {
        throw new FaultException(-501, "passwordRequiredOrUsePam",
                "Password is required if not using PAM authentication");
    }//from   w w  w.j a v  a 2s  . com
}

From source file:org.apache.carbondata.processing.loading.csvinput.CSVInputFormat.java

/**
 * Sets the skipEmptyLine to configuration. Default it is false
 *
 * @param configuration//from w w  w  . ja v  a  2s  . c  om
 * @param skipEmptyLine
 */
public static void setSkipEmptyLine(Configuration configuration, String skipEmptyLine) {
    if (skipEmptyLine != null && !skipEmptyLine.isEmpty()) {
        configuration.set(SKIP_EMPTY_LINE, skipEmptyLine);
    } else {
        try {
            BooleanUtils.toBoolean(
                    CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_SKIP_EMPTY_LINE),
                    "true", "false");
            configuration.set(SKIP_EMPTY_LINE,
                    CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_SKIP_EMPTY_LINE));
        } catch (Exception e) {
            configuration.set(SKIP_EMPTY_LINE, CarbonCommonConstants.CARBON_SKIP_EMPTY_LINE_DEFAULT);
        }
    }
}