Example usage for org.apache.commons.lang3 BooleanUtils toBooleanObject

List of usage examples for org.apache.commons.lang3 BooleanUtils toBooleanObject

Introduction

In this page you can find the example usage for org.apache.commons.lang3 BooleanUtils toBooleanObject.

Prototype

public static Boolean toBooleanObject(final String str) 

Source Link

Document

Converts a String to a Boolean.

'true' , 'on' , 'y' , 't' or 'yes' (case insensitive) will return true .

Usage

From source file:info.donsun.core.utils.Values.java

/**
 * ??/*from  www .j a  v a2  s .co  m*/
 * 
 * @param obj 
 * @param defaultValue ,null
 * @return 
 */
public static boolean getBoolean(Object obj, boolean defaultValue) {
    Boolean bool = BooleanUtils.toBooleanObject(getString(obj));
    return bool != null ? bool.booleanValue() : defaultValue;
}

From source file:net.ontopia.utils.PropertyUtils.java

public static boolean isTrue(String property_value, boolean default_value) {
    return BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(property_value), default_value);
}

From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.AbstractOAuth2Base.java

protected static void createOrDescend(JsonObject root, Deque<String> keyPath, String value) {
    // If there are still key-path elements remaining to traverse.
    if (keyPath.size() > 1) {
        // If there's no object already at this key-path create a new JsonObject.
        if (root.getJsonObject(keyPath.peek()) == null) {
            JsonObject newJson = new JsonObject();
            String val = keyPath.pop();
            root.put(val, newJson);
            createOrDescend(newJson, keyPath, value);
        } else { // If there's already an existing object on key-path, grab it and traverse.
            createOrDescend(root.getJsonObject(keyPath.pop()), keyPath, value);
        }/*ww w  .  j a v a 2  s  . c o  m*/
    } else { // Set the value.
        Boolean boolObj = BooleanUtils.toBooleanObject(value);
        if (boolObj != null) {
            root.put(keyPath.pop(), boolObj);
        } else if (StringUtils.isNumeric(value)) {
            root.put(keyPath.pop(), Long.parseLong(value));
        } else {
            root.put(keyPath.pop(), value);
        }
    }
}

From source file:gr.abiss.calipso.jpasearch.specifications.BooleanPredicateFactory.java

/**
 * @see gr.abiss.calipso.jpasearch.jpa.search.specifications.IPredicateFactory#addPredicate(javax.persistence.criteria.Root,
 *      javax.persistence.criteria.CriteriaBuilder, java.lang.String,
 *      java.lang.Class, java.lang.String[])
 *//*from   w ww . j av  a  2  s.c om*/
@Override
public Predicate getPredicate(Root<Persistable> root, CriteriaBuilder cb, String propertyName, Class fieldType,
        String[] propertyValues) {
    Predicate predicate = null;
    if (!Boolean.class.isAssignableFrom(fieldType)) {
        throw new IllegalArgumentException(
                fieldType + " is not a subclass of Boolean for field: " + propertyName);
    }

    Boolean b = BooleanUtils.toBooleanObject(propertyValues[0]);
    if (b == null) {
        b = Boolean.FALSE;
    }

    predicate = cb.equal(root.<Boolean>get(propertyName), b);
    return predicate;
}

From source file:com.mirth.connect.model.AbstractSettings.java

/**
 * Takes a String and returns a Boolean Object.
 * "1" = true/*from ww  w .  j  a v  a 2s .  c  o m*/
 * "0" = false
 * null or not a number = defaultValue
 * 
 * @param str
 * @param defaultValue
 * @return
 */
protected Boolean intToBooleanObject(String str, Boolean defaultValue) {
    int i = NumberUtils.toInt(str, -1);

    if (i == -1) {
        // Must return null explicitly to avoid Java NPE due to autoboxing
        if (defaultValue == null) {
            return null;
        } else {
            return defaultValue;
        }
    } else {
        return BooleanUtils.toBooleanObject(i);
    }
}

From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.LogoutServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(false);
    if (session != null) {
        session.invalidate();//from w ww. j av a  2 s. co m
    }
    /*
     * We need to redirect here rather than forward so that 
     * logout.jsp gets a request object without a user. Otherwise,
     * the button bar will think we're still logged in.
     */
    StringBuilder buf = new StringBuilder();
    String casLogoutUrl = webappProperties.getCasLogoutUrl();
    buf.append(casLogoutUrl);
    String awaitingActivation = req.getParameter("awaitingActivation");
    boolean aaEmpty = StringUtils.isEmpty(awaitingActivation);
    if (!aaEmpty && BooleanUtils.toBooleanObject(awaitingActivation) == null) {
        resp.sendError(HttpStatus.SC_BAD_REQUEST);
        return;
    }
    String notRegistered = req.getParameter("notRegistered");
    boolean nrEmpty = StringUtils.isEmpty(notRegistered);
    if (!nrEmpty && BooleanUtils.toBooleanObject(notRegistered) == null) {
        resp.sendError(HttpStatus.SC_BAD_REQUEST);
        return;
    }
    if (!aaEmpty || !nrEmpty) {
        buf.append('?');
    }
    if (!aaEmpty) {
        buf.append("awaitingActivation=").append(awaitingActivation);
    }
    if (!aaEmpty && !nrEmpty) {
        buf.append('&');
    }
    if (!nrEmpty) {
        buf.append("notRegistered=").append(notRegistered);
    }
    log("URL IS " + buf.toString());
    resp.sendRedirect(buf.toString());
}

From source file:com.esri.geoportal.harvester.ckan.CkanBrokerDefinitionAdaptor.java

/**
 * Initializes adaptor from definition.//from w w  w.j  av  a 2s  .  c o  m
 * @param def broker definition
 * @throws InvalidDefinitionException if definition is invalid
 */
protected void initialize(EntityDefinition def) throws InvalidDefinitionException {
    apiKey = get(P_API_KEY);
    emitXml = BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(get(P_EMIT_XML)), true);
    emitJson = BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(get(P_EMIT_JSON)), false);

    try {
        hostUrl = new URL(get(P_HOST_URL));
    } catch (MalformedURLException ex) {
        throw new InvalidDefinitionException(String.format("Invalid %s: %s", P_HOST_URL, get(P_HOST_URL)), ex);
    }
}

From source file:com.cognifide.aet.job.common.modifiers.hide.HideModifier.java

@Override
public void setParameters(Map<String, String> params) throws ParametersException {
    setElementParams(params);/*from ww  w  .  j a  v  a  2 s .c o m*/
    leaveBlankSpace = BooleanUtils.toBooleanDefaultIfNull(
            BooleanUtils.toBooleanObject(params.get(LEAVE_BLANK_SPACE_PARAM)), LEAVE_BLANK_SPACE_DEFAULT);
}

From source file:io.apiman.manager.api.exportimport.manager.ExportImportConfigParser.java

public boolean isOverwrite() {
    Boolean booleanObject = BooleanUtils.toBooleanObject(System.getProperty(OVERWRITE));
    if (booleanObject == null) {
        booleanObject = Boolean.FALSE;
    }/*from  ww w  . j  a va  2 s  .c  o  m*/
    return booleanObject;
}

From source file:com.epam.wilma.stubconfig.condition.checker.xml.CustomXQueryBodyChecker.java

private boolean evaluateCondition(final String xml, final String query) throws SaxonApiException {
    boolean result;
    String queryResult = queryExpressionEvaluator.evaluateXQuery(xml, query);
    String fromXQueryResult = "";
    try {// www .  j  av  a 2 s.  c  o m
        fromXQueryResult = removeXmlDecTagFromXQueryResult(queryResult);
        result = BooleanUtils.toBooleanObject(fromXQueryResult);
    } catch (NullPointerException e) {
        logger.debug(
                "Expected result of the XQuery evaluation was true or false, but it returned with the following:"
                        + fromXQueryResult + ".\n Thus the condition evaluated to true!",
                e);
        result = true;
    }
    return result;
}