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.granita.icloudcalsync.DateUtils.java

public static String findAndroidTimezoneID(String tzID) {
    String localTZ = null;//from w w  w  . j  a  v a2 s .co  m
    String availableTZs[] = SimpleTimeZone.getAvailableIDs();

    // first, try to find an exact match (case insensitive)
    for (String availableTZ : availableTZs)
        if (availableTZ.equalsIgnoreCase(tzID)) {
            localTZ = availableTZ;
            break;
        }

    // if that doesn't work, try to find something else that matches
    if (localTZ == null) {
        Log.w(TAG, "Coulnd't find time zone with matching identifiers, trying to guess");
        for (String availableTZ : availableTZs)
            if (StringUtils.indexOfIgnoreCase(tzID, availableTZ) != -1) {
                localTZ = availableTZ;
                break;
            }
    }

    // if that doesn't work, use UTC as fallback
    if (localTZ == null) {
        Log.e(TAG, "Couldn't identify time zone, using UTC as fallback");
        localTZ = Time.TIMEZONE_UTC;
    }

    Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID);
    return localTZ;
}

From source file:com.iadams.sonarqube.puppet.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)) : false;
    boolean post = end < line.length() - 1 ? Character.isLetter(line.charAt(end)) : false;

    return pre || post;
}

From source file:gr.seab.r2rml.entities.sql.SelectQuery.java

public ArrayList<SelectTable> createSelectTables(String q) {
    ArrayList<SelectTable> results = new ArrayList<SelectTable>();

    int start = q.toUpperCase().indexOf("FROM") + 4;
    ArrayList<String> tables = new ArrayList<String>();

    //split in spaces
    String tokens[] = q.substring(start).split("\\s+");

    //if there are aliases
    if (StringUtils.containsIgnoreCase(q.substring(start), "AS")) {
        for (int i = 0; i < tokens.length; i++) {
            if ("AS".equalsIgnoreCase(tokens[i])) {
                if (tokens[i + 1].endsWith(",")) {
                    tokens[i + 1] = tokens[i + 1].substring(0, tokens[i + 1].indexOf(","));
                }//from  w ww  .j a  v  a 2s.  c o m
                tables.add(tokens[i - 1] + " " + tokens[i] + " " + tokens[i + 1]);
            }
        }
    } else {
        //otherwise, split in commas
        int end = StringUtils.indexOfIgnoreCase(q, "WHERE");
        if (end == -1)
            end = q.length();
        tables = new ArrayList<String>(Arrays.asList(q.substring(start, end).split(",")));
    }

    for (String table : tables) {
        SelectTable selectTable = new SelectTable();
        selectTable.setName(table.trim());
        selectTable.setAlias(createAlias(selectTable.getName()).trim());
        log.info("Adding table with: name '" + selectTable.getName() + "', alias '" + selectTable.getAlias()
                + "'");
        results.add(selectTable);
    }
    return results;
}

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

private void analyzeSQLHint() {
    int addr = StringUtils.indexOfIgnoreCase(sql, "/*");
    if (addr < 0) {//  w w w  .  j a  v a  2  s . c  om
        return;
    }
    int addr_right = StringUtils.indexOfIgnoreCase(sql, "*/");
    if (addr < 0 || addr_right < addr) {
        errmsg = "hint systax is not right.";
        return;
    }

    String hintString = sql.substring(addr, addr_right + 2);
    this.hint = new HintStruct(hintString);
    this.hint.AnalyzeHint();
    this.sql = sql.substring(0, addr) + sql.substring(addr_right + 2);
}

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

private void analyzeSortMethod() {
    if (StringUtils.indexOfIgnoreCase(sql, "order by") > 0 && StringUtils.indexOfIgnoreCase(sql, " asc") > 0) {
        this.sortMethod = OrderByType.ASC;
    } else if (StringUtils.indexOfIgnoreCase(sql, "order by") > 0
            && StringUtils.indexOfIgnoreCase(sql, " desc") > 0) {
        this.sortMethod = OrderByType.DESC;
    } else if (StringUtils.indexOfIgnoreCase(sql, "order by") > 0) {
        // ??/*from w  w w  .  j a v a 2  s  .  co m*/
        this.sortMethod = OrderByType.ASC;
    } else {
        this.sortMethod = null;
    }
}

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

private void analyzeLimit() {
    int addr = StringUtils.indexOfIgnoreCase(sql, " limit ");
    if (addr < 0) {
        return;/*w w w.  j  a  v  a 2  s .c o  m*/
    }
    addr = addr + 7;
    String limitstr = sql.substring(addr).trim();
    String[] array_limit = limitstr.split(",");
    if (array_limit.length == 1) {
        this.limitStart = 0;
        this.limit = Integer.valueOf(array_limit[0]);
        if (this.limit < 0) {
            this.errmsg = "limitOffset should larger than 0";
        }
    } else if (array_limit.length == 2) {
        this.limitStart = Integer.valueOf(array_limit[0]);
        this.limit = Integer.valueOf(array_limit[1]);
        if (this.limitStart < 0) {
            this.errmsg = "limitStart should larger than 0";
            return;
        }
        if (this.limit < 0) {
            this.errmsg = "limitOffset should larger than 0";
            return;
        }
    } else {
        this.errmsg = "wrong limit systax.";
    }
}

From source file:at.bitfire.davdroid.resource.Event.java

protected static void validateTimeZone(DateProperty date) {
    if (date.isUtc() || !hasTime(date))
        return;/*from  w ww.  java  2  s . c  o  m*/

    String tzID = getTzId(date);
    if (tzID == null)
        return;

    String localTZ = null;
    String availableTZs[] = SimpleTimeZone.getAvailableIDs();

    // first, try to find an exact match (case insensitive)
    for (String availableTZ : availableTZs)
        if (tzID.equalsIgnoreCase(availableTZ)) {
            localTZ = availableTZ;
            break;
        }

    // if that doesn't work, try to find something else that matches
    if (localTZ == null) {
        Log.w(TAG, "Coulnd't find time zone with matching identifiers, trying to guess");
        for (String availableTZ : availableTZs)
            if (StringUtils.indexOfIgnoreCase(tzID, availableTZ) != -1) {
                localTZ = availableTZ;
                break;
            }
    }

    // if that doesn't work, use UTC as fallback
    if (localTZ == null) {
        Log.e(TAG, "Couldn't identify time zone, using UTC as fallback");
        localTZ = Time.TIMEZONE_UTC;
    }

    Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID);
    date.setTimeZone(tzRegistry.getTimeZone(localTZ));
}

From source file:ips1ap101.lib.core.db.util.InterpreteSqlAbstracto.java

@Override
public String getComandoSelect1(String comando) {
    if (StringUtils.isBlank(comando)) {
        return null;
    }/*  w ww .j a va  2s  . c o m*/
    int i = StringUtils.indexOfIgnoreCase(comando, " FROM ");
    if (i < 8) {
        return null;
    }
    int j = StringUtils.indexOfIgnoreCase(comando, " GROUP BY ");
    if (j < 0) {
        j = StringUtils.indexOfIgnoreCase(comando, " ORDER BY ");
    }
    if (j < 0) {
        j = comando.length();
    }
    String substring1 = comando.substring(i, j);
    return "SELECT 1" + substring1;
}

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

private void parseSQLDelete() {
    // delete?SQL auto review,???where???
    logger.debug("SQL at parsing:" + this.sql);
    int i = 0;/*from ww  w .  j av  a  2  s.com*/
    int loop = 0;
    // 
    if (i + 6 < sql.length() && sql.substring(0, 6).equalsIgnoreCase("delete"))
        i = i + 6;
    else {
        this.errmsg = "not delete SQL statement.";
        return;
    }

    // ,?
    while (i + 1 < sql.length() && sql.substring(i, i + 1).equalsIgnoreCase(" "))
        i++;

    // ,from
    if (i + 4 < sql.length() && sql.substring(i, i + 4).equalsIgnoreCase("from"))
        i = i + 4;
    else {
        this.errmsg = "not find from key word.";
        return;
    }

    // ,?
    while (i + 1 < sql.length() && sql.substring(i, i + 1).equalsIgnoreCase(" "))
        i++;

    // ,tablename
    while (i + 1 < sql.length() && !sql.substring(i, i + 1).equalsIgnoreCase(" ")) {
        tablename = tablename + sql.substring(i, i + 1);
        i++;
    }

    logger.debug("table name:" + this.tablename);

    // ,?
    while (i + 1 < sql.length() && sql.substring(i, i + 1).equalsIgnoreCase(" "))
        i++;

    // ,where
    if (i + 5 <= sql.length() && sql.substring(i, i + 5).equalsIgnoreCase("where"))
        i = i + 5;
    else {
        this.errmsg = "not find where key word.";
        return;
    }

    // ?
    if (i > sql.length()) {
        this.errmsg = "not find where condition.";
        logger.warn(this.errmsg);
        return;
    } else {
        if (sql.substring(i).trim().length() == 0) {
            this.errmsg = "not find where condition.";
            logger.warn(this.errmsg);
            return;
        }
    }

    int addrOderBy = StringUtils.indexOfIgnoreCase(sql, "order by");
    int addrLimit = StringUtils.indexOfIgnoreCase(sql, " limit ");
    String whereStr;
    if (addrOderBy > 0) {
        whereStr = sql.substring(i, addrOderBy);
    } else if (addrLimit > 0) {
        whereStr = sql.substring(i, addrLimit);
    } else {
        whereStr = sql.substring(i);
    }

    whereNode = parseWhere(null, whereStr, loop);

    // ????
    whereNode = parseWhere(null, whereStr.trim(), loop);

    // check whereNode tree
    checkWhereTreeRootNode(whereNode);
    analyzeOrderByStr();
    logger.debug("where condition:" + whereStr.trim());
}

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

public void analyzeOrderByStr() {
    logger.debug("enter function AnalyzeOrderByStr");
    String orderbycolumns = "";
    int addr_order_by = StringUtils.indexOfIgnoreCase(sql, "order by");
    if (addr_order_by < 0)
        return;/*from w w  w .j  a  v  a2  s. c om*/

    if (StringUtils.indexOfIgnoreCase(sql, " limit ", addr_order_by) > addr_order_by) {
        orderbycolumns = sql.substring(addr_order_by + 8,
                StringUtils.indexOfIgnoreCase(sql, " limit ", addr_order_by));
    } else {
        // no limit key word
        orderbycolumns = sql.substring(addr_order_by + 8).trim();
    }

    orderbycolumns = orderbycolumns.replace(" asc", " ");
    orderbycolumns = orderbycolumns.replace(" desc", " ");
    this.orderbycolumn = orderbycolumns;
    logger.debug("order by columns:" + orderbycolumn);
}