List of usage examples for org.apache.commons.lang StringUtils indexOfIgnoreCase
public static int indexOfIgnoreCase(String str, String searchStr, int startPos)
Case in-sensitive find of the first index within a String from the specified position.
From source file:com.taobao.tdhs.jdbc.NonRegisteringDriver.java
public Properties parseURL(String url, Properties defaults) throws java.sql.SQLException { Properties urlProps = (defaults != null) ? new Properties(defaults) : new Properties(); if (url == null) { return null; }// ww w . j a va2s .c om if (!StringUtils.startsWithIgnoreCase(url, URL_PREFIX)) { return null; } int beginningOfSlashes = url.indexOf("//"); int index = url.indexOf("?"); if (index != -1) { String paramString = url.substring(index + 1, url.length()); url = url.substring(0, index); StringTokenizer queryParams = new StringTokenizer(paramString, "&"); while (queryParams.hasMoreTokens()) { String parameterValuePair = queryParams.nextToken(); int indexOfEquals = StringUtils.indexOfIgnoreCase(parameterValuePair, "=", 0); String parameter = null; String value = null; if (indexOfEquals != -1) { parameter = parameterValuePair.substring(0, indexOfEquals); if (indexOfEquals + 1 < parameterValuePair.length()) { value = parameterValuePair.substring(indexOfEquals + 1); } } if ((value != null && value.length() > 0) && (parameter != null && parameter.length() > 0)) { try { urlProps.put(parameter, URLDecoder.decode(value, "UTF-8")); } catch (UnsupportedEncodingException badEncoding) { // punt urlProps.put(parameter, URLDecoder.decode(value)); } catch (NoSuchMethodError nsme) { // punt again urlProps.put(parameter, URLDecoder.decode(value)); } } } } url = url.substring(beginningOfSlashes + 2); String hostStuff = null; int slashIndex = StringUtil.indexOfIgnoreCaseRespectMarker(0, url, "/", ALLOWED_QUOTES, ALLOWED_QUOTES, true); if (slashIndex != -1) { hostStuff = url.substring(0, slashIndex); if ((slashIndex + 1) < url.length()) { urlProps.put(DBNAME_PROPERTY_KEY, url.substring((slashIndex + 1), url.length())); } } else { hostStuff = url; } if ((hostStuff != null) && (hostStuff.trim().length() > 0)) { String[] hostPortPair = StringUtils.split(hostStuff, ":"); if (StringUtils.isNotBlank(hostPortPair[0])) { urlProps.setProperty(HOST_PROPERTY_KEY, hostPortPair[0]); } else { urlProps.setProperty(HOST_PROPERTY_KEY, "localhost"); } if (hostPortPair.length > 1 && StringUtils.isNotBlank(hostPortPair[1])) { urlProps.setProperty(PORT_PROPERTY_KEY, hostPortPair[1]); } else { urlProps.setProperty(PORT_PROPERTY_KEY, "9999"); } } else { urlProps.setProperty(HOST_PROPERTY_KEY, "localhost"); urlProps.setProperty(PORT_PROPERTY_KEY, "9999"); } return urlProps; }
From source file:com.taobao.tdhs.jdbc.sqlparser.ParseSQL.java
private void parseSQLInsert() { // insert SQL logger.debug(sql);/* w w w .j a v a 2s. c om*/ int i = 0; int addr_values; String columns; String values; // insert if (sql.substring(0, 6).equalsIgnoreCase("insert")) { i = i + 6; } else { errmsg = "it is not a insert SQL"; return; } // ?into while (sql.substring(i, i + 1).equalsIgnoreCase(" ")) { i++; } if (!sql.substring(i, i + 4).equalsIgnoreCase("into")) { errmsg = "insert sql miss into,syntax error!"; return; } else { i = i + 4; } // ???? while (sql.substring(i, i + 1).equalsIgnoreCase(" ")) { i++; } while (!sql.substring(i, i + 1).equalsIgnoreCase(" ") && !sql.substring(i, i + 1).equalsIgnoreCase("(")) { tablename = tablename + sql.substring(i, i + 1); i++; } logger.debug(tablename); // (col1,col2)values(#col1#,#col2#) addr_values = StringUtils.indexOfIgnoreCase(sql, "values", i); if (addr_values < 0) { errmsg = "not find values key word."; logger.warn(errmsg); return; } // ??,???,? int kuohao_left = StringUtils.indexOfIgnoreCase(sql, "(", i); int kuohao_right = StringUtils.indexOfIgnoreCase(sql, ")", i); if (kuohao_left >= i && kuohao_right > kuohao_left && kuohao_right < addr_values) { columns = sql.substring(kuohao_left + 1, kuohao_right); } else { errmsg = "between tablename and values key word,you must write columns clearly."; logger.warn(errmsg); return; } // values?sysdate(),?? if (StringUtils.indexOfIgnoreCase(sql, "sysdate()", addr_values) > 0) { errmsg = "use sysdate() function,this not allowed,you should use now() replace it."; logger.warn(errmsg); return; } kuohao_left = StringUtils.indexOfIgnoreCase(sql, "(", addr_values); kuohao_right = StringUtils.lastIndexOfIgnoreCase(sql, ")"); values = sql.substring(kuohao_left + 1, kuohao_right); // ??value?,?map<String,String>? String[] array_columns = columns.split(","); String[] array_values = dealInsertValues(values); if (array_columns.length != array_values.length) { errmsg = "insert sql columns is not map with values."; return; } List<Entry<String, String>> entries = new ArrayList<Entry<String, String>>(array_columns.length); for (int j = 0; j < array_columns.length; j++) { entries.add(new Entry<String, String>(array_columns[j], array_values[j])); } this.insertEntries = entries; }
From source file:org.pentaho.di.core.vfs.SftpFileSystemWindows.java
/** * cut user groups from output whoami//from w ww .j a va 2s .com * * @param commandOutput output from whoami * @return list of user groups */ private List<String> getUserGroups(String commandOutput) { List<String> result = new ArrayList<>(); int startIndex = 0; int endIndex; while (true) { startIndex = StringUtils.indexOfIgnoreCase(commandOutput, GROUP_NAME, startIndex); if (startIndex < 0) { return result; } startIndex += GROUP_NAME.length(); endIndex = StringUtils.indexOfIgnoreCase(commandOutput, RN_DELIMITER, startIndex); if (endIndex < 0) { return result; } result.add(commandOutput.substring(startIndex, endIndex).toUpperCase().trim()); } }