Example usage for org.apache.commons.lang StringUtils containsIgnoreCase

List of usage examples for org.apache.commons.lang StringUtils containsIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils containsIgnoreCase.

Prototype

public static boolean containsIgnoreCase(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String irrespective of case, handling null.

Usage

From source file:org.apache.mailet.base.GenericMailet.java

private static boolean isFalseOrNo(String value) {
    return StringUtils.containsIgnoreCase(value, FALSE) || StringUtils.containsIgnoreCase(value, NO);
}

From source file:org.apache.mailet.base.GenericMailet.java

private static boolean isTrueOrYes(String value) {
    return StringUtils.containsIgnoreCase(value, TRUE) || StringUtils.containsIgnoreCase(value, YES);
}

From source file:org.apache.ranger.biz.RangerBizUtil.java

public static int getDBFlavor() {
    String[] propertyNames = { "xa.db.flavor", "ranger.jpa.jdbc.dialect", "ranger.jpa.jdbc.url",
            "ranger.jpa.jdbc.driver" };

    for (String propertyName : propertyNames) {
        String propertyValue = PropertiesUtil.getProperty(propertyName);

        if (StringUtils.isBlank(propertyValue)) {
            continue;
        }//from w w w . java 2 s  .  c om

        if (StringUtils.containsIgnoreCase(propertyValue, "mysql")) {
            return AppConstants.DB_FLAVOR_MYSQL;
        } else if (StringUtils.containsIgnoreCase(propertyValue, "oracle")) {
            return AppConstants.DB_FLAVOR_ORACLE;
        } else if (StringUtils.containsIgnoreCase(propertyValue, "postgresql")) {
            return AppConstants.DB_FLAVOR_POSTGRES;
        } else if (StringUtils.containsIgnoreCase(propertyValue, "sqlserver")) {
            return AppConstants.DB_FLAVOR_SQLSERVER;
        } else if (StringUtils.containsIgnoreCase(propertyValue, "mssql")) {
            return AppConstants.DB_FLAVOR_SQLSERVER;
        } else if (StringUtils.containsIgnoreCase(propertyValue, "sqlanywhere")) {
            return AppConstants.DB_FLAVOR_SQLANYWHERE;
        } else if (StringUtils.containsIgnoreCase(propertyValue, "sqla")) {
            return AppConstants.DB_FLAVOR_SQLANYWHERE;
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("DB Flavor could not be determined from property - " + propertyName + "="
                        + propertyValue);
            }
        }
    }

    logger.error("DB Flavor could not be determined");

    return AppConstants.DB_FLAVOR_UNKNOWN;
}

From source file:org.apache.ranger.plugin.store.AbstractPredicateUtil.java

private Predicate addPredicateForPartialPolicyName(final String policyName, List<Predicate> predicates) {
    if (StringUtils.isEmpty(policyName)) {
        return null;
    }/*from w w  w .  j a  va 2  s . c om*/

    Predicate ret = new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }

            boolean ret = false;

            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;

                ret = StringUtils.containsIgnoreCase(policy.getName(), policyName);
            } else {
                ret = true;
            }

            return ret;
        }
    };

    if (predicates != null) {
        predicates.add(ret);
    }

    return ret;
}

From source file:org.apache.ranger.plugin.store.AbstractPredicateUtil.java

private Predicate addPredicateForPolicyResource(final String resourceValue, List<Predicate> predicates) {
    if (StringUtils.isEmpty(resourceValue)) {
        return null;
    }/*w  w  w  .ja  v a2  s .c  om*/

    Predicate ret = new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }

            boolean ret = false;

            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;
                Map<String, RangerPolicyResource> policyResources = policy.getResources();

                if (MapUtils.isNotEmpty(policyResources)) {

                    for (Map.Entry<String, RangerPolicyResource> entry : policyResources.entrySet()) {

                        RangerPolicyResource policyResource = entry.getValue();

                        if (policyResource != null && CollectionUtils.isNotEmpty(policyResource.getValues())) {

                            for (String policyResoureValue : policyResource.getValues()) {
                                if (StringUtils.containsIgnoreCase(policyResoureValue, resourceValue)) {
                                    ret = true;

                                    break;
                                }
                            }
                        }

                    }

                }
            } else {
                ret = true;
            }

            return ret;
        }
    };

    if (predicates != null) {
        predicates.add(ret);
    }

    return ret;
}

From source file:org.apache.solr.request.SimpleFacets.java

License:asdf

/**
 * Returns <code>true</code> if a String contains the given substring. Otherwise
 * <code>false</code>.//from   www .j av  a 2 s.  c  om
 *
 * @param ref
 *          the {@link String} to test
 * @param substring
 *          the substring to look for
 * @param ignoreCase
 *          whether the comparison should be case-insensitive
 * @return Returns <code>true</code> iff the String contains the given substring.
 *         Otherwise <code>false</code>.
 */
public static boolean contains(String ref, String substring, boolean ignoreCase) {
    if (ignoreCase)
        return StringUtils.containsIgnoreCase(ref, substring);
    return StringUtils.contains(ref, substring);
}

From source file:org.apache.solr.request.SubstringBytesRefFilter.java

protected boolean includeString(String term) {
    if (ignoreCase) {
        return StringUtils.containsIgnoreCase(term, contains);
    }// w ww.  j  a  v a  2 s .c o  m

    return StringUtils.contains(term, contains);
}

From source file:org.apache.wookie.BasicLTIServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    //debugParameters(request);
    String userId = request.getParameter("user_id"); //$NON-NLS-1$
    String sharedDataKey = request.getParameter("resource_link_id"); //$NON-NLS-1$
    // We use this mapping as BasicLTI assumes one "tool provider" per endpoint URL
    // We map the value onto the actual widget id (IRI)
    String widgetId = Controller.getResourceId(request); //$NON-NLS-1$
    widgetId = getWidgetGuid(widgetId);/*from  ww w .ja v  a 2s .c o m*/
    // TODO Get the oAuth token, for now just use the consumer key as a quick demo hack
    String token = request.getParameter("oauth_consumer_key");
    String locale = request.getParameter("launch_presentation_locale");//replace with real one
    // Construct the internal key
    sharedDataKey = SharedDataHelper.getInternalSharedDataKey(token, widgetId, sharedDataKey);

    HttpSession session = request.getSession(true);
    Messages localizedMessages = LocaleHandler.localizeMessages(request);

    if (userId == null || sharedDataKey == null || widgetId == null)
        error(500, request, response);

    // Construct a proxy URL for this instance
    checkProxy(request);

    // Get an instance
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidgetInstance instance = persistenceManager.findWidgetInstanceByGuid(token, userId, sharedDataKey,
            widgetId);

    // Widget instance exists?
    if (instance == null) {
        instance = WidgetInstanceFactory.getWidgetFactory(session, localizedMessages).newInstance(token, userId,
                sharedDataKey, "", widgetId, locale);
        response.setStatus(HttpServletResponse.SC_CREATED);
    }

    // Not a valid widget
    if (instance == null) {
        error(HttpServletResponse.SC_NOT_FOUND, request, response);
        return;
    }

    response.setStatus(HttpServletResponse.SC_OK);

    // Set some properties, e.g. participant info and roles
    setParticipant(instance, userId, request);

    boolean isModerator = false;
    if (request.getParameter("roles") != null) {
        for (String role : BASICLTI_ADMIN_ROLES) {
            if (StringUtils.containsIgnoreCase(request.getParameter("roles"), role))
                isModerator = true;
        }
    }
    if (isModerator)
        setOwner(instance, userId);
    // Set any other properties as preferences
    setPreferences(instance, request);

    // Redirect to the instance URL
    try {
        // Construct widget instance URL
        // For some reason this doesn't work:
        // String url = URLDecoder.decode(super.getUrl(request, instance),"UTF-8");
        String url = super.getUrl(request, instance).toString().replace("&amp;", "&");
        response.sendRedirect(url);
    } catch (Exception e) {
        error(500, request, response);
        return;
    }

}

From source file:org.apache.zeppelin.hive.HiveInterpreter.java

private InterpreterResult executeSql(String sql) {
    try {/* www. j  a  v a2  s . c om*/
        if (exceptionOnConnect != null) {
            return new InterpreterResult(Code.ERROR, exceptionOnConnect.getMessage());
        }
        currentStatement = jdbcConnection.createStatement();
        StringBuilder msg = null;
        if (StringUtils.containsIgnoreCase(sql, "EXPLAIN ")) {
            //return the explain as text, make this visual explain later
            msg = new StringBuilder();
        } else {
            msg = new StringBuilder("%table ");
        }
        ResultSet res = currentStatement.executeQuery(sql);
        try {
            ResultSetMetaData md = res.getMetaData();
            for (int i = 1; i < md.getColumnCount() + 1; i++) {
                if (i == 1) {
                    msg.append(md.getColumnName(i));
                } else {
                    msg.append("\t" + md.getColumnName(i));
                }
            }
            msg.append("\n");
            while (res.next()) {
                for (int i = 1; i < md.getColumnCount() + 1; i++) {
                    msg.append(res.getString(i) + "\t");
                }
                msg.append("\n");
            }
        } finally {
            try {
                res.close();
                currentStatement.close();
            } finally {
                currentStatement = null;
            }
        }

        InterpreterResult rett = new InterpreterResult(Code.SUCCESS, msg.toString());
        return rett;
    } catch (SQLException ex) {
        logger.error("Can not run " + sql, ex);
        return new InterpreterResult(Code.ERROR, ex.getMessage());
    }
}

From source file:org.apache.zeppelin.phoenix.PhoenixInterpreter.java

private InterpreterResult executeSql(String sql) {
    try {//  w  w w  . j  ava  2  s . c o m
        if (exceptionOnConnect != null) {
            return new InterpreterResult(Code.ERROR, exceptionOnConnect.getMessage());
        }

        currentStatement = getJdbcConnection().createStatement();

        boolean isExplain = StringUtils.containsIgnoreCase(sql, EXPLAIN_PREDICATE);
        StringBuilder msg = (isExplain) ? new StringBuilder() : new StringBuilder(TABLE_MAGIC_TAG);

        ResultSet res = null;
        try {
            boolean hasResult = currentStatement.execute(sql);
            if (hasResult) { //If query had results
                res = currentStatement.getResultSet();
                //Append column names
                ResultSetMetaData md = res.getMetaData();
                String row = clean(isExplain, md.getColumnName(1));
                for (int i = 2; i < md.getColumnCount() + 1; i++)
                    row += TAB + clean(isExplain, md.getColumnName(i));
                msg.append(row + NEWLINE);

                //Append rows
                int rowCount = 0;
                while (res.next() && rowCount < getMaxResult()) {
                    row = clean(isExplain, res.getString(1));
                    for (int i = 2; i < md.getColumnCount() + 1; i++)
                        row += TAB + clean(isExplain, res.getString(i));
                    msg.append(row + NEWLINE);
                    rowCount++;
                }
            } else { // May have been upsert or DDL
                msg.append(UPDATE_HEADER + NEWLINE + "Rows affected: " + currentStatement.getUpdateCount()
                        + NEWLINE);
            }

        } finally {
            try {
                if (res != null)
                    res.close();
                getJdbcConnection().commit();
                currentStatement.close();
            } finally {
                currentStatement = null;
            }
        }

        return new InterpreterResult(Code.SUCCESS, msg.toString());
    } catch (SQLException ex) {
        logger.error("Can not run " + sql, ex);
        return new InterpreterResult(Code.ERROR, ex.getMessage());
    }
}