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

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

Introduction

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

Prototype

public static int indexOfIgnoreCase(String str, String searchStr) 

Source Link

Document

Case in-sensitive find of the first index within a String.

Usage

From source file:com.taobao.tdhs.jdbc.sqlparser.ParseSQL.java

public String removeSpace(String tmp_wherestr) {
    String tmpString = "";
    int addr_between = StringUtils.indexOfIgnoreCase(tmp_wherestr, " between ");
    int addr_and;
    int start = 0;
    while (addr_between > -1) {
        addr_and = StringUtils.indexOfIgnoreCase(tmp_wherestr, " and ", addr_between);
        tmpString = tmpString + tmp_wherestr.substring(start, addr_between) + " between "
                + tmp_wherestr.substring(addr_between + 9, addr_and).trim().replaceAll(" ", "#") + " and ";
        addr_between = StringUtils.indexOfIgnoreCase(tmp_wherestr, " between ", addr_and + 5);
        start = addr_and + 5;//  w ww .ja v  a 2s  . c om
    }
    if (start < tmp_wherestr.length()) {
        tmpString = tmpString + tmp_wherestr.substring(start);
    }
    return tmpString;
}

From source file:com.taobao.tdhs.jdbc.sqlparser.ParseSQL.java

private TreeNode parseBase(TreeNode rootnode, String str) {
    int addr;//ww  w. j a v a  2 s . com

    addr = StringUtils.indexOfIgnoreCase(str, ">=");
    if (addr > 0) {
        return buildTree(rootnode, str, addr, 2);
    }

    addr = StringUtils.indexOfIgnoreCase(str, "<=");
    if (addr > 0) {
        return buildTree(rootnode, str, addr, 2);
    }

    addr = StringUtils.indexOfIgnoreCase(str, ">");
    if (addr > 0) {
        return buildTree(rootnode, str, addr, 1);
    }

    addr = StringUtils.indexOfIgnoreCase(str, "<");
    if (addr > 0) {
        return buildTree(rootnode, str, addr, 1);
    }

    addr = StringUtils.indexOfIgnoreCase(str, "!=");
    if (addr > 0) {
        return buildTree(rootnode, str, addr, 2);
    }

    addr = StringUtils.indexOfIgnoreCase(str, "=");
    if (addr > 0) {
        return buildTree(rootnode, str, addr, 1);
    }

    addr = StringUtils.indexOfIgnoreCase(str, " in ");
    if (addr > 0) {
        // ?in,???,??
        // ???
        return buildTree(rootnode, str, addr, 4);
    }

    addr = StringUtils.indexOfIgnoreCase(str, " like ");
    if (addr > 0) {
        return buildTree(rootnode, str, addr, 6);
    }

    addr = StringUtils.indexOfIgnoreCase(str, " is ");
    if (addr > 0) {
        return buildTree(rootnode, str, addr, 4);
    }

    return null;
}

From source file:com.taobao.tdhs.jdbc.sqlparser.ParseSQL.java

public TreeNode parseWhere(TreeNode rootnode, String str_where, int loop) {
    // //from   w  w  w . ja  v  a  2 s  . c o  m
    loop++;
    if (loop > 10000)
        return null;

    String str = str_where.trim();
    TreeNode node = new TreeNode();
    int addr_and;
    int addr_or;
    // ??,??
    if (str.substring(0, 1).equalsIgnoreCase("(")) {
        // ???
        // SQL??in,???
        Stack<String> stack = new Stack<String>();
        int k = 0;
        String tmp_s;
        while (k < str.length()) {
            tmp_s = str.substring(k, k + 1);
            if (!tmp_s.equalsIgnoreCase(")"))
                // 
                stack.push(tmp_s);
            else {
                // ,??
                while (!stack.pop().equalsIgnoreCase("(")) {
                    ;
                }
                // ?,,?
                if (stack.isEmpty())
                    break;
            }

            k++;
        } // end while

        if (k == str.length() - 1) {
            // ??
            return parseWhere(rootnode, str.substring(1, k), loop);
        } else {
            // ??,and  or,
            if (str.substring(k + 1, k + 6).equalsIgnoreCase(" and ")) {
                node.node_content = "and";
                node.node_type = 4;
                node.left_node = parseWhere(node, str.substring(1, k), loop);
                node.right_node = parseWhere(node, str.substring(k + 6), loop);
                node.parent_node = rootnode;
            } else if (str.substring(k + 1, k + 5).equalsIgnoreCase(" or ")) {
                node.node_content = "or";
                node.node_type = 4;
                node.left_node = parseWhere(node, str.substring(1, k), loop);
                node.right_node = parseWhere(node, str.substring(k + 5), loop);
                node.parent_node = rootnode;
            }

            return node;

        }
    } else {
        addr_and = StringUtils.indexOfIgnoreCase(str, " and ");
        addr_or = StringUtils.indexOfIgnoreCase(str, " or ");
        if (addr_and > 0 && addr_or > 0)
            if (addr_and < addr_or) {
                // and
                node.node_content = "and";
                node.node_type = 4;
                node.parent_node = rootnode;
                node.left_node = parseBase(node, str.substring(0, addr_and).trim());
                node.right_node = parseWhere(node, str.substring(addr_and + 5), loop);
                return node;
            } else {
                // or
                node.node_content = "or";
                node.node_type = 4;
                node.parent_node = rootnode;
                node.left_node = parseBase(node, str.substring(0, addr_or).trim());
                node.right_node = parseWhere(node, str.substring(addr_or + 4), loop);
                return node;
            }
        else if (addr_and > 0) {
            node.node_content = "and";
            node.node_type = 4;
            node.parent_node = rootnode;
            node.left_node = parseBase(node, str.substring(0, addr_and).trim());
            node.right_node = parseWhere(node, str.substring(addr_and + 5), loop);
            return node;
        } else if (addr_or > 0) {
            node.node_content = "or";
            node.node_type = 4;
            node.parent_node = rootnode;
            node.left_node = parseBase(node, str.substring(0, addr_or).trim());
            node.right_node = parseWhere(node, str.substring(addr_or + 4), loop);
            return node;
        } else {
            // ??
            return parseBase(rootnode, str);
        }
    }
}

From source file:ips1ap101.lib.core.db.xdp.RecursoCachedRowSetDataProvider.java

/**
 * Getter para propiedad comandoSelectRestringido.
 *
 * @return Valor de la propiedad comandoSelectRestringido.
 *//* w  w w  . j a  va2 s.com*/
public String getComandoSelectRestringido() {
    String select = getComandoSelectAnsi();
    String columnas = getColumnasComandoSelectRestringido();
    int i = StringUtils.isBlank(columnas) ? -1 : StringUtils.indexOfIgnoreCase(select, " FROM ");
    return i < 0 ? select : "SELECT " + columnas + select.substring(i);
}

From source file:org.hippoecm.repository.util.RepoUtils.java

public static String encodeXpath(String xpath) {
    final int whereClauseIndexStart = xpath.indexOf("[");
    final int whereClauseIndexEnd = xpath.lastIndexOf("]");
    final String orderByString = " order by ";
    if (whereClauseIndexStart > -1 && whereClauseIndexEnd > -1) {
        String beforeWhere = xpath.substring(0, whereClauseIndexStart);
        String afterWhere = xpath.substring(whereClauseIndexEnd + 1, xpath.length());
        // in where clause we can have path constraints
        String whereClause = "[" + xpath.substring(whereClauseIndexStart + 1, whereClauseIndexEnd) + "]";
        return encodePathConstraint(beforeWhere) + whereClause + afterWhere;
    } else if (StringUtils.containsIgnoreCase(xpath, orderByString)) {
        int orderByIndex = StringUtils.indexOfIgnoreCase(xpath, orderByString);
        return encodePathConstraint(xpath.substring(0, orderByIndex)) + xpath.substring(orderByIndex);
    } else if (whereClauseIndexStart == -1 && whereClauseIndexEnd == -1) {
        // only path
        return encodePathConstraint(xpath);
    } else {// w  ww .j ava 2 s.  co m
        // most likely incorrect query
        return xpath;
    }

}

From source file:org.jahia.services.query.QueryWrapper.java

/**
 * Get the query for a specific provider
 *
 * @param jcrStoreProvider/*w  w  w .java  2  s.  co m*/
 * @return
 * @throws RepositoryException
 */
protected Query getQuery(JCRStoreProvider jcrStoreProvider) throws RepositoryException {
    Query query = null;
    QueryManager qm = jcrStoreProvider.getQueryManager(session);

    String statement = null;
    String language = this.language;

    if (qm != null) {
        if (ArrayUtils.contains(qm.getSupportedQueryLanguages(), language)) {
            statement = this.statement;
        } else if (sqlStatement != null
                && ArrayUtils.contains(qm.getSupportedQueryLanguages(), Query.JCR_SQL2)) {
            statement = this.sqlStatement;
            language = Query.JCR_SQL2;
        }
    }
    if (statement != null) {
        boolean facetDelimiterReplaced = false;
        if (jcrStoreProvider.isDefault() && jrQOM != null) {
            query = jrQOM;
        } else {
            if (statement.contains("rep:facet")) {
                facetDelimiterReplaced = true;
                int selectIndex = StringUtils.indexOfIgnoreCase(statement, "select ");
                int fromIndex = StringUtils.indexOfIgnoreCase(statement, " from ");
                String rewritedColumns = statement.substring(selectIndex, fromIndex).replaceAll("&",
                        "JAHIA_TEMP_FACET_DELIMITER_PLACEHOLDER");
                statement = statement.substring(0, selectIndex) + rewritedColumns
                        + statement.substring(fromIndex, statement.length());
            }
            query = qm.createQuery(statement, language);
        }
        QueryObjectModelFactory factory = qm.getQOMFactory();
        if (!jcrStoreProvider.getMountPoint().equals("/")) {
            try {
                QueryObjectModel qom;
                if (query instanceof QueryObjectModel) {
                    qom = (QueryObjectModel) query;
                } else if (language.equals(Query.JCR_SQL2)) {
                    qom = (QueryObjectModel) service.getDefaultProvider().getQueryManager(session)
                            .createQuery(statement, language);
                } else if (sqlStatement != null) {
                    qom = (QueryObjectModel) service.getDefaultProvider().getQueryManager(session)
                            .createQuery(sqlStatement, Query.JCR_SQL2);
                } else {
                    // Cannot create query on provider, skip
                    return null;
                }
                Constraint constraint = convertPath(qom.getConstraint(), jcrStoreProvider.getMountPoint(),
                        jcrStoreProvider.getRelativeRoot(), factory);
                if (!jcrStoreProvider.getRelativeRoot().equals("")) {
                    Constraint addRelativeRootConstraint = addRelativeRootConstraint(factory,
                            jcrStoreProvider.getRelativeRoot(), qom.getSource());
                    constraint = (constraint == null) ? addRelativeRootConstraint
                            : factory.and(addRelativeRootConstraint, constraint);
                }
                query = factory.createQuery(qom.getSource(), constraint, qom.getOrderings(), qom.getColumns());
            } catch (ConstraintViolationException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.getMessage(), e);
                }
                // Provider path incompatible with constraints, skip query
                return null;
            } catch (NamespaceException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.getMessage(), e);
                }
                // Query nodetype / namespace does not exist on this provider, skip query
                return null;
            }
        }
        if (query != null && query instanceof QueryObjectModel) {
            if (Query.JCR_SQL2.equals(language)) {
                QueryObjectModel qom = QueryServiceImpl.getInstance()
                        .modifyAndOptimizeQuery((QueryObjectModel) query, factory, session);
                Constraint constraint;
                if (jcrStoreProvider.isDefault()) {
                    constraint = filterMountPoints(qom.getConstraint(), qom.getSource(), factory);
                } else {
                    constraint = qom.getConstraint();
                }

                Column[] columns;
                if (facetDelimiterReplaced) {
                    columns = new Column[qom.getColumns().length];
                    for (int i = 0; i < qom.getColumns().length; i++) {
                        Column column = qom.getColumns()[i];
                        columns[i] = factory.column(column.getSelectorName(), column.getPropertyName(), column
                                .getColumnName().replaceAll("JAHIA_TEMP_FACET_DELIMITER_PLACEHOLDER", "&"));
                    }
                } else {
                    columns = qom.getColumns();
                }

                query = factory.createQuery(qom.getSource(), constraint, qom.getOrderings(), columns);
            }
            if (query instanceof JahiaQueryObjectModelImpl) {
                JahiaLuceneQueryFactoryImpl lqf = (JahiaLuceneQueryFactoryImpl) ((JahiaQueryObjectModelImpl) query)
                        .getLuceneQueryFactory();
                lqf.setQueryLanguageAndLocale(LuceneUtils.extractLanguageOrNullFromStatement(statement),
                        session.getLocale());
            }
        }
    }
    return query;
}

From source file:org.openhab.io.neeo.internal.TokenSearch.java

/**
 * The search algorithm (lifted from tokensearch.js)
 *
 * @param haystack the search term//from w  ww  .  j a  v a  2s . c o m
 * @param needles the items to search
 * @return the score of the match
 */
private int searchAlgorithm(String haystack, String[] needles) {
    Objects.requireNonNull(needles, "needles cannot be null");

    int score = 0;

    int arrayLength = needles.length;
    for (int i = 0; i < arrayLength; i++) {
        String needle = needles[i];
        int stringPos = StringUtils.indexOfIgnoreCase(haystack, needle);
        int tokenScore = 0;
        if (stringPos > -1) {
            if (needle.length() < 2) {
                tokenScore = 1;
            } else {
                if (StringUtils.equalsIgnoreCase(haystack, needle)) {
                    tokenScore = 6;
                } else if (stringPos == 0) {
                    tokenScore = 2;
                } else {
                    tokenScore = 1;
                }
            }
        }
        score += tokenScore;
    }
    return score;
}

From source file:org.sonar.core.i18n.RuleI18nManager.java

public List<RuleKey> searchNames(String search, Locale locale) {
    List<RuleKey> result = Lists.newArrayList();
    for (RuleKey ruleKey : ruleKeys) {
        String name = i18nManager.message(locale, ruleKey.getNameProperty(), null);
        if (name != null && StringUtils.indexOfIgnoreCase(name, search) >= 0) {
            result.add(ruleKey);/* w w w .  j a v  a 2 s.  com*/
        }
    }
    return result;
}

From source file:org.sonar.css.checks.CommentContainsPatternChecker.java

private static boolean isLetterAround(String line, String pattern) {
    int start = StringUtils.indexOfIgnoreCase(line, pattern);
    int end = start + pattern.length();

    boolean pre = start > 0 && Character.isLetter(line.charAt(start - 1));
    boolean post = end < line.length() - 1 && Character.isLetter(line.charAt(end));

    return pre || post;
}

From source file:org.sonar.cxx.checks.CommentContainsPatternChecker.java

private boolean isLetterAround(String line, String pattern) {
    int start = StringUtils.indexOfIgnoreCase(line, pattern);
    int end = start + pattern.length();

    boolean pre = start > 0 ? Character.isLetter(line.charAt(start - 1)) : false;
    boolean post = end < line.length() - 1 ? Character.isLetter(line.charAt(end)) : false;

    return pre || post;
}